4.2 Начало работы с Zend_Layout. Использование Zend_Layout | Participants
|
- Statistics
- Participants
- Translate into Russian
- Translation result
- Translated in draft, editing and proof-reading required.
If you do not want to register an account, you can sign in with OpenID.
Getting Started with Zend_Layout. Using Zend_Layout | 4.2 Начало работы с Zend_Layout. Использование Zend_Layout | |
Basic usage of Zend_Layout is fairly trivial. Assuming you're using Zend_Application already, you can simply provide some configuration options and create a layout view script. | Основы использования Zend_Layout достаточно просты. Особенно если вы уже применяете Zend_Application, то вам достаточно указать несколько параметров конфигурации и создать скрипт макета. | |
Layout Configuration | ||
The recommended location of layouts is in a "layouts/scripts/" subdirectory of your application: | Рекомендуется размещать макеты (шаблоны) в подкаталоге "layouts/scripts" вашего приложения: | |
01. application | ||
02. |-- Bootstrap.php | ||
03. |-- configs | ||
04. | `-- application.ini | ||
05. |-- controllers | ||
06. |-- layouts | ||
07. | `-- scripts | ||
08. | |-- layout.phtml | ||
To initialize Zend_Layout, add the following to your configuration file ("application/configs/application.ini"): | Для инициализации Zend_Layout добавьте в конфигурационный файл ("/application/configs/application.ini") следующие строки: | |
01. resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" | 01. resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts" | |
02. resources.layout.layout = "layout" | ||
The first line indicates where to look for layout scripts; the second line gives the name of the layout to use, minus the view script extension (which is assumed to be ".phtml" by default). | Первая строка указывает, где располагаются скрипты макетов (шаблонов); вторая строка указывает имя макета(шаблона) по умолчанию, без указания расширения скриптов вида (по умолчанию используется ".phtml"). | |
Create a Layout Script | ||
Now that you have your configuration in place, you need to create your layout script. First, make sure that you've created the "application/layouts/scripts" directory; then, open an editor, and create the markup for your layout. Layout scripts are simply view scripts, with some slight differences. | Теперь, когда в конфигурации произведена настройка, необходимо создать скрипт макета. Для начала убедитесь, что у вас создана следующую структуру каталогов: "/application/layouts/scripts"; после этого в редакторе создайте ваш макет. Скрипты макетов - это те же скрипты вида, с небольшими отличиями. | |
01. <html> | ||
02. <head> | ||
03. <title>My Site</title> | ||
04. </head> | ||
05. <body> | ||
06. <?php echo $this->layout()->content ?> | ||
07. </body> | ||
08. </html> | ||
In the example above, you'll note the call to a layout() view helper. When you register the Zend_Layout resource, you also gain access to both an action and view helper that allow you access to the Zend_Layout instance; you can then call operations on the layout object. In this case, we're retrieving a named variable, $content, and echoing it. By default, the $content variable is populated for you from the application view script rendered. Otherwise, anything you'd normally do in a view script is perfectly valid -- call any helpers or view methods you desire. | Как вы могли заметить, в данном примере производится вызов макета, являющегося помощником вида. Когда вы регистрируете ресурс Zend_Layout, то вы так же получаете доступ к действиям и помощникам вида, через которые получаете доступ к инстанцированному Zend_Layout; в результате можно выполнять различные операции в макете. В данном случае мы получаем переменную $content и отображаем её. По умолчанию, переменную $content приложение за вас наполняет скриптом вида. В остальных случаях вы можете выполнять все то, что делаете с обычными скриптами вида -- вызов помощников или различных действий. | |
At this point, you have a working layout script, and your application is informed of its location and knows to render it. | К текущему моменту, вы получили рабочий скрипт макета и приложение знает, где он расположен и готово его заполнить. |
