Javatpoint Logo
Javatpoint Logo

Phalcon Views

View represents the front-end of the application. It consists of HTML files embedded inside PHP code which creates the view of the application. View provides the data to the web browser from your application.

Phalcon\Mvc\View and Phalcon\Mvc\View\Simple are responsible for the managing the view layer of MVC application.

Integrating Views with controller

Views are automatically integrated when controller completes its functionality. The entire view component looks inside the view folder of same file name whose last controller is executed.

Example: If a request made to url 193.168.1.1/javatpoint/phalcon/intro/911

Server Address 193.168.1.1
Phalcon Directory Javatpoint
Controller Phalcon
Action Intro
Parameter 911

Implementation

Hierarchal Rendering

It is the default component for the view rendering and located under directory Phalcon\MVC\View. Its component automatically uses PHP itself as template engine. It has extension .phtml and view component will find following 3 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 showaction is 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.

Implementation

Output:

Phalcon Views 1

Simple Rendering

It is an alternate component to Phalcon\MVC\View and located under Phalcon\MVC\View\Simple. It is similar to the MVC\View but lacks hierarchy. It allows developer to control view when it is altered and its location.

Implementation

Default component replacement

Now, to render we call the render() method


View Events

Phalcon\Mvc\View and Phalcon\Mvc\View\Simple are able to send events to an EventsManager if it is present.

Event Name Triggered Break Operation
beforeRender Triggered before starting the render process Yes
beforeRenderView Triggered before rendering an existing view Yes
afterRenderView Triggered after rendering an existing view No
afterRender Triggered after completing the render process No
notFoundView Triggered when a view was not found No

Implementation


Next TopicPhalcon Volt




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA