Welcome Guest, Not a member yet? Register   Sign In
Are Classes Dead?
#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.


Messages In This Thread
Are Classes Dead? - by El Forum - 08-05-2009, 09:24 AM
Are Classes Dead? - by El Forum - 08-11-2009, 01:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB