Welcome Guest, Not a member yet? Register   Sign In
Combining Model Methods? Linking Models
#1

[eluser]Polarity[/eluser]
Hi2all

Im coding some sort of a bulletin board and i run into a programming design question.

I have a "Post_model" and a "User_model". Actually i retrieve all postings for a "thread" together with ja left join on the user database in a "Post_model" function. It works correctly, so theres nothing special. But i want to make it more "modular" and leave all Database functions that affects the "user table" inside the "User_model".

I have a function inside the "User_model" for retrieving "User_data" based on a "id". So i thougt of a plain foreach loop inside the "Post_model" function and do a query for every iteration on the "User_model" funtion. But thats also not very "modular" because i have to redefine every database coloumn and i want to have return a complete Object from the "Post_model" function together with all available User_data i defined in the "User_model". Something CakePHP does

I hope someone understands my question and give me a solid answer on the problem.
Greetings Robert
#2

[eluser]m4rw3r[/eluser]
Maybe you should take a look at the ORM solutions present for CodeIgniter.
They are quite similar to CakePHP's model in their purpose.

Mine is one of them, link in my signature.
#3

[eluser]Polarity[/eluser]
Hey thx m4w3r, thx for your advice. i miss something like last_row(), choosing different databases types etc.
#4

[eluser]Senthilguru[/eluser]
Hi Dude,

Just try this,
I hope u r trying to use a function of User_model in Post_model

pls put this code in your Post_model..

//Load Model
$this->load->model('User_model');
$this->User_model->getUserDetails($user_id);

Now u can use the User_model functions in your Post_model...

Thanks and regards,
senthilguru.e
cogzideltemplates.com




Theme © iAndrew 2016 - Forum software by © MyBB