lito
有个问题 假如用户 id为1 的订单为空 那么Customer::findModel($id)->orders 也为空,view层该如何处理这种空?
爬啊爬怕怕!!Mark
- lito 2016-08-11 已签到连续签到1天,获得了5个金钱
- lito 评论了教程 yii2-admin 插件使用简要教程
我使用Yii2的基本应用程序模板安装完成yii2-admin后,查看路由只能看到admin下的路由列表
但是,路由列表中看不到app\controller下的控制器?请问为什么module配置如下:
<?php return [ 'admin' => [ 'class' => 'mdm\admin\Module', 'layout'=>'left-menu', 'mainLayout' => '@app/views/layouts/main.php', ], 'controllerMap' => [ 'assignment' => [ 'class' => 'mdm\admin\controllers\AssignmentController', /* 'userClassName' => 'app\models\User', */ 'idField' => 'user_id', 'usernameField' => 'username', 'fullnameField' => 'profile.full_name', 'extraColumns' => [ [ 'attribute' => 'full_name', 'label' => 'Full Name', 'value' => function($model, $key, $index, $column) { return $model->profile->full_name; }, ], [ 'attribute' => 'dept_name', 'label' => 'Department', 'value' => function($model, $key, $index, $column) { return $model->profile->dept->name; }, ], [ 'attribute' => 'post_name', 'label' => 'Post', 'value' => function($model, $key, $index, $column) { return $model->profile->post->name; }, ], ], 'searchClass' => 'app\models\UserSearch' ], ], ];
components配置如下
<?php return [ 'request' => [ // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation 'cookieValidationKey' => 'Owod8SuyH0Syh2pjYY6LYGIGvKtQLHAt', ], 'cache' => [ 'class' => 'yii\caching\FileCache', ], 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true, ], 'urlManager'=>[ 'enablePrettyUrl' => true, 'showScriptName' => false,//index.php ], 'errorHandler' => [ 'errorAction' => 'site/error', ], 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', // send all mails to a file by default. You have to set // 'useFileTransport' to false and configure a transport // for the mailer to send real emails. 'useFileTransport' => true, ], 'log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], ], ], 'db' => require(__DIR__ . '/db.php'), //权限管理 'authManager' => [ 'class' => 'yii\rbac\DbManager', 'itemTable' => '{{%auth_item}}', 'assignmentTable' => '{{%auth_assignment}}', 'itemChildTable' => '{{%auth_item_child}}', "defaultRoles" => ["guest"], ], //样式管理 'assetManager' => [ 'bundles' => [ 'dmstr\web\AdminLteAsset' => [ 'skin' => 'skin-blue', ], ], ],