Note that there are some explanatory texts on larger screens.

plurals
  1. POProper way to use a config file?
    text
    copied!<p>I just started using a PHP framework, Kohana (V2.3.4) and I am trying to set up a config file for each of my controllers. </p> <p>I never used a framework before, so obviously Kohana is new to me. I was wondering how I should set up my controllers to read my config file. </p> <p>For example, I have an article controller and a config file for that controller. I have 3 ways of loading config settings</p> <pre><code>// config/article.php $config = array( 'display_limit' =&gt; 25, // limit of articles to list 'comment_display_limit' =&gt; 20, // limit of comments to list for each article // other things ); </code></pre> <p>Should I</p> <p>A) Load everything into an array of settings</p> <pre><code>// set a config array class article_controller extends controller{ public $config = array(); function __construct(){ $this-&gt;config = Kohana::config('article'); } } </code></pre> <p>B) Load and set each setting as its own property</p> <pre><code>// set each config as a property class article_controller extends controller{ public $display_limit; public $comment_display_limit; function __construct(){ $config = Kohana::config('article'); foreach ($config as $key =&gt; $value){ $this-&gt;$key = $value; } } } </code></pre> <p>C) Load each setting only when needed</p> <pre><code>// load config settings only when needed class article_controller extends controller{ function __construct(){} // list all articles function show_all(){ $display_limit = Kohana::config('article.display_limit'); } // list article, with all comments function show($id = 0){ $comment_display)limit = Kohana::config('article.comment_display_limit'); } } </code></pre> <p>Note: Kohana::config() returns an array of items.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload