🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# Class Phalcon\\Mvc\\View\\Simple # Class **Phalcon\\Mvc\\View\\Simple** *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 ``` <pre class="calibre14">``` <?php $view = new \Phalcon\Mvc\View\Simple(); echo $view->render('templates/my-view', array('content' => $html)); //or with filename with extension echo $view->render('templates/my-view.volt', array('content' => $html)); ``` ``` ### Methods public **getRegisteredEngines** () ... public **\_\_construct** (\[*array* $options\]) Phalcon\\Mvc\\View\\Simple constructor public **setViewsDir** (*unknown* $viewsDir) Sets views directory. Depending of your platform, always add a trailing slash or backslash public **getViewsDir** () Gets views directory public **registerEngines** (*unknown* $engines) Register templating engines ``` <pre class="calibre14">``` <?php $this->view->registerEngines(array( ".phtml" => "Phalcon\Mvc\View\Engine\Php", ".volt" => "Phalcon\Mvc\View\Engine\Volt", ".mhtml" => "MyCustomEngine" )); ``` ``` 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 *string***render** (*string* $path, \[*array* $params\]) Renders a view public **partial** (*string* $partialPath, \[*array* $params\]) Renders a partial view ``` <pre class="calibre14">``` <?php //Show a partial inside another view $this->partial('shared/footer'); ``` ``` ``` <pre class="calibre14">``` <?php //Show a partial inside another view with parameters $this->partial('shared/footer', array('content' => $html)); ``` ``` public <a class="calibre6 pcalibre1" href="">*Phalcon\\Mvc\\View\\Simple*</a>**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** (\[*unknown* $options\]) Cache the actual view render to certain level ``` <pre class="calibre14">``` <?php $this->view->cache(array('key' => 'my-key', 'lifetime' => 86400)); ``` ``` public **setParamToView** (*unknown* $key, *unknown* $value) Adds parameters to views (alias of setVar) ``` <pre class="calibre14">``` <?php $this->view->setParamToView('products', $products); ``` ``` public **setVars** (*unknown* $params, \[*unknown* $merge\]) Set all the render params ``` <pre class="calibre14">``` <?php $this->view->setVars(array('products' => $products)); ``` ``` public **setVar** (*unknown* $key, *unknown* $value) Set a single view parameter ``` <pre class="calibre14">``` <?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 **setContent** (*unknown* $content) Externally sets the view content ``` <pre class="calibre14">``` <?php $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** (*unknown* $key, *unknown* $value) Magic method to pass variables to the views ``` <pre class="calibre14">``` <?php $this->view->products = $products; ``` ``` public *mixed*\*\*\_\_get\*\* (*string* $key) Magic method to retrieve a variable passed to the view ``` <pre class="calibre14">``` <?php echo $this->view->products; ``` ``` public **setDI** (*unknown* $dependencyInjector) inherited from Phalcon\\Di\\Injectable Sets the dependency injector public **getDI** () inherited from Phalcon\\Di\\Injectable Returns the internal dependency injector public **setEventsManager** (*unknown* $eventsManager) inherited from Phalcon\\Di\\Injectable Sets the event manager public **getEventsManager** () inherited from Phalcon\\Di\\Injectable Returns the internal event manager | - [索引](# "总目录") - [下一页](# "Abstract class Phalcon\Paginator\Adapter") | - [上一页](# "Class Phalcon\Mvc\View\Exception") | - [API Indice](#) »