extends abstract class Phalcon\Di\Injectable
implements Phalcon\Events\EventsAwareInterface, Phalcon\Di\InjectionAwareInterface, Phalcon\Mvc\ViewBaseInterface
This component allows to render views without hierarchical levels
use Phalcon\Mvc\View\Simple as View;
$view = new View();
// Render a view
echo $view->render(
"templates/my-view",
[
"some" => $param,
]
);
// Or with filename with extension
echo $view->render(
"templates/my-view.volt",
[
"parameter" => $here,
]
);
Phalcon\Mvc\View\Simple constructor
Sets views directory. Depending of your platform, always add a trailing slash or backslash
Gets views directory
Register templating engines
$this->view->registerEngines(
[
".phtml" => "Phalcon\\Mvc\\View\\Engine\\Php",
".volt" => "Phalcon\\Mvc\\View\\Engine\\Volt",
".mhtml" => "MyCustomEngine",
]
);
Loads registered template engines, if none is registered it will use Phalcon\Mvc\View\Engine\Php
Tries to render the view with every engine registered in the component
Renders a view
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",
[
"content" => $html,
]
);
Sets the cache options
Returns the cache options
Create a Phalcon\Cache based on the internal cache options
Returns the cache instance used to cache
Cache the actual view render to certain level
$this->view->cache(
[
"key" => "my-key",
"lifetime" => 86400,
]
);
Adds parameters to views (alias of setVar)
$this->view->setParamToView("products", $products);
Set all the render params
$this->view->setVars(
[
"products" => $products,
]
);
Set a single view parameter
$this->view->setVar("products", $products);
Returns a parameter previously set in the view
Returns parameters to views
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
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;
Sets the dependency injector
Returns the internal dependency injector
Sets the event manager
Returns the internal event manager
© 2011–2017 Phalcon Framework Team
Licensed under the Creative Commons Attribution License 3.0.
https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_View_Simple.html