2011-11-23 200 views
1

添加更多的功能,以辅助类下面是我的助手类在Zend公司

class Zend_View_Helper_CommonArea extends Zend_View_Helper_Abstract { 

    public function commonArea() 
    { 
     ?> 

     <div class="clear"></div> 
     <div id="quick_search"> 
      <div class="search"> 
         <strong>QUICK SEARCH </strong> 

        <input type="text" name="keyword" id="keyword" value="Enter keywords" class="form" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;" /> 
       <select name="select" id="select" class="selectstyled"> 
        <option>Prefered Location</option> 
        <option>Prefered Location</option> 
        <option>Prefered Location</option> 
        <option>Prefered Location</option> 
        <option>Prefered Location</option> 
       </select> 
      </div> 
      <div class="bt_box"> 
       <input name="find" type="submit" class="find" id="search" value="Find Jobs" /> 
      </div> 
      <div class="resume"><a href="jobseeker.html"><img src="images/resume.jpg" alt="" /></a></div> 
     </div> 


     <?php 
    } 
} 

和我的问题是,我需要一个新的功能添加到这个类。我通过增加新的功能,试图像

public function addBox() 
    { 
     ?> 
     <div id="add_right_box"style="height:500px;"><h3 class="add_h2">Width 210px</h3></div> 
     <?php 
    } 

到上面的类,但我正在逐渐eror像 插件的名字“AddBox”在注册表中未找到;

在这里,我需要知道我可以添加更多的功能的助手类,如果是的话,这是如何可能的。

回答

2

首先,您应该返回所有输出,而不是直接回显它。

Zend_View_Helper docs

一般来说,类不应回声或打印或以其他方式产生输出。相反,它应该返回要打印或回显的值。返回的值应该适当地转义。

当您从视图中调用$this->commonArea()时,它将加载'CommonArea'类,然后调用匹配方法。因此,拨打$this->addBox()的电话会查找“AddBox”类 - 它不会知道您期望它是“CommonArea”插件的一部分。

如果你想调用来自同一个插件的多个方法,具有匹配的方法返回该插件的一个实例:

public function commonArea(){ 
    return $this; 
} 

然后调用这样的方法:

$this->commonArea()->addBox(); 
$this->commonArea()->display(); //assuming you renamed the original method to 'display' 

你可以看看navigation helperplaceholder helper看到这种模式。