Welcome Guest, Not a member yet? Register   Sign In
Unknown column 'email' in 'field list'
#1

[eluser]stoefln[/eluser]
its the first time i get really angry about codeigniter: why is it possible that i have a field 'email' in my model, although i never declared this? the referencing of $this is very strange in models- i already noticed that members of the controller class are automatically available in models too- WTF?

Any help is appreciated very much!
#2

[eluser]pistolPete[/eluser]
Quote:Any help is appreciated very much!
Without having seen any of your code it's almost impossible!
#3

[eluser]stoefln[/eluser]
[quote author="pistolPete" date="1236010081"]
Quote:Any help is appreciated very much!
Without having seen any of your code it's almost impossible![/quote]

Yeah, absolutely!
the problem is that i dont know which code to post, cause i dont know where this email-property gets set. and thats exactly the thing i m critisising: if there is a $this->property set anywhere it will be available anywhere and therefor a main concept of object oriented programming is lost: encapsulation.

i just tried to debug the Model class: found out that it gets initialised several times, and the email property is set right with the email-library instance the first view times.

But all at once it is set with a email adress string of the current logged in user.

Maybe you have an idea how to debug this further?
#4

[eluser]TheFuzzy0ne[/eluser]
$this->email is the email library. It's accessible from both your model and from your controller. When CodeIgniter loads a model, the model imports methods and properties from the CodeIgniter Super Object. If you don't want that behaviour, you can override it.

./system/application/libraries/MY_Model.php
Code:
class MY_Model extends CI_Model {

    function _assign_libraries() { }

}
// End of File: MY_Model.php
// Location: ./system/application/libraries/MY_Model.php

The above code is untested, but should suppress the behaviour you mentioned.
#5

[eluser]wiredesignz[/eluser]
It's probably not wise to override _assign_libraries() as the model relies on this function to get access to the database object from the Controller as well as other things such as the loader.
#6

[eluser]TheFuzzy0ne[/eluser]
Good thinking

Code:
class MY_Model extends CI_Model {

    function _assign_libraries() {
        $CI =& get_instance();
        $this->db =& $CI->db;
    }

}
// End of File: MY_Model.php
// Location: ./system/application/libraries/MY_Model.php

Unless there's something else I forgot, that should do the trick.
#7

[eluser]stoefln[/eluser]
[quote author="TheFuzzy0ne" date="1236013505"]Good thinking

Code:
class MY_Model extends CI_Model {

    function _assign_libraries() {
        $CI =& get_instance();
        $this->db =& $CI->db;
    }

}
// End of File: MY_Model.php
// Location: ./system/application/libraries/MY_Model.php

Unless there's something else I forgot, that should do the trick.[/quote]

yeah, thats exactly what i just did.
i think this should be done in CI by default- cause emails shouldnt be sent out of models anyway. CI should support a good programming-style IMO.
#8

[eluser]xwero[/eluser]
[quote author="stoefln" date="1236013855"]i think this should be done in CI by default- cause emails shouldnt be sent out of models anyway. CI should support a good programming-style IMO.[/quote]
I don't think it's possible to not bind certain objects from the CI instance because you can attach so many objects and variables to the CI instance.

Kohana solves this by not binding the instance to the classes that are known but instead call the instance direct.
Code:
$value = Kohana::instance()->uri->segment(3);
#9

[eluser]wiredesignz[/eluser]
Code:
$value = CI_Base::get_instance()->uri->segment(3);

PHP5 only Wink
#10

[eluser]xwero[/eluser]
[quote author="wiredesignz" date="1236015230"]
Code:
$value = CI_Base::get_instance()->uri->segment(3);

PHP5 only Wink[/quote]
Damn edited too fast to make a php5 only comment Smile




Theme © iAndrew 2016 - Forum software by © MyBB