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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:28:34+00:00 2026-06-03T03:28:34+00:00

I’m trying to make a way to disable some view helpers that are inside

  • 0

I’m trying to make a way to disable some view helpers that are inside “application/views/helpers”…

What I really want is to put some options on the application.ini to enable or disable some Helpers.

Example on application.ini:

helpers.Helper1=on
helpers.Helper2=off

Now the problem is that when a Helper is off, I want to rewrite some functions of this helper in order to return a different result on the view. In this way, I don’t need to change anything in the view script.

I thought in having 2 different php files for each helper, in different locations. One with the real helper and another with the changed helper (to work when it is off on the application.ini).

The problem is that I don’t know how to tell the view which one it shoul load…

Does anyone know how it could be done?

FINAL CODE

Ok, after many tries, I put it to work with the following code:

Bootstrap

protected function _initConfigureHelpers(){
    $this->bootstrap('view');
    $view = $this->getResource('view');

    $view->addHelperPath("./../library/ConfigHelpers","Configurable_Helper");
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
        'ViewRenderer'
    );
    $viewRenderer->setView($view);
    $front  = Zend_Controller_Front::getInstance();
    $front->registerPlugin(new Application_Plugin_ViewPlugins());
    return $view;
}

Application_Plugin_ViewPlugins

class Application_Plugin_ViewPlugins extends Zend_Controller_Plugin_Abstract
{

    public function preDispatch(Zend_Controller_Request_Abstract $request){

        $front=Zend_Controller_Front::getInstance();
        $bootstrap=$front->getParam('bootstrap');
        $options=$bootstrap->getOption("helpers");
        if (is_array($options)){
            $view = $bootstrap->getResource('view');

            foreach($options as $option => $value){
                $helper=$view->getHelper($option);
                if ($helper){
                    if ($value=="off")
                        $helper->__disable();
                    else if ($value!="on")
                        throw new Exception('The value of helpers.'.$option.' must be "on" or "off" on application.ini.');
                } else {
                    throw new Exception("Inexistent Helper");
                }
            }
        }
    }

}

Modified helper example

require_once APPLICATION_HELPERS."CssCrush.php";

class Configurable_Helper_CssCrush extends Zend_View_Helper_CssCrush {

    protected $__config_enabled = true;

    public function __disable(){
        $this->__config_enabled = false;
        return $this;
    }


    public function __enable(){
        $this->__config_enabled = true;
        return $this;
    }

    public function cssCrush(){
        if ($this->__config_enabled){
            return parent::cssCrush();
        } else{
            return new Modified_CssCrush();
        }
    }

}

class Modified_CssCrush {

    public static function file ( $file, $options = null ) {
        return $file;
    }

}

APPLICATION_HELPERS is defined on /public/index.php as “../application/views/helpers/”.

Now, when I want to add a configurable helper, I put the original helper on “/application/views/helpers/” and then, create a modified version of it on “/library/ConfigHelpers” with the structure of the example above.

  • 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-03T03:28:35+00:00Added an answer on June 3, 2026 at 3:28 am

    What I think you want is Dependency Injection which is coming in zf2, but not available in zf1.

    With some tinkering though you can get what you need.

    Configuring helpers in the bootstrap

    (assumes default project structure)

    View helpers paths config : application/configs/application.ini:

    resources.view.helperPath.Zf_View_Helper_ = "Zf/View/Helper"
    

    A simple configurable helper, (allows disable/enable but you can obviously add any methods you need (use this as base class for helpers that need the behaviour)

    class Zf_View_Helper_Configurable extends Zend_View_Helper_Abstract
    {
        protected $isEnabled = true;
    
        public function configurable()
        {
            return $this;
        }
    
        public function disable()
        {
            $this->isEnabled = false;
            return $this;
        }
    
    
        public function enable()
        {
            $this->isEnabled = true;
            return $this;
        }
    
        public function __toString()
        {
            if ($this->isEnabled) {
                return 'Configurable is enabled';
            } else {
                return 'Configurable is disabled';
            }
        }
    }
    

    And configure the helpers in the bootstrap:

    public function _initConfigureHelpers()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
    
        $configurableHelper = $view->configurable();
        $configurableHelper->disable();
    }
    

    You can add options in the .ini file and grab them in the bootstrap initConfigureHelpers() method.

    If you want this behaviour from any default zf helper, do what @Ratzo said and extend those helpers and add the required behaviour and then configure them in your bootstrap.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.