Kohana configuration
Posted by chaabant on Dec 9, 2011
When doing a PHP project you will need some kind of configuration since we are not using a CMS like WordPress or Joomla , In Kohana we have to do it manually …
Kohana make this process easy , here’s the steps for having a configuration file and using it in our application .
First Step :
Add a new file (site.php) inside the following directory (application -> config -> site.php)
past the following code inside that file :
1 2 3 4 5 |
<?php defined('SYSPATH') or die('No direct script access.'); return array( 'name' => 'PHP Tutorials', 'tag_line' => "Let's talk about kohana!" ); |
<?php defined('SYSPATH') or die('No direct script access.');
return array(
'name' => 'PHP Tutorials',
'tag_line' => "Let's talk about kohana!"
);
Now to use that configuration we could use the following requests :
1 2 3 4 |
// full array $site_config_1 = Kohana::$config->load('site'); // items inside the array $site_config_2 = Kohana::$config->load('site.name'); |
// full array
$site_config_1 = Kohana::$config->load('site');
// items inside the array
$site_config_2 = Kohana::$config->load('site.name');
$site_config_1 would return the full array that we have in our configuration
while
$site_config_2 would only return PHP Tutorials
We could even go farther and add an array inside the array in the configuration file in that case if we wanted to access a specific child we would call it using site.name.child …
Hope this post helped you , if you have any question let me know .