Documentation

Class Phalcon\Mvc\View\Simple

extends abstract class Phalcon\Di\Injectable

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

Source on GitHub

This component allows to render views without hicherquical levels

<?php

 $view = new Phalcon\Mvc\View\Simple();
 echo $view->render('templates/my-view', array('content' => $html));

Methods

public __construct ([array $options])

Phalcon\Mvc\View constructor

public setViewsDir (string|array $viewsDir)

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

public string getViewsDir ()

Gets views directory

public registerEngines (array $engines)

Register templating engines

<?php

$this->view->registerEngines(array(
  ".phtml" => "Phalcon\Mvc\View\Engine\Php",
  ".mhtml" => "MyCustomEngine"
));

public getRegisteredEngines ()

Returns the registered templating engines

protected array _loadTemplateEngines ()

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

protected _internalRender ()

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

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

Renders a view

public partial (string $partialPath, [array $params], [unknown $absolutePath])

Renders a partial view

<?php

    //Show a partial inside another view
    $this->partial('shared/footer');
<?php

    //Show a partial inside another view with parameters
    $this->partial('shared/footer', array('content' => $html));

public Phalcon\Mvc\View\Simple setCacheOptions (array $options)

Sets the cache options

public array getCacheOptions ()

Returns the cache options

protected Phalcon\Cache\BackendInterface _createCache ()

Create a Phalcon\Cache based on the internal cache options

public Phalcon\Cache\BackendInterface getCache ()

Returns the cache instance used to cache

public Phalcon\Mvc\View\Simple cache ([boolean|array $options])

Cache the actual view render to certain level

<?php

  $this->view->cache(array('key' => 'my-key', 'lifetime' => 86400));

public Phalcon\Mvc\View\Simple setParamToView (string $key, mixed $value)

Adds parameters to views (alias of setVar)

<?php

$this->view->setParamToView('products', $products);

public Phalcon\Mvc\View\Simple setVars (array $params, [boolean $merge])

Set all the render params

<?php

$this->view->setVars(array('products' => $products));

public Phalcon\Mvc\View\Simple setVar (string $key, mixed $value)

Set a single view parameter

<?php

$this->view->setVar('products', $products);

public mixed getVar (string $key)

Returns a parameter previously set in the view

public array getParamsToView ()

Returns parameters to views

public Phalcon\Mvc\View\Simple setContent (string $content)

Externally sets the view content

<?php

$this->view->setContent("<h1>hello</h1>");

public string getContent ()

Returns cached ouput from another view stage

public startSection (string $name)

Start a new section block

public string stopSection ()

Stop the current section block

public string|null section (string $name, [unknown $defaultValue])

Returns the content for a section block

public string getActiveRenderPath ()

Returns the path of the view that is currently rendered

public __set (string $key, mixed $value)

Magic method to pass variables to the views

<?php

$this->view->products = $products;

public mixed __get (string $key)

Magic method to retrieve a variable passed to the view

<?php

echo $this->view->products;

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

Sets the dependency injector

public Phalcon\DiInterface getDI ([unknown $error], [unknown $notUseDefault]) 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 Phalcon\Events\ManagerInterface getEventsManager () inherited from Phalcon\Di\Injectable

Returns the internal event manager

public boolean fireEvent (string $eventName, [mixed $data], [unknown $cancelable]) inherited from Phalcon\Di\Injectable

Fires an event, implicitly calls behaviors and listeners in the events manager are notified

public mixed fireEventCancel (string $eventName, [mixed $data], [unknown $cancelable]) inherited from Phalcon\Di\Injectable

Fires an event, can stop the event by returning to the false

public boolean hasService (string $name) inherited from Phalcon\Di\Injectable

Check whether the DI contains a service by a name

public Phalcon\Di\ServiceInterface setService (unknown $name) inherited from Phalcon\Di\Injectable

Sets a service from the DI

public object|null getService (unknown $name) inherited from Phalcon\Di\Injectable

Obtains a service from the DI

public mixed getResolveService (string $name, [array $args], [unknown $noerror], [unknown $noshared]) inherited from Phalcon\Di\Injectable

Resolves the service based on its configuration

public attachEvent (string $eventType, Closure $callback) inherited from Phalcon\Di\Injectable

Attach a listener to the events

public __sleep () inherited from Phalcon\Di\Injectable

...

public __debugInfo () inherited from Phalcon\Di\Injectable

...