Yii Framework Forum: Suggestion - renderAction? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Suggestion - renderAction? Rate Topic: -----

#1 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 15 April 2010 - 06:11 AM

MVC and Ruby already have renderAction() method, but yii not yet... maybe it's time? :rolleyes:
-Posted Image-
Thanks, you make me stronger!
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 15 April 2010 - 07:16 AM

What does it do?
0

#3 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 15 April 2010 - 07:38 AM

Quote

One of the upcoming new features being added to ASP.NET MVC 2 Beta is a little helper method called Html.RenderAction and its counterpart, Html.Action. This has been a part of our ASP.NET MVC Futures library for a while, but is now being added to the core product.

Both of these methods allow you to call into an action method from a view and output the results of the action in place within the view. The difference between the two is that Html.RenderAction will render the result directly to the Response (which is more efficient if the action returns a large amount of HTML) whereas Html.Action returns a string with the result.


Check this LINK and this LINK
-Posted Image-
Thanks, you make me stronger!
0

#4 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 15 April 2010 - 12:29 PM

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.
0

#5 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 15 April 2010 - 12:38 PM

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

#6 User is offline   rakson 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 26-March 10

Posted 17 April 2010 - 09:35 AM

View PostY!!, on 15 April 2010 - 12:38 PM, said:

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?
0

#7 User is offline   vamp 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 30-January 09

Posted 17 April 2010 - 11:24 AM

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);
 }
}

-Posted Image-
Thanks, you make me stronger!
0

#8 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 17 April 2010 - 11:56 AM

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

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users