I wanna to use database data in the layout, how?

For programming and general questions on Zend Framework

I wanna to use database data in the layout, how?

Postby jobsfan on Mon Dec 10, 2012 3:01 pm

In the controller, we can connect database and fetachall and then passed it to view, however I don't known how to passed array or variables to layout.phtml. who can help?
jobsfan
 
Posts: 23
Joined: Sat Sep 08, 2012 3:15 am

Re: I wanna to use database data in the layout, how?

Postby jobsfan on Tue Dec 11, 2012 2:54 pm

I don't know how to use database in the layout.phtml, also, when I wrote the following code at the begining of layout.phtml. It is also error, it says, can not find the file. it seems the path is not correct.

Code: Select all
<?php
$series = file_get_contents('/js/series.js');
$series = json_decode($series,true);
?>
<?php echo $this->doctype(); ?>
jobsfan
 
Posts: 23
Joined: Sat Sep 08, 2012 3:15 am

Re: I wanna to use database data in the layout, how?

Postby johnmukii on Fri Dec 14, 2012 1:44 pm

In the controller to pass data to the layout pass the variables to the view object .
//in the controller
$this->view->yourdata='data';
//in the layout
$this->yourvariable;
johnmukii
 
Posts: 13
Joined: Fri Mar 02, 2012 11:20 pm

Re: I wanna to use database data in the layout, how?

Postby jobsfan on Sat Dec 22, 2012 5:48 pm

johnmukii wrote:In the controller to pass data to the layout pass the variables to the view object .
//in the controller
$this->view->yourdata='data';
//in the layout
$this->yourvariable;



thank you!! I got you.
jobsfan
 
Posts: 23
Joined: Sat Sep 08, 2012 3:15 am

Re: I wanna to use database data in the layout, how?

Postby jobsfan on Sun Dec 23, 2012 2:18 pm

johnmukii wrote:In the controller to pass data to the layout pass the variables to the view object .
//in the controller
$this->view->yourdata='data';
//in the layout
$this->yourvariable;



I thought it over, I don't think it is a good way to use this method. Try to imaging that, if we need to fetch category or series from database as navigator in the header area, each page need to show this, in your way, you need to pass data in every controller and every actions, it is not the best way I think.
jobsfan
 
Posts: 23
Joined: Sat Sep 08, 2012 3:15 am


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 11 guests