Class Phalcon\Mvc\View\Simple

extends abstract class Phalcon\Di\Injectable

implements Phalcon\Events\EventsAwareInterface, Phalcon\Di\InjectionAwareInterface, Phalcon\Mvc\ViewBaseInterface

Source on GitHub

This component allows to render views without hierarchical levels

  1. <?php
  2. use Phalcon\Mvc\View\Simple as View;
  3. $view = new View();
  4. // Render a view
  5. echo $view->render(
  6. "templates/my-view",
  7. [
  8. "some" => $param,
  9. ]
  10. );
  11. // Or with filename with extension
  12. echo $view->render(
  13. "templates/my-view.volt",
  14. [
  15. "parameter" => $here,
  16. ]
  17. );

Methods

public getRegisteredEngines ()

public __construct ([array $options])

Phalcon\Mvc\View\Simple constructor

public setViewsDir (mixed $viewsDir)

Sets views directory. Depending of your platform, always add a trailing slash or backslash

public getViewsDir ()

Gets views directory

public registerEngines (array $engines)

Register templating engines

  1. <?php
  2. $this->view->registerEngines(
  3. [
  4. ".phtml" => "Phalcon\\Mvc\\View\\Engine\\Php",
  5. ".volt" => "Phalcon\\Mvc\\View\\Engine\\Volt",
  6. ".mhtml" => "MyCustomEngine",
  7. ]
  8. );

protected array _loadTemplateEngines ()

Loads registered template engines, if none is registered it will use Phalcon\Mvc\View\Engine\Php

final protected _internalRender (string $path, array $params)

Tries to render the view with every engine registered in the component

public render (string $path, [array $params])

Renders a view

public partial (mixed $partialPath, [mixed $params])

Renders a partial view

  1. <?php
  2. // Show a partial inside another view
  3. $this->partial("shared/footer");
  1. <?php
  2. // Show a partial inside another view with parameters
  3. $this->partial(
  4. "shared/footer",
  5. [
  6. "content" => $html,
  7. ]
  8. );

public setCacheOptions (array $options)

Sets the cache options

public array getCacheOptions ()

Returns the cache options

protected _createCache ()

Create a Phalcon\Cache based on the internal cache options

public getCache ()

Returns the cache instance used to cache

public cache ([mixed $options])

Cache the actual view render to certain level

  1. <?php
  2. $this->view->cache(
  3. [
  4. "key" => "my-key",
  5. "lifetime" => 86400,
  6. ]
  7. );

public setParamToView (mixed $key, mixed $value)

Adds parameters to views (alias of setVar)

  1. <?php
  2. $this->view->setParamToView("products", $products);

public setVars (array $params, [mixed $merge])

Set all the render params

  1. <?php
  2. $this->view->setVars(
  3. [
  4. "products" => $products,
  5. ]
  6. );

public setVar (mixed $key, mixed $value)

Set a single view parameter

  1. <?php
  2. $this->view->setVar("products", $products);

public getVar (mixed $key)

Returns a parameter previously set in the view

public array getParamsToView ()

Returns parameters to views

public setContent (mixed $content)

Externally sets the view content

  1. <?php
  2. $this->view->setContent("<h1>hello</h1>");

public getContent ()

Returns cached output from another view stage

public string getActiveRenderPath ()

Returns the path of the view that is currently rendered

public __set (mixed $key, mixed $value)

Magic method to pass variables to the views

  1. <?php
  2. $this->view->products = $products;

public __get (mixed $key)

Magic method to retrieve a variable passed to the view

  1. <?php
  2. echo $this->view->products;

public setDI (Phalcon\DiInterface $dependencyInjector) inherited from Phalcon\Di\Injectable

Sets the dependency injector

public getDI () inherited from Phalcon\Di\Injectable

Returns the internal dependency injector

public setEventsManager (Phalcon\Events\ManagerInterface $eventsManager) inherited from Phalcon\Di\Injectable

Sets the event manager

public getEventsManager () inherited from Phalcon\Di\Injectable

Returns the internal event manager