0
votes

I was wondering when to call from the view a Custom View Helper like this one

<?php
class Zend_View_Helper_MyHelper
{
    public $view;

    public function setView(Zend_View_Interface $view)
    {
        $this->view = $view;
    }

    public function myHelper()
    {
        return $this->view->escape(
            ’This is being output from the custom helper <br />’
        );
    }
}
?>

and an action view helper.

Thanks. Yehia A.Salam

2
What is the "action view helper"? There are view-helpers and action-helpers. view-helpers are for common code used in the view, action-helpers are used for common code used in the controllers.Benjamin Cremer
framework.zend.com/manual/en/zend.view.helpers.html scroll for the action view helper, they're called from inside the view, my question is when to use what, i could implement the same functionality using either method, but what is better suited for what, thanksYehia A.Salam

2 Answers

1
votes

Why would you do this?

You could easily do:

class Zend_View_Helper_MyHelper extends Zend_View_Helper_Abstract
{
    public function myHelper()
    {
        return "This is output from the custom helper<br/>";
    }
}

and then do a:

<?php echo $this->myHelper(); ?>

on your view script

1
votes

In ZF, there are View Helper and Action Helper, which have been discussed here so so many times so I won't repeat. But Ben asked "What is Action View helper?" Action View Helper is a View Helper that calls an action of a controller.

Here is an example of Action View Helper from ZF manual:

    <div id="sidebar right">
    <div class="item">
       <?php echo $this->action('list',
                                'comment',
                                null,
                                array('count' => 10)); ?>
    </div>
    </div>