Ideas for changes on CController

Hello,

I don't know if is a good idea and the right place to wrote about this.

I want to have partial views generated from database, as ex the menu.

The search of this forum doesn't helped me too much in finding the right solution.

Even mine which I'll describe it below it's not perfect, but I'm waiting for better suggestion.

I didn't found how to have different partial views rendered in the layout dynamically I chose to change a little the CController class, in fact the render function. (sometimes I prefer to load a model from a view, without the controller, it's possile?) (for partialRender I have to provide the data anyway from the controller)

Now I can have in SiteController:

$this->render(array('content'=>'index', 'menu'=>'menu1'));

So, the function looks now like this.

public function render($view,$data=null,$return=false)


	{


		if(!is_array($view)){


			$output=$this->renderPartial($view,$data,true);


			if(($layoutFile=$this->getLayoutFile($this->layout))!==false)


				$output=$this->renderFile($layoutFile,array('content'=>$output),true);


			


		}


		else


		{


			$out = array();


			foreach($view as $k=>$v)


				$out[$k] = $this->renderPartial($v,$data,true);


			if(($layoutFile=$this->getLayoutFile($this->layout))!==false)


				$output=$this->renderFile($layoutFile,$out,true);


			else


				$output = implode("", $out);


		}


		$output=$this->processOutput($output);





		if($return)


			return $output;


		else


			echo $output;


	}

Any better idea?

Regards,

Paul

Edit:

Because I have talked about menu below is an idea for a dynamic one.

I made a ne widget named HorizontalMenu (an identical copy of the MainMenu) and I changed run function:

public function run()


	{


		$items=array();


		$controller=$this->controller;


		$action=$controller->action;


		


		$criteria=new CDbCriteria;


		eval('$model='.$this->items["model"].'::model()->findAll($criteria);');


		


		foreach($model as $item)


		{


			$item2=array();


			$item2['label']=$item->{$this->items['label']};


			//$item2['url']=$item[$this->items['url']]; //if absolute url


			$item2['url']=$controller->createUrl($item[$this->items['url']]);


			


			$pattern=isset($item['pattern'])?$item['pattern']:$item[$this->items['url']];


			$item2['active']=$this->isActive($pattern,$controller->uniqueID,$action->id);


			$items[]=$item2;


		}


		


		$this->render('mainMenu',array('items'=>$items));


	}

not complete, but improvable.

The widget in main.php looks like this:

$this->widget('application.components.HorizontalMenu',array(


	'items'=>array(


		'model' => 'model_name',


		'label' => 'label_field',


		'url' => 'url_field'


	),


));

It has to be integrated with authorization, mine is not fully done.

Hope that helps