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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:49:09+00:00 2026-06-14T06:49:09+00:00

In an effort to keep my code DRY I would like to be able

  • 0

In an effort to keep my code DRY I would like to be able to define “cross controller” variables.

Classic example is that I would like access to some config items that are loaded in my bootstap.

What is the best practise method of achieving this?

Tim

  • 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-14T06:49:11+00:00Added an answer on June 14, 2026 at 6:49 am

    You can always use the Di container.

    Once you register a component in the Di it is available in the controller by the magic method. For instance:

    // Bootstrap
    $configFile = ROOT_PATH . '/app/config/config.ini';
    
    // Create the new object
    $config = new \Phalcon\Config\Adapter\Ini($configFile);
    
    // Store it in the Di container
    $this->di->setShared('config', $config);
    

    and in your controller it is as simple as:

    $config = $this->config;
    

    If you create a base controller class, you can pass those objects in the view if needed like so:

    $this->view->setVar('config', $this->config);
    

    Finally the Di container can act also as a registry, where you store items you might want to use in your application.

    For an example of bootstrapping and accessing objects in controllers, have a look at the phalcon/website repository. It implements bootstrapping and base controller patterns among other things.

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

Sidebar

Related Questions

In an effort to keep code down I was hoping to use regular expressions
I have a large collection of my personal scripts that I would like to
I am making the effort to learn Vim. When I paste code into my
In an effort to 'clean up' my code - I was wondering if this
There is a lot of effort in the Silverlight community to keep a XAML's
I have written the following code in an effort to try and compute the
If we've learned anything from HTML/CSS it's that, declarative languages (like XML) do a
First keep in mind I am new to nop/mvc, and despite my best effort
I try to keep the Java Runtime Environment from being enabled in an effort
I have, for example, a UIButton that I placed in IB. This UIButton has

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.