Global Strings! |
[eluser]jordanarseno[/eluser]
Hello everyone, I created a php file called site_specific.php in CI/applications/config/ to store site specific information that will never change: Code: <?php Now at the top of my header.php view I want to be able to include this file. So used a simple php include... Code: <?php include(base_url() . "application/config/site_specific.php");?> Now I'm getting errors: Message: include() [function.include]: http:// wrapper is disabled in the server configuration by allow_url_include=0 Message: include(http://localhost/CI/application/site_specific.php) [function.include]: failed to open stream: no suitable wrapper could be found If I use the following...it works, but it is undesirable!: Code: <?php include("/opt/lampp/htdocs/CI/application/site_specific.php");?> I tried moving site_specific.php out of the config folder,because maybe CodeIgniter locks down the config directory? - But the errors still flow. I know this goes against the MVC pattern, but it seemed like the easiest way to get static information to the view without making a mess of all my controllers.
[eluser]kaejiavo[/eluser]
Hi, you can use a config file e.g. CI/applications/config/myconfig.php with the following syntax: Code: $config['title'] = 'Title'; To use it in your controllers: Code: $this->load->config('myconfig', TRUE); Marco
[eluser]jordanarseno[/eluser]
Thank you! - That was a very informative article. I left a comment on Phil's blog, but his processing engine destroyed half of my message, and it won't let me post a new one Therefore, question for you, and you...and you! I followed Phil's method - I now have a MY_Controller class. Now, he mentioned at the bottom of his post, I quote: Quote:You can also use $this->load->vars('foo', $bar) in your Base Controllers to set values that are only available in your views. So in MY_Controller, I have the following: Code: $arr = array ( And in my view: Code: <?php echo $arr['test1'];?> I'm getting the error: Message: Undefined variable: arr Why!!
[eluser]Twisted1919[/eluser]
Code: echo $test1 ;
[eluser]jordanarseno[/eluser]
Hi Twisted, Thanks - but: Message: Undefined variable: test1 now...
[eluser]Twisted1919[/eluser]
Weird, but what if, you do like so : Code: //MY CONTROLLER
[eluser]jordanarseno[/eluser]
Hey Twisted, I played around with your code a bit - eventually tweaked my scripts so that it works perfectly! Your help is much appreciated - this global string stuff is going to really make my life easier; no longer do I have to send additional data from controllers to views! Keep it DRY!
[eluser]John_Betong[/eluser]
Maybe this will get you over the hump and be able to proceed to the next "Gotcha"... To use site specific information that will not change, you can store the information in your MY_Controller file: Code: // My_Controller
[eluser]Twisted1919[/eluser]
Glad it helped, actually this is the way i do it(and think the most of programmers), i have a $data var in MY_Controller, then when passing data for the view i just $this->data['something'] = 'something'; then pass $this->data when loading the view. |
Welcome Guest, Not a member yet? Register Sign In |