Welcome Guest, Not a member yet? Register   Sign In
Passing a class name to CI_DB_result::result()
#1

[eluser]Joseph Wynn[/eluser]
Hi there,

The documentation for result() says that you can pass it the name of a class to instantiate for each result object: http://ellislab.com/codeigniter/user-gui...sults.html

This is not the case; result() either returns a StdClass object or an array. There is no logic whatsoever that looks for a class to instantiate.

I'm curious to know why this feature (and it's a really good feature!) is documented when it doesn't actually exist?
#2

[eluser]danmontgomery[/eluser]
Sure there is...

https://bitbucket.org/ellislab/codeignit....php#cl-48

Code:
/**
* Query result. Acts as a wrapper function for the following functions.
*
* @access    public
* @param    string    can be "object" or "array"
* @return    mixed    either a result object or array
*/
function result($type = 'object')
{
    if ($type == 'array') return $this->result_array();
    else if ($type == 'object') return $this->result_object();
    else return $this->custom_result_object($type);
}
#3

[eluser]Joseph Wynn[/eluser]
Ah, my apologies. Do you know in which version this was added? I should have stated in my original post that I noticed this while working on an ExpressionEngine project, which I now realise may not be running the latest version of CodeIgniter.

Thanks for your reply.
#4

[eluser]Aken[/eluser]
My EE install says it's running CI 2.0.1, which is going to be CI Core and not Reactor. It was committed to Reactor on January 15th 2011. It has not been added to Core yet, or EE.
#5

[eluser]Joseph Wynn[/eluser]
Thanks for the info Aken, much appreciated!
#6

[eluser]Aken[/eluser]
Sure thing. You could always extend the file or replace it in your EE install if you need to use it. It wasn't much added code.




Theme © iAndrew 2016 - Forum software by © MyBB