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 8844157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:24:56+00:00 2026-06-14T11:24:56+00:00

I know with ZF1 you would retrieve the module/controller name using custom View Helpers

  • 0

I know with ZF1 you would retrieve the module/controller name using custom View Helpers that would get the singleton frontController object and get the name there.

Using ZF2 as they’ve abolished alot of the singleton nature of the framework and introduced DI where I’ve specified aliases for all of my controllers within this module… I can imagine I would get it through accessing the DI or perhaps injecting the current name into the layout.

Anyone got any idea how you would do it. I guess there a hundred different ways but after sniffing about the code for a few hours I can’t really figure out how its meant to be done now.

The reason I wanted the controller name is to add it to the body as a class for specific controller styling.

Thanks, Dom

  • 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-14T11:24:58+00:00Added an answer on June 14, 2026 at 11:24 am

    ZF2 is out and so is the skeleton. This is adding on top of the skeleton so it should be your best example:

    Inside Module.php

    public function onBootstrap($e)
    {
        $e->getApplication()->getServiceManager()->get('translator');
        $e->getApplication()->getServiceManager()->get('viewhelpermanager')->setFactory('controllerName', function($sm) use ($e) {
            $viewHelper = new View\Helper\ControllerName($e->getRouteMatch());
            return $viewHelper;
        });
    
        $eventManager        = $e->getApplication()->getEventManager();
        $moduleRouteListener = new ModuleRouteListener();
        $moduleRouteListener->attach($eventManager);
    }
    

    The actual ViewHelper:

    // Application/View/Helper/ControllerName.php
    
    namespace Application\View\Helper;
    
    use Zend\View\Helper\AbstractHelper;
    
    class ControllerName extends AbstractHelper
    {
    
    protected $routeMatch;
    
        public function __construct($routeMatch)
        {
            $this->routeMatch = $routeMatch;
        }
    
        public function __invoke()
        {
            if ($this->routeMatch) {
                $controller = $this->routeMatch->getParam('controller', 'index');
                return $controller;
            }
        }
    }
    

    Inside any of your views/layouts

    echo $this->controllerName()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know how to get the machines on a server using the System.DirectoryServices network.
Know if it's possible to access the iPhone compass in Safari using JavaScript? I
I know that Phonegap has an event for back button, but it's only available
I know that this sort of question has been asked here before, but still
I know there are lots of tools on the net that can make our
I know that if port 443 is open that means the remote host supports
I know that delete is a keyword in JavaScript. So I have this code
I know this is a somewhat abstract question and that an answer depends on
I know that when we use App Wizard for creating an MFC application in
I know that we can stop inheritance of the web.config files from the root

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.