Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8095777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:14:47+00:00 2026-06-05T21:14:47+00:00

NOTE: This is an old question and the answers here no longer works (since

  • 0

NOTE: This is an old question and the answers here no longer works (since beta5). See this question on how to do it with ZF2 stable version.

I have looked at this example from the manual. Note that this is version 2 of the Zend Framework.

I create this helper:

<?php
namespace Mats\Helper;    
use Zend\View\Helper\AbstractHelper;    
class SpecialPurpose extends AbstractHelper
{
    protected $count = 0;    
    public function __invoke()
    {
        $this->count++;
        $output = sprintf("I have seen 'The Jerk' %d time(s).", $this->count);
        return htmlspecialchars($output, ENT_QUOTES, 'UTF-8');
    }
}
?>

and then try to register it like this:

return array(
    'di' => array('instance' => array(
        'Zend\View\HelperLoader' => array('parameters' => array(
            'map' => array(
                'specialpurpose' => 'Mats\Helper\SpecialPurpose',
            ),
        )),
    )),
);

but when doing this in a view, for instance add.phtml

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

It will crash, saying it cannot find the helper.

However, in the same add.phtml file I can do

<?php $helper = new Mats\Helper\SpecialPurpose(); ?>

and have access to it, so I guess the namespace should be right?

Currently I register it in Module.php, but I have also tried elsewhere.

My goal is to have access to the view helper in all views in my module, without having to create an instance of it in each phtml file, and not having to add it every time in the controller.

How can this be achieved? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T21:14:49+00:00Added an answer on June 5, 2026 at 9:14 pm

    ZF2 moved to service managers with programmatic factories, while di used as fallback factory.

    For view there is view manager now and as service resolution stops as soon as it found factory, helpers configured via di no longer work.

    Example how you should register helpers now you can find in ZfcUser module config

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

NOTE: This is a followup to my question here. I have a program that
Note: This question refers to a very old version of jQuery.validate() (version 1.5). This
I have an Interbase 5.5 database (note: this is a very old version, from
Note: This question has broadened in scope from previous revisions. I have tried to
Note: This problem occurs only on Mac, on Windows works fine. I have a
Please note that I have already been through similar questions and their answers here
NOTE: This question deals with an issue observed back in 2011 with an old
EDIT The bare-bones version of this question is, if I have some object o
(Note: This is not a question about what is the best way with code
Note: this question has nothing to do with Knockout.js, but it's about the selectedOptions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.