I have a search page that passes data to the render function:
public function actionIndex() {
$this->render(
'searchResults',
array(
'dataProvider' => $dataProvider,
'searchQuery' => $searchQuery,
)
);
}
The problem is, I also need to pass this data from here to a widget that appears in the sidebar. The widget is currently displayed in layout/main.php like so:
<?php
$this->widget('searchSidebar', array(
'id' => 'searchSidebar',
));
?>
How would I go about passing data to this widet from the controller without having to redo the query again?
dataProvider already has all data included with
$dataProvider->data
$dataProvider->getData()
To place it in the main layout you may create another variable in your Controller
class Controller extends CController
{
public $data_exchange='';
...
}
It will be easy to manipulate everywhere in the code with $this->data_exchange
similar to breadcrumbs
in your main layout
$this->widget('searchSidebar', array(
'id' => 'searchSidebar',
'data' => $this->data_exchange
/* where $this refer to any class which extends Controller */
));
In your view code define your data as:
$this->data_exchange = $dataProvider->data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With