2012-12-18 17 views
1

我發現,爾康可以通過爾康\逃避者進行轉義視圖變量:http://docs.phalconphp.com/en/latest/api/Phalcon_Escaper.html如何逃脫的HTML爾康的mvc 查看

例如,在Zend的,有一種方法可從視圖中調用視圖助手:

// view context 
$this->escape($data); // calls View\Helper\Escape 
$this->url($params); // calls url view helper 
// etc 

有沒有辦法讓這樣的視圖助手沒有每次創建新的對象? 我目前的想法是做一些BaseView類,從Phalcon \ Mvc \ View擴展,並定義一些常用的方法,將使用緩存對象..但我不知道它是最好的方式:

class BaseView extends Phalcon\Mvc\View 
{ 
    // cached helper objects 
    $helpers = []; 

    // view helper call 
    public function url($params) 
    { 
     if (!$this->helpers['url']) { 
      $this->helpers['url'] = new Phalcon\Mvc\Url(); 
     } 
     return $this->helpers['url']->get($params); 
    } 
} 

回答