Hello. I have action - actionCity with switch (add, delete, update) for link example: site.com/admin/city/add
Code:
I don't know correctly this code or not, but it's work.
And my question: How I can do accessrules for add,delete,update?
Thanks.
Code:
<?php class AdminController extends Controller { public function filters() { return array( 'accessControl', // perform access control for CRUD operations 'postOnly + delete', // we only allow deletion via POST request ); } public function accessRules() { return array( array('allow', 'actions'=>array('city'), 'users'=>array('admin'); ), array('deny', // deny all users 'users'=>array('*'), ), ); } public function actionCity($id=null, $act=null) { switch($act) { case 'add': $city = new City; if (isset($_POST['City'])) { $city->attributes = $_POST['City']; if($city->save()) $this->redirect('/admin/city/'); } $this->render('city/create', array( 'city' => new City, )); break; } } }
I don't know correctly this code or not, but it's work.
And my question: How I can do accessrules for add,delete,update?
Thanks.