This is a title
This is the post content
Viewの使用 =========== Views represent the user interface of your application. Views are often HTML files with embedded PHP code that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application. :doc:`Phalcon\\Mvc\\View <../api/Phalcon_Mvc_View>` and :doc:`Phalcon\\Mvc\\View\\Simple <../api/Phalcon_Mvc_View_Simple>` are responsible for the managing the view layer of your MVC application. コントローラとビューの結合 ---------------------------------- Phalcon automatically passes the execution to the view component as soon as a particular controller has completed its cycle. The view component will look in the views folder for a folder named as the same name of the last controller executed and then for a file named as the last action executed. For instance, if a request is made to the URL *http://127.0.0.1/blog/posts/show/301*, Phalcon will parse the URL as follows: +-------------------+-----------+ | Server Address | 127.0.0.1 | +-------------------+-----------+ | Phalcon Directory | blog | +-------------------+-----------+ | Controller | posts | +-------------------+-----------+ | Action | show | +-------------------+-----------+ | Parameter | 301 | +-------------------+-----------+ The dispatcher will look for a "PostsController" and its action "showAction". A simple controller file for this example: .. code-block:: php view->postId = $postId; } } The :code:`setVar()` method allows us to create view variables on demand so that they can be used in the view template. The example above demonstrates how to pass the :code:`$postId` parameter to the respective view template. 階層的なレンダリング ---------------------- :doc:`Phalcon\\Mvc\\View <../api/Phalcon_Mvc_View>` supports a hierarchy of files and is the default component for view rendering in Phalcon. This hierarchy allows for common layout points (commonly used views), as well as controller named folders defining respective view templates. This component uses by default PHP itself as the template engine, therefore views should have the .phtml extension. If the views directory is *app/views* then view component will find automatically for these 3 view files. +-------------------+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Name | File | Description | +===================+===============================+==========================================================================================================================================================================================================================+ | Action View | app/views/posts/show.phtml | This is the view related to the action. It only will be shown when the "show" action was executed. | +-------------------+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Controller Layout | app/views/layouts/posts.phtml | This is the view related to the controller. It only will be shown for every action executed within the controller "posts". All the code implemented in the layout will be reused for all the actions in this controller. | +-------------------+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Main Layout | app/views/index.phtml | This is main action it will be shown for every controller or action executed within the application. | +-------------------+-------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ You are not required to implement all of the files mentioned above. :doc:`Phalcon\\Mvc\\View <../api/Phalcon_Mvc_View>` will simply move to the next view level in the hierarchy of files. If all three view files are implemented, they will be processed as follows: .. code-block:: html+php
I have received the parameter
.. code-block:: html+phpI have received the parameter 101
テンプレートの使用 ^^^^^^^^^^^^^^^^^^ Templates are views that can be used to share common view code. They act as controller layouts, so you need to place them in the layouts directory. Templates can be rendered before the layout (using :code:`$this->view->setTemplateBefore()`) or they can be rendered after the layout (using :code:`this->view->setTemplateAfter()`). In the following example the template (layouts/common.phtml) is rendered after the main layout (layouts/posts.phtml): .. code-block:: php view->setTemplateAfter("common"); } public function lastAction() { $this->flash->notice( "These are the latest posts" ); } } .. code-block:: html+phpThis is the post content
This is another post content
This is the post content
This is another post content
This is the post content
This is another post content
Check out our specials for robots:
...