In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the example analysis of Zend Framework's Zend_Layout layout assistant. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
The details are as follows:
I. function
The role of layout is similar to that of templates. It can be thought of as taking out the general and public parts of the website as a general page framework. For example, a basic web page, the head and tail of the page may be the same, the only difference may be the content body part is different, the common part can be made into a template. It can not only improve the development efficiency, but also bring convenience for the later maintenance.
2. Use
Here is a simple example.
First create a basic zend framework project with zend studio: layout_demo1
The structure is roughly as follows. "
├─ .settings
├─ application
│ ├─ configs
│ ├─ controllers
│ ├─ models
│ └─ views
│ ├─ helpers
│ └─ scripts
│ ├─ error
│ └─ index
├─ docs
├─ library
├─ public
└─ tests
├─ application
│ └─ controllers
└─ library
1. Join the layout function:
Apply the configuration file / layout_demo2/application/configs/application.ini and add the following configuration
Resources.frontController.controllerDirectory = APPLICATION_PATH "/ controllers" resources.frontController.params.displayExceptions = 0resources.layout.layoutPath = APPLICATION_PATH "/ layouts/scripts/" [staging: production]
two。 Corresponding directory and layout template files / layout_demo2/application/layouts/scripts/layout.phtml
├─ application
│ ├─ configs
│ ├─ controllers
│ ├─ layouts
│ │ └─ scripts
│ ├─ models
│ └─ views
The layout.html looks like this:
My app header header
Here
It's more important. Indicates that this is the content of the layout, that is, where it will change dynamically.
So, run the program.
Www.localzend.com/layout_demo1/public/
The generated html source code is as follows
My app header a:link, a:visited {color: # 0398CA;} span#zf-name {color: # 91BE3F;} div#welcome {color: # FFFFFF; background-image: url (https://cache.yisu.com/upload/information/20201209/266/40829.jpg); width: 600px; height: 400px; border: 2px solid # 444444; overflow: hidden; text-align: center } div#more-information {background-image: url (https://cache.yisu.com/upload/information/20201209/266/40830.gif); height: 100%;} Welcome to the Zend Framework! This is your project's main page
Helpful Links: Zend Framework Website | Zend Framework Manual
Header
The middle part is the content of / layout_demo1/application/views/scripts/index/index.phtml.
Injection: the configuration and files of layout can be generated automatically through zf's command tool.
The command is as follows:
Zf enable layout
You can refer to the command line section
III. Configuration
1. Custom location and name can be used to configure the location and name of the layout file through the application.ini configuration file, for example:
Resources.layout.layoutPath = APPLICATION_PATH "/ mylayouts/scripts" resources.layout.layout = "mylayout"
two。 Using layout objects in action
Can be passed through
$layout = $this- > _ helper- > layout ()
Or
$helper = $this- > _ helper- > getHelper ('Layout'); $layout = $helper- > getLayoutInstance ()
Gets the layout object.
You can disable the current action usage layout mode in the following ways
$layout- > disableLayout ()
Can be passed through
$layout- > setLayout ('other')
To set up to use another layout file
You can pass the assignment through
$layout- > assign ('headertitle',' app title'); $layout- > somekey = "value"
3. Other methods of getting layout objects
(1)
$layout = Zend_Layout::getMvcInstance ()
(2)
$layout = $bootstrap- > getResource ('Layout')
Fourth, other uses, realization principle
For other specific usage methods, please refer to
Zend_Layout_Controller_Action_Helper_Layout class
Zend_Layout_Controller_Plugin_Layout class
Zend_View_Helper_Layout class
It speaks for itself.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.