Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i see cakephp database save errors?

if i have a cake php saveAll method like so:

if ($this->Video->saveAll($this->data)){
    ... // stuff that never happens, sadly
} else {
    ...
    $this->Session->setFlash('boo! hss! error here');
}

how do i print out the database error? I tried:

    $this->Session->setFlash('boo! hss! error here' . print_r($this->Video->validationErrors,true);

but that didn't work (it just showed me an empty array)

cheerio!

UPDATE: ah. So, the problem is that, while normally i'd get the database error, i was using the old prg mechanism, and cake doesn't (magically) show the db errors on redirect pages.

Fair enough, but in the future, how the heck am i meant to see the db errors on a redirect page (that is, the question still stands, its just that most people probably just SEE the error, and don't need to do anything to get it)

like image 283
bharal Avatar asked Jan 24 '12 05:01

bharal


People also ask

How can I get data from database in cakephp?

To view records of database, we first need to get hold of a table using the TableRegistry class. We can fetch the instance out of registry using get() method. The get() method will take the name of the database table as argument. Now, this new instance is used to find records from database using find() method.

How to log in CakePHP?

We can configure the log in file config/app. There is a log section in the file, where you can configure logging options as shown in the following screenshot. By default, you will see two log levels − error and debug already configured for you. Each will handle different level of messages.

How can I update my data in cakephp 2?

To update a record in database, we first need to get hold of a table using TableRegistry class. We can fetch the instance out of registry using the get() method. The get() method will take the name of the database table as an argument. Now, this new instance is used to get particular record that we want to update.


1 Answers

  1. make sure debug is set to 2 in config/core.php

  2. print error messages to the log file like so:

    $this->log(print_r($this->Video->validationErrors, true));

like image 64
marknatividad Avatar answered Oct 23 '22 03:10

marknatividad