rendering methods in Yii

Hi friends,

Do we have any other methods like "render" and "render-partial"

If there are any,please mention them and try to explain there functionality.

Hello ,

Instead of posting here you have to search on net.

Yii has rich documentation that explain each and everything , so first try to read that.

this will help you ,

http://www.yiiframework.com/doc/api

http://www.yiiframework.com/doc/guide/

Thanks a lot my dear

You can always create your own ‘render’ method on a per controller basis or the controller component in the components directory.

Here’s an example this is a custom render method.


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

	{

		if($this->beforeRender($view))

		{

                    if($col1view)

                    {

                        $col1=$this->renderPartial($col1view,$col1data,true);

                    } else {

                        if($col1data)

                        {

                            $col1 = $col1data;

                        }

                        else

                        $col1 = null;

                    }

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

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

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


			$this->afterRender($view,$output);


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


			if($return)

				return $output;

			else

				echo $output;

		}

	}

This is how I am using it.


$this->render('application.views.sBCms.content',array('pagedata'=>$data,'page'=>$page),array('page'=>$parent),'sidebar');

Notice that I am sending values to render two views. The first values are being rendered using a view that Is absolutely defined (does not matter which controller). So the first view is ‘content’ the second view renders different values, the second view is in my controller specific ‘views’ directory.

The end result is that the layout file now has two values that it can echo on the final output. First variable is $content, like we always have the second value is $col1.

So now in the layout file ‘column2.php’


<?php $this->beginContent('//layouts/main'); ?>

<div class="container">

	<div class="span-16"><!-- sidebar -->

        <div id="content">

<?php echo $content; ?>

		</div>

	</div>

	<div class="span-8 last"><!-- content -->

		<div id="right-column">

<?php echo $col1; ?>

		</div>

	</div>

</div>

<?php $this->endContent(); ?>

Left column and right column can have discreet data and the controller passes this info along.

I am thinking that I can create a better render method by supplying an array of arrays. But I haven’t got there yet :)

doodle