CodeIgniter Forums

Full Version: vars in own config file not available on other server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]LuckyFella73[/eluser]
hi,

I have a strange problem right now:
I have a config file where my db table names and other stuff is defined
which is loaded in every controller. It works at my local xampp webserver
but not at the productive server.

I load the file in the controller this way:
Code:
$this->load->file('system/application/config/config_sktv_admin.php', true);

And the vars defined in my config file look like:
Code:
$this->tbl_news_de = 'de_news';
$this->tbl_news_en = 'en_news';
// and so on

In my controller/method I use the vars like this:
Code:
$data['total_offline'] = $this->news_model->count_offline_entries($this->tbl_news_de);
$data['total_online'] = $this->news_model->count_online_entries($this->tbl_news_de);

The error message (calling the "home" controller) is:
Quote:A PHP Error was encountered
Severity: Notice

Message: Undefined property: Home::$tbl_news_de

Filename: controllers/home.php

Line Number: 44

I don't know where to look for an error anymore so it would
be great to get a hint what to do!

El Forum

[eluser]InsiteFX[/eluser]
Hi,

Did you try this?

Code:
$data['total_offline'] = $this->news_model->count_offline_entries(tbl_news_de);
$data['total_online'] = $this->news_model->count_online_entries(tbl_news_de);

Not sure if thats the problem but I do not think that you need $this on there.
$this refers to the object that you are in say controller.

Enjoy
InsiteFX

El Forum

[eluser]LuckyFella73[/eluser]
It would work if I hardcode the tablenames but that
isn't what I want. I use the table name in the controller
many times and in case the table name has to be changed
I just want to change the name once in my config file.

As mentioned that works on my local pc just not on the
clients server ..

Thank you for trying to help anyway!

El Forum

[eluser]John_Betong[/eluser]
 
A quick KLUDGE would be to set $_SESSION['tbl_news_de'] = 'table_name';
 
 
 
 

El Forum

[eluser]Aken[/eluser]
The error itself is saying that there is no var that exists in $this->tbl_news_de. $this in the context you're using is referring to the master CI class. You need to figure out what kind of information is being returned when you load your config file, and then go from there.

I'm curious why you're defining your own config files like that, and then using $this->load->file() to get them? There's specific functions built into CI's config system for creating and loading your own config items. ($this->config->load() for instance).

El Forum

[eluser]LuckyFella73[/eluser]
I managed my config / vars like described in my first
post in at least 10 projects without having problems,
so it seems to be a server issue. The server having trouble
is set up:
Quote:"Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny3 with Suhosin-Patch"


I found an other thread where a simular problem occoured and
the guy said after updating the debian version the problem
disappeared.
http://ellislab.com/forums/viewthread/127255/


But to keep my projects cleen in the future I will set up
my config file like described in the user guide. I just prefered
to do it the way I did untill yet because it was much easier
to define the needed ways.

Thank you all for your support !!

El Forum

[eluser]n0xie[/eluser]
I don't know if this would work but you could try to just include your config file in the construct of your controller. In theory this should assign your variables to the CI object.
Code:
function __construct()
    {    
        require(APPPATH.'config/config_sktv_admin.php');
    }

Although loading the config files the codeigniter way seems like a cleaner solution to me.

El Forum

[eluser]LuckyFella73[/eluser]
Do you mean the function in the controller having the
same name as the controller (I allway thought that is
the contructor) where to put the "requiered" part you
described? Sorry for asking such stupid questions - I allways
have some problems with this kind of terminology.

Or do I have to set up "__construct()" in my controller?

I tested your code this way:
Code:
class News extends Controller {

    function News()
    {
        parent::Controller();
require(APPPATH.'config/config_sktv_admin.php');
// here more code
but that didn't work

I think the best is to use the CI config-system in future to
avoid problems of that kind.

Thanks again!