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)
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.
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.
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.
make sure debug is set to 2 in config/core.php
print error messages to the log file like so:
$this->log(print_r($this->Video->validationErrors, true));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With