grigori

yii Action classes as subcontrollers for virtual paths

Mar 29th, 2011
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. class RblocksController extends Controller{
  2. //...
  3.     public function actions(){
  4.     // return external action classes, e.g.:
  5.         return array(
  6.             'links'=>$this->getModule()->id.'.controllers.'.$this->id.'.linksActions',
  7.         );
  8.     }
  9. }
  10.  
  11. class LinksActions extends CAction{
  12.    
  13.     public function run(){
  14.         $r = yii::app()->getUrlManager()->parseUrl(yii::app()->getRequest());
  15.         $controller = $this->getController()->getId().'/'.$this->id;
  16.         $r = trim(substr($r,strpos($r,$controller)+strlen($controller)),'/');
  17.         $path = explode('/', $r);
  18.         $action = $path[0]?:'index';
  19.         if (yii::app()->request->getIsPostRequest() && method_exists($this, $action.'Post')){
  20.             $action .= 'Post';
  21.         }elseif (!method_exists($this, $action)){
  22.             $this->getController()->missingAction($action);
  23.         }
  24.         $this->$action();
  25.     }
  26.    
  27.     public function index(){
  28.         $model = MangaLinks::model()->findAll();
  29.         $this->getController()->render('links',array('model'=>$model));
  30.     }
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment