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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:29:46+00:00 2026-05-27T03:29:46+00:00

I’ve got a common set of functionality I’d like to embed into a Zend_Application

  • 0

I’ve got a common set of functionality I’d like to embed into a Zend_Application instance using the configs parameter inside of that app’s Zend_Config instance. However, the slaved configuration file would like to be able to refer to things in a path relative to itself. For instance:

$/application/configs/application.ini:

[base]
config[] = APPLICATION_PATH "../CasCommon/Configs/common.ini

$/CasCommon/Configs/common.ini

[base]
resources.frontController.controllerDirectory[] = PATH_TO_THIS_IN_DIR "../Controllers"
resources.frontController.actionHelperPaths.Cas_Common_Helper = PATH_TO_THIS_IN_DIR "../ControllerHelpers"
;...

How might one accomplish such a thing?

  • 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-05-27T03:29:46+00:00Added an answer on May 27, 2026 at 3:29 am

    PHP supports constants in Ini files, but unfortunately not magic constants, so you cannot use __DIR__, which would solve the problem. The easiest and most obvious thing would be defining the path to the application.ini file as a constant just like you did with APPLICATION_PATH, e.g.

    // application.ini
    foo = INI_PATH '/../somewhere/else'
    
    // index.php
    const INI_PATH = '/path/to/config/folder';
    

    Then just load your Zend_Application regularly or instantiate a new Zend_Config and the constant will be evaluated like you wanted.

    Edit after comments

    I find that argument about the above being not automagic enough moot. In a standard ZF project, the APPLICATION_PATH is defined in the index.php file and that’s also where the default application.ini is loaded. All you have to do is add the constant there. The Ini file won’t exist on it’s own anyway so someone will have to call an external library at some point (likely you as the developer). The above solution requires one line of setup. Any other solution requires more work.

    If that is not good enough for you, you can extend Zend_Application to automatically add that constant before the application.ini gets loaded:

    class My_Zend_Application extends Zend_Application
    {
        protected function _loadConfig($file)
        {
            if (!defined('PATH_TO_INI')) {
                define('PATH_TO_INI', dirname(realpath($file)));
            }
            return parent::_loadConfig($file);
        }
    }
    

    Of course, you will still have to change index.php to use your extended My_Zend_Application then which is why I find this approach rather pointless given that you can also just add the constant in the index.php file.

    A custom Zend_Application will limit you to the application.ini of course because you cannot change the constant at runtime anymore. So if you need this functionality for multiple Ini files and not just the application.ini, extend Zend_Config_Ini and check each value for a Relative Path marker before it is returned, e.g.

    class My_Config_Ini extends Zend_Config_Ini
    {
        protected $_relativePath;
        protected $_relativePathMarker = '%REL_PATH%';
        public function __construct($filename, $section = null, $options = false)
        {
            $this->_relativePath = dirname(realpath($filename));
            parent::__construct($filename, $section, $options);
        }
        public function get($name, $default = null)
        {
            if (array_key_exists($name, $this->_data)) {
                return $this->_containsRelativePathMarker($this->_data[$name])
                    ? $this->_expandRelativePath($this->_data[$name])
                    : $this->_data[$name];
            }
            return $default;
        }
        protected function _containsRelativePathMarker($value)
        {
            return strpos($value, $this->_relativePathMarker) !== FALSE;
        }
        protected function _expandRelativePath($value)
        {
            return str_replace('%REL_PATH%', $this->_relativePath, $value);
        }
    }
    

    The above assumes you write your Ini files with something like

    foo = %REL_PATH% '/../foo.txt'
    

    If that is still not what you are looking I can only encourage you once more to put up precise requirements. There is no point in offering 500 reputation when you are not going to accept any answers here because we failed to read your mind.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
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 a string like this: La Torre Eiffel paragonata all’Everest What PHP function
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 would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.