• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Are Classes Dead?

#1
[eluser]matyhaty[/eluser]
Hi All

As you may have seen, Ive just posted another article, it was getting abit long, so putting this seperate issue here!

Are classes dead as such?

I was interested to define each element of CI.... For example:

View - your markup, pass it the data, nothing more
Controller - the dicator of the page. It gets everything, but no data manipulation here.
Model - The data gatherer. Contact the old mySQL and get it all

Now my confusion is where is the data transformation taking place.
Do you do it in the model, in nicely OO code (of course)
Or, where suitable, send it over to a specific class (such as 'Shop_products' or something) where it processes the gathered database information in the model and returns it back to the model in the desired form?

Also, if classes are the way forward, is there a autoloader method / or best practice.

I have done a ton of reading on CI, but this one escapes me. Apologies if I have missed something obvious, but i am new!!

Regards


Matt

#2
[eluser]mrmeyers99[/eluser]
I had this question when I first started using CI. I was used to a database class that returned an PHP object that I defined. In CI, the $qry->result() method returns an array of standard objects that contain member variables based on each column of the query. CI uses the mysql_fetch_object method to do this.

http://us.php.net/mysql_fetch_object explains how this method works. On that page it says that you can pass it a parameter for what kind of class you want to instantiate. If you don't pass anything, it uses stdClass. So, if you wanted to return an array of Shop_product objects, you could tweak the CI result() method to accept an optional parameter for the name of the class you to instantiate. Then you could pass it 'Shop_product' and it would return an array of Shop_product objects.

I've never tried doing this. I always thought it might be useful, but I haven't taken the time to try it out. If you have any success with it let me know.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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