Welcome Guest, Not a member yet? Register   Sign In
debugging Models
#1

[eluser]jtan[/eluser]
Is it possible to debug the Model in Codeigniter? I want to check whether the mistake is in the Controller or the Model, hence would like to get the result of the Models directly without loading the Views.
#2

[eluser]Eric Barnes[/eluser]
You can just echo, print_r, var_dump etc in the model. Or use unit testing.
#3

[eluser]mddd[/eluser]
Or you can use the log_message() function to write information to the log file.
Code:
log_message('debug', 'Some_model: value of $somevar: '. $somevar);
#4

[eluser]Ngulo[/eluser]
hi guys...i'm referring to this post cause i'm trying debugging with an echo a query like this:

Code:
$query =  $this->db->select('id','ip','date')
            ->from('asd');

    echo $query;

but it always returns me this error:
Code:
A PHP Error was encountered

Severity: 4096

Message: Object of class CI_DB_mysql_driver could not be converted to string
do you know why guys?

thanks
#5

[eluser]Eric Barnes[/eluser]
Try this:
Code:
echo $this->db->last_query();
#6

[eluser]danmontgomery[/eluser]
You're never executing the query. from() doesn't return a compiled query, it returns the database object. You need to execute the query with get() or get_where() first.

Also, select() fields aren't individual parameters, they should all be one:

Code:
select('id,ip,date')
not
Code:
select('id','ip','date')

user guide
#7

[eluser]Eric Barnes[/eluser]
[quote author="noctrum" date="1280185555"]You're never executing the query. from() doesn't return a compiled query, it returns the database object.[/quote]

Good catch! Smile

Code:
$query = $this->db->get();
echo $this->db->last_query();
#8

[eluser]Ngulo[/eluser]
thanks guys i will try Wink
#9

[eluser]pickupman[/eluser]
Even better try:
Code:
$this->output->enable_profiler(TRUE);

Get execution time, memory, $_REQUEST array, all sql queries with query times.
#10

[eluser]Ngulo[/eluser]
yeah perfect man this is nicer Wink




Theme © iAndrew 2016 - Forum software by © MyBB