CodeIgniter Forums
Object oriented CI - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Object oriented CI (/showthread.php?tid=51625)



Object oriented CI - El Forum - 05-11-2012

[eluser]Christer_[/eluser]
Hi all - could you give me a hint as to go with this problem -

I would like to be able to use current code..

Code:
$this->user-id

$this->account->id

How can i setup this perspective with CI ?


Object oriented CI - El Forum - 05-11-2012

[eluser]Christer_[/eluser]
After a second and third tougth - would this be best to implement as a model with autoload and a construct method that just checks if the session has been initialized and gets the database values from there?


Object oriented CI - El Forum - 05-11-2012

[eluser]Spir[/eluser]
You are not telling enough to be clear. What do you want to accomplish here?
Also I guess you meant $this->user->id instead of $this->user-id?


Object oriented CI - El Forum - 05-11-2012

[eluser]jmadsen[/eluser]
CI is built with php. stdClass works the same here as anywhere else.


Object oriented CI - El Forum - 05-11-2012

[eluser]Christer_[/eluser]
What i meen is that i want to do a instance class..

instead of doing

Code:
$this->user_model->get_name_by_current_user_id($this->session->userdata('userid'))
Or
Code:
$this->user_model->get_email_by_current_user_id($this->session->userdata('userid'))

i could just make a more personal side to another model witch says.
Code:
$this->user->email
$this->user->id

but i believe the right way to do this is to make a model "User.php"
and just autoload it with

Code:
class User extends CI_Model {

function __construct()
{
if ($this->session->userdata('userid'))
{
$id = $this->db->query

e.e
}
}
}

or am i completly missing som points in the mvc pattern here?


The reason why i am askin is because someone says i need to extend the CI_Controller with a MY_Controller and go from there.
Someone else means its a library since it contains user information
Someone, aswell as myself meens it should be model as there is DB interaction and it is to be used within the controller directly.


Object oriented CI - El Forum - 05-11-2012

[eluser]Spir[/eluser]
[quote author="Christer_" date="1336723699"]What i meen is that i want to do a instance class..

instead of doing

Code:
$this->user_model->get_name_by_current_user_id($this->session->userdata('userid'))
Or
Code:
$this->user_model->get_email_by_current_user_id($this->session->userdata('userid'))

i could just make a more personal side to another model witch says.
Code:
$this->user->email
$this->user->id
[/quote]
Code:
$this->load->model('user_model', 'user');
$this->user->function();
// or if your porperties are public :
$this->user->name = 'My name';
http://ellislab.com/codeigniter/user-guide/general/models.html