Suggestion - renderAction?

MVC and Ruby already have renderAction() method, but yii not yet… maybe it’s time? :rolleyes:

What does it do?

Check this LINK and this LINK

I suppose same as Cake requestAction and ZF has something like that… mostly there is talk how bad they are because use so many resources… but i agree its pretty usefull in many cases where coding a widget is just double work.

It runs a controller action, captures the output and then displays?

That/s write it does the same thing:

Consider an example where in I want to render some UI based on some business logic as a partial within parent UI.

I needed this feature in my current portion of application I am developing. Basically I am rendering a page, while rendering a page, in one of the div I need to load list of folder so I just created a partial load_folder and tried using $this->renderPartial(‘load_folders’), but then I realized that load_folders should be an action so that it can go to DB and fetch folder information from table.

I am stuck here, trying to find some good solution to avoid violating MVC design. Anyone got suggestion?

I’m not test this piece of my code, but maybe something like:




class Controller extends CController {

 private $_isChildAction=false;


 /**

  * @return boolean

  */

 public function getIsChildAction(){

  return $this->_isChildAction;

 }


 /**

  * @param boolean $value

  */

 public function setIsChildAction($value){

  $this->_isChildAction=$value;

 }


 /**

  * @param string $actionID

  * @param string $controllerID

  * @param string $return

  * @return null|string

  */

 public function renderAction($actionID,$controllerID,$return=false){

  if(!strcasecmp($controllerID,$this->getId())){

   if(null!==($action=$this->createAction($actionID))){

    if(($parent=$this->getModule())===null)

     $parent=Yii::app();


    ob_start();

    if($parent->beforeControllerAction($this,$action)){

     $this->runActionWithFilters($action,$this->filters());

     $parent->afterControllerAction($this,$action);

    }

    $output=ob_get_clean();


    if($return)

     return $output;

    else

     echo $output;

   }

   else

    $this->missingAction($actionID);

  }

  else if(null!==($ca=Yii::app()->createController($controllerID.'/'.$actionID))){

   list($controller,$actionID)=$ca;

   $controller->init();

   $controller->setIsChildAction(true);


   return $controller->renderAction($actionID,$controllerID,$return);

  }

  else

   $this->missingAction($actionID);

 }

}



Is it no option to simply wrap $this->forward($controller, false)?