extends abstract class Phalcon\DI\Injectable
implements Phalcon\Events\EventsAwareInterface, Phalcon\DI\InjectionAwareInterface, Phalcon\Mvc\ViewInterface
Phalcon\Mvc\View is a class for working with the “view” portion of the model-view-controller pattern. That is, it exists to help keep the view script separate from the model and controller scripts. It provides a system of helpers, output filters, and variable escaping.
//Setting views directory $view = new Phalcon\Mvc\View(); $view->setViewsDir('app/views/'); $view->start(); //Shows recent posts view (app/views/posts/recent.phtml) $view->render('posts', 'recent'); $view->finish(); //Printing views output echo $view->getContent();
Phalcon\Mvc\View constructor
Sets views directory. Depending of your platform, always add a trailing slash or backslash
Gets views directory
Sets the layouts sub-directory. Must be a directory under the views directory. Depending of your platform, always add a trailing slash or backslash
$view->setLayoutsDir('../common/layouts/');
Gets the current layouts sub-directory
Sets a partials sub-directory. Must be a directory under the views directory. Depending of your platform, always add a trailing slash or backslash
$view->setPartialsDir('../common/partials/');
Gets the current partials sub-directory
Sets base path. Depending of your platform, always add a trailing slash or backslash
$view->setBasePath(__DIR__ . '/');
Returns the render level for the view
Returns the render level for the view
Sets the render level for the view
//Render the view related to the controller only $this->view->setRenderLevel(View::LEVEL_LAYOUT);
Disables a specific level of rendering
//Render all levels except ACTION level $this->view->disableLevel(View::LEVEL_ACTION_VIEW);
Returns an array with disabled render levels
Sets default view name. Must be a file without extension in the views directory
//Renders as main view views-dir/base.phtml $this->view->setMainView('base');
Returns the name of the main view
Change the layout to be used instead of using the name of the latest controller name
$this->view->setLayout('main');
Returns the name of the main view
Appends template before controller layout
Resets any template before layouts
Appends template after controller layout
Resets any template after layouts
Adds parameters to views (alias of setVar)
$this->view->setParamToView('products', $products);
Set all the render params
$this->view->setVars(array('products' => $products));
Set a single view parameter
$this->view->setVar('products', $products);
Returns a parameter previously set in the view
Returns parameters to views
Gets the name of the controller rendered
Gets the name of the action rendered
Gets extra parameters of the action rendered
Starts rendering process enabling the output buffering
Loads registered template engines, if none is registered it will use Phalcon\Mvc\View\Engine\Php
Checks whether view exists on registered extensions and render it
Register templating engines
$this->view->registerEngines(array( ".phtml" => "Phalcon\Mvc\View\Engine\Php", ".volt" => "Phalcon\Mvc\View\Engine\Volt", ".mhtml" => "MyCustomEngine" ));
Returns the registered templating engines
...
Executes render process from dispatching data
//Shows recent posts view (app/views/posts/recent.phtml) $view->start()->render('posts', 'recent')->finish();
Choose a different view to render instead of last-controller/last-action
class ProductsController extends Phalcon\Mvc\Controller { public function saveAction() { //Do some save stuff... //Then show the list view $this->view->pick("products/list"); } }
Renders a partial view
//Show a partial inside another view $this->partial('shared/footer');
//Show a partial inside another view with parameters $this->partial('shared/footer', array('content' => $html));
Perform the automatic rendering returning the output as a string
$template = $this->view->getRender('products', 'show', array('products' => $products));
Finishes the render process by stopping the output buffering
Create a Phalcon\Cache based on the internal cache options
Check if the component is currently caching the output content
Returns the cache instance used to cache
Cache the actual view render to certain level
$this->view->cache(array('key' => 'my-key', 'lifetime' => 86400));
Externally sets the view content
$this->view->setContent("<h1>hello</h1>");
Returns cached output from another view stage
Returns the path of the view that is currently rendered
Disables the auto-rendering process
Enables the auto-rendering process
Whether automatic rendering is enabled
Resets the view component to its factory default values
Magic method to pass variables to the views
$this->view->products = $products;
Magic method to retrieve a variable passed to the view
echo $this->view->products;
Magic method to inaccessible a variable passed to the view
isset($this->view->products)
Sets the dependency injector
Returns the internal dependency injector
Sets the event manager
Returns the internal event manager
© 2011–2016 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/2.0.0/api/Phalcon_Mvc_View.html