1.修改自动生成的basic\controllers\PostsController.php,前面引入use yii\filters\AccessControl;
[code]class PostsController extends Controller
{
public function behaviors()
{
return [
'access'=>[
'class'=>AccessControl::className(),
'only'=>['create','update'],
'rules'=>[
['allow'=>true,
'roles'=>['@']
],
]
]
,
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}[/code]
2.访问http://https://https://amyflash.com/yii/basic/web/index.php?r=posts/
点击create posts按钮,出现登陆页面了