Where is the best place to include inc file?? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Where is the best place to include inc file?? (/showthread.php?tid=52709) |
Where is the best place to include inc file?? - El Forum - 06-22-2012 [eluser]OKIEWARDOYO[/eluser] I have a code like below Note that $options is a variable in file options.inc.php Code: class Welcome extends CI_Controller { I'm confusing, where is the best place to place the line of code include "options.inc.php"; i want the code like below Code: class Welcome extends CI_Controller { thanks Where is the best place to include inc file?? - El Forum - 06-22-2012 [eluser]OKIEWARDOYO[/eluser] So here is my story, i'm creating an application like structure below my_cms/ application/ system/ inc/ i have placed options.inc.php in inc folder this file contain main array of all my_cms configuration <? $options = array( 'status_index' => 0, 'status_read' => 1, 'status_write => 2, ); ?> on index.php, i have define a path for this file, define('INCPATH', CURRDIR.'inc/'); Now, where should i put this include "options.inc.php" so i can make a global variable for $options from every function in model or controller page?? should i include this file on index.php? Where is the best place to include inc file?? - El Forum - 06-22-2012 [eluser]PhilTem[/eluser] You may include it in any file you want, but you must be sure to not include it within any class or any class' method. I'd suggest you create a MY_Controller in ./application/core/ and put the 'include' line before you start the description of your MY_Controller class: Code: <?php However, it is much more MVC-/CI-style to create a config file of your configs, put it into ./application/config/your_config.php and have the config file being autoloaded within ./application/config/autoload.php in $autoload['config']. That way it will also be global put you do it in a better way. You can then access your config-items with Code: config_item('status_read'); Where is the best place to include inc file?? - El Forum - 06-23-2012 [eluser]OKIEWARDOYO[/eluser] Hem, thanks for reply, what about if i have another example like below, this is my project structure for example, root/ __application/ ____models/ ______mymodellang.php __system/ __lang/ ____en.php __index.php __.htaccess look, i have an en.php there, this en.php contain the code like below, it's an array Code: <? and, i have a mymodellang.php as the model of project, Code: <?php My problem is on my model, my translate function above contain @include(LANGPATH.'en.php'); I want to delete this line of code from the translate function, place it somewhere that can be access by global $langs. but i don't know where to placed. i have tried putting like below but no luck, Code: <?php i want this en.php stay on folder lang/ i don't want to create my_controller or another extra config, can somebody help me?? thanks Where is the best place to include inc file?? - El Forum - 06-23-2012 [eluser]OKIEWARDOYO[/eluser] anyone? Where is the best place to include inc file?? - El Forum - 06-23-2012 [eluser]PhilTem[/eluser] I know this may sound stupid again, but why don't you stick with the load of classes that CI provides you? I'd recommend you put your languages in one file in ./application/language/english/your_lang.php and load it via Code: $this->lang->load('your_lang', 'english'); Then you can access any language line with Code: $this->lang->line('_Home'); Otherwise it must work if you add the include before declaring the model-class (as long as your LANGPATH constant is defined well, it will work. Try to remove the @ before the include and see if you get any errors prompted) |