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

  • Home
  • SEARCH
  • 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 8781775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:23:32+00:00 2026-06-13T20:23:32+00:00

I cannot seem to register a custom view helper in zend Framework 2.02 I

  • 0

I cannot seem to register a custom view helper in zend Framework 2.02 I tried all solutions posted here and anything I can think I should do but I keep getting this error:

Fatal error: Class ‘ModuleName\view\Helper\mylinkhelper’ not found in C:\wamp\vhosts\projectName\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php on line 177

And here’s how my module.config.php looks like:

return array{
      'controllers'=>array(

           ....
       ),
      'view_manager' => array(
          'template_path_stack' => array(
             'ModuleName' => __DIR__ . '/../view',
           ),    
   ),
   'view_helpers' => array(  
            'invokables' => array(  
                 'mylink' => 'ModuleName\view\Helper\mylinkhelper',   
             ),  
       ),
};

in my view file, I have:

echo $this->mylink($someparameter); 

I appreciate any feedback on this. I don’t really know what else to do here.

  • 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-13T20:23:34+00:00Added an answer on June 13, 2026 at 8:23 pm
    <?php
    // ./module/Application/src/Application/View/Helper/AbsoluteUrl.php
    namespace Application\View\Helper;
    
    use Zend\Http\Request;
    use Zend\View\Helper\AbstractHelper;
    
    class AbsoluteUrl extends AbstractHelper
    {
        protected $request;
    
        public function __construct(Request $request)
        {
            $this->request = $request;
        }
    
        public function __invoke()
        {
            return $this->request->getUri()->normalize();
        }
    }
    

    You’ll notice that this particular helper has a dependency — a Zend\Http\Request object. To inject this, we’ll need to set up a factory with the initialization logic for our view helper:

        <?php
        // ./module/Application/Module.php
        namespace Application;
    
        use Application\View\Helper\AbsoluteUrl;
    
        class Module
        {
            public function getViewHelperConfig()
            {
                return array(
                    'factories' => array(
                        // the array key here is the name you will call the view helper by in your view scripts
                        'absoluteUrl' => function($sm) {
                            $locator = $sm->getServiceLocator(); // $sm is the view helper manager, so we need to fetch the main service manager
                            return new AbsoluteUrl($locator->get('Request'));
                        },
                    ),
                );
            }
    
    
         // If copy/pasting this example, you'll also need the getAutoloaderConfig() method; I've omitted it for the sake of brevity.
    }
    

    That’s it! Now you can call your helper in your view scripts:

    The full URL to the current page is: <?php echo $this->absoluteUrl(); ?>

    thanks to evan to create this tutorial

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

Sidebar

Related Questions

I cannot seem to get this date picker working at all. I know it
Just getting started here and cannot seem to get this very basic thing working.
I have tried several different submit buttons but can not seem to get this
Cannot seem to loop through the XElement and build a datatable. My XElement will
I cannot seem to get user entered data into a table and then printed.
I cannot seem to figure out I am getting the following error in IE
i cannot seem to find the answer to this. i uploaded code to pastebin
I cannot seem to write to a file. I create the file and directory
I cannot seem to find a way to have LINQ return the value from
I cannot seem to get the quotes around this statement right. No matter what

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.