Welcome Guest, Not a member yet? Register   Sign In
A simple config class issue
#1

[eluser]Dagobert Renouf[/eluser]
Hello guys,

I'm currently optimizing my first app code (a bit messy 'round here) and I'm trying to write config files to store MY specific data.

I created a file named "my_db_parameters" in the system/config folder, and I autoload it.

here's the file's code :
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$config['my_db_tables'] = array('blog' => 'blog_entries');

?>

when I try to call it in my blog model like this :
Code:
$this->config->my_db_tables('blog')

I have an error
Quote:Fatal error: Call to undefined method CI_Config::my_db_tables()

I don't get why this doesn't work, help me out BROTHERS.
#2

[eluser]xwero[/eluser]
Code:
$tables = $this->config->item('my_db_tables');
$blog_table = $tables['blog'];
If you want direct access you can do
Code:
$config['db_table_blog'] = 'blog_entries';
#3

[eluser]Dagobert Renouf[/eluser]
thank you xwero it works fine.

However I would like to ask - what's the best way to achieve my goal (storing my specific data)?
The second method seems better to me but there are so many ways to do this, what do you guys advice ?
#4

[eluser]xwero[/eluser]
less code is in most cases the best way to go.
#5

[eluser]Dagobert Renouf[/eluser]
thanks.

nothing more to say.




Theme © iAndrew 2016 - Forum software by © MyBB