1

Here is my helper class

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
    }
}

and My question is , I needed to add a new function to this class. I have tried by adding new function like

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

to the above class, but I am getting eror something like Plugin by name 'AddBox' was not found in the registry;

Here I need to know Can I add more functions to the helper class , if yes how is this possible.

1 Answer 1

2

First, you should return all output, not echo it directly.

From the Zend_View_Helper docs:

In general, the class should not echo or print or otherwise generate output. Instead, it should return values to be printed or echoed. The returned values should be escaped appropriately.

When you call $this->commonArea() from the view, it will load the 'CommonArea' class, and then call the matching method. So a call to $this->addBox() will look for the 'AddBox' class - it won't know that you expect it to be part of the 'CommonArea' plugin.

If you want to call multiple methods from the same plugin, have the matching method return an instance of the plugin:

public function commonArea(){
  return $this;
}

Then call the methods like this:

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

You could look at the navigation helper or the placeholder helper to see this pattern.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.