开发者

How can i make my own view helpers such as $this->partial or $this->render?

开发者 https://www.devze.com 2023-03-09 03:12 出处:网络
Like we can do $this->partial(); or $this->render() with Zend Framework. How can i make my own $this->myOwnStuff(); ?

Like we can do $this->partial(); or $this->render() with Zend Framework. How can i make my own $this->myOwnStuff(); ?

Example:
Before:
<tr>
 <td>label</td>
 <td>value1</td>
</tr>
<tr>
 <td>label2</td>
 <td&开发者_Python百科gt;value2</td>
</tr>

After:
$this->tr(
  array(
    "label"=>"value1", "value"=> "value1"
    "label"=>"value2", "value"=> "value2"
  )
);


It's pretty easy. If you want to create a helper, just create a new helper class and plot it in /application/views/helpers. Of if you're structuring it so that you have your own library putting it in library/My_Library/View/Helper will also work.

Make sure to extend from the base helper abstract. Something along the lines of

class My_View_Helper_Stuff extends Zend_View_Helper_Abstract {
}

Here's an article that goes into greater detail about the matter : http://devzone.zend.com/article/3412

0

精彩评论

暂无评论...
验证码 换一张
取 消