Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Variables that you have defined in your controller action are only available to immediate view files that are being used to render a view. They are not available to layouts. However, layouts will be able to use public methods and properties of the controller. So, if you want to pass a variable to your layout you need to declare it as a property of the controller. There are two ways of doing this.</p> <p>Firstly, you can just create a public variable.</p> <pre><code>Class YourController extends CController{ public $dataProvider2; public function actionIndex(){ // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' //$this-&gt;render('index'); $dataProviderUser=new CActiveDataProvider('User',array( 'pagination'=&gt;array( 'pageSize'=&gt;20, ), )); $dataProviderDomain = new CActiveDataProvider('Domain'); //Added new line here $this-&gt;dataProvider2 = $dataProviderDomain; $this-&gt;render('index',array( 'dataProvider1'=&gt;$dataProviderUser, 'dataProvider2'=&gt;$dataProviderDomain )); } } </code></pre> <p>$this->dataProvider is now available in your view file, but don't foorget to check that it exists before using it.</p> <p>The other method is to use the magic getter method from Yii.</p> <p>In your model, describe a method like this;</p> <pre><code>public function getdataProvider2(){ return $this-&gt;_dataProvider2; } </code></pre> <p>and you'll need a property;</p> <pre><code>private $_dataProvider2; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload