• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call, another model in a model

#11
[eluser]Colin Williams[/eluser]
You can create a pseudo-constructor method, maybe call it initialize(), call it directly with whatever params you require, and be done with it. This should be pretty familiar if you have had any experience using CI libraries.

#12
[eluser]uptime[/eluser]
[quote author="Colin Williams" date="1227732476"]You can create a pseudo-constructor method, maybe call it initialize(), call it directly with whatever params you require, and be done with it. This should be pretty familiar if you have had any experience using CI libraries.[/quote]

Or if you have experience with OOP in general...

#13
[eluser]chakhar86[/eluser]
[quote author="Colin Williams" date="1227732476"]You can create a pseudo-constructor method, maybe call it initialize(), call it directly with whatever params you require, and be done with it. This should be pretty familiar if you have had any experience using CI libraries.[/quote]

I thought of it already and sure a lot easier than make an extension of Loader class (which I've found in the user_guide, it can NOT be extended, cmiiw)

#14
[eluser]sophistry[/eluser]
for a general solution to getting models to be "related" check out ORM contributions: IgnitedRecord and DataMapper

#15
[eluser]jwindhorst[/eluser]
The best way that I've found to deal with the CI approach to MVC is to not try to blast through it, but instead, create a higher road above it.

Let me explain a little. I use the models essentially to pull data from the DB, and to do complicated business processing. Then I use my own custom "libraries" to store individual Objects from the data that is pulled.

So, if I had a model called "Cars_model" with a method named "getAmerican()" which was going to return me a list of American cars, inside that method after I grabbed the db data, I would process the data through my custom libraries as:
Code:
while(looping through car data)
         {
             $car_list[]=new my_car($args);
         }

This way, I can manage my data view normal individual objects, but I'm not skirting around the way that CI sees the model.

Hope this helps!

#16
[eluser]chakhar86[/eluser]
From the code I get "my_car" is a class, so you must include or declared above the code?

I recently read a blog about MVC, he said there are two approach to MVC:
1. Thin Controller, Fat Model => Business logic falls to Models
2. Fat Controller, Thin Model => Business Logic falls to Controller

I personally prefer the former. But in case we need a lot of model in single instance of controller then second choice I think have more advantage...

What do you say?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.