TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Globally Access Variables
  • I have a couple of arrays that I want to be available for all pages. Where do I put the include_once call? Right now I put this call at the top of the view, but it still errors with 'undefined variable'. Also I don't want to have to put the include in every file that uses it. Where can I put it so I only have to include it once?

    //view file
    <?php require_once DOCROOT . 'assets/files/gamedata.php' ?>
    echo $aTeamArray[1];  // this line errors with undefined variable
    //gamedata.php file
    $aTeamArray = array();
    $aTeamArray[1] = array('city' => 'Baltimore', 'nickname' => 'Orioles', 'league' => 'AL', 'division' => 'East', 'abbr' => 'BAL');
    $aTeamArray[2] = array('city' => 'Boston', 'nickname' => 'Red Sox', 'league' => 'AL', 'division' => 'East', 'abbr' => 'BOS');
    $aTeamArray[3] = array('city' => 'New York', 'nickname' => 'Yankees', 'league' => 'AL', 'division' => 'East', 'abbr' => 'NYY');
    $aTeamArray[4] = array('city' => 'Tampa Bay', 'nickname' => 'Rays', 'league' => 'AL', 'division' => 'East', 'abbr' => 'TB');
    $aTeamArray[5] = array('city' => 'Toronto', 'nickname' => 'Blue Jays', 'league' => 'AL', 'division' => 'East', 'abbr' => 'TOR');
  • Read @wintersilence comment. I personally put a file in app/config/app.php and then use


    I even use this file to populate other config files so I can keep all of the config in this one app.php file

    If you want to do a include in all your controllers, you can put it in your base controller classes before()

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion