I have a Zend application with the following structure:
application
configs
application.ini
modules
api
controllers
Bootstrap.php
default
controllers
IndexController.php
models
views
scripts
index
index.phtml
layouts
layout.phtml
Bootstrap.php
My application/configs/application.ini looks like this:
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.db.adapter = "PDO_SQLITE"
resources.db.params.dbname = APPLICATION_PATH "/../data/db/test.sqlite3"
resources.modules = ""
resources.frontController.params.prefixDefaultModule = "1"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.layout.layoutPath = APPLICATION_PATH "/modules/default/views/layout/"
My problem is that I cannot use the layout no matter what I do. If I go to http://test.app/index/index , I can see the output of the view script, but not the layout.
I see you specify the layout path but never the actual layout file to use. Assuming the layout is named layout.phtml
add this to the app's ini.
resources.layout.layout = "layout"
You can override on a per action/controller level if you ever need to use more than one layout. In the controller you can reach the layout via $this->_helper->layout()
Then you have methods such as: setLayoutPath()
, setLayout()
, disableLayout()
Reference: http://framework.zend.com/manual/1.12/en/learning.layout.usage.html
You need to initialize your layout file in the Bootstrap.php or application.ini to be able to use it, you haven't declared which file to use.
In Bootstrap.php
function _initViewHelpers()
{
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
}
And you should be good to go, if you want to have multiple layout and have different condition to use layout you should look at this answer here this is pretty cool.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.