2009年4月29日星期三

Res: [fw-db] Problem with toArray logging a fatal error to the screen instead allowing catch to get it.

You need to test if found results

Try this:


try {
$found = $this->article->find($id);
if ($found->count()) {
$this->view->mainArticle = $found->current()->toArray();
}
}
catch( Exception $e )
{
Zend_Registry::get('logger')->err($e->getMessage());
Zend_Registry::get('logger')->notice('User tried to do somthing in articles that was not allowed');
$this->_helper->redirector('index','index');
}

----- Mensagem original ----
De: Mr. Eric Eugene Naujock <naujocke@mac-cafe.com>
Para: fw-db@lists.zend.com
Enviadas: Quarta-feira, 29 de Abril de 2009 10:25:41
Assunto: [fw-db] Problem with toArray logging a fatal error to the screen instead allowing catch to get it.

I have a function that calls a table object to return a rowset. The code results in a fatal error thrown up on the screen instead of allowing me to gracefully handle it.

Below is a code example.

The variable $id is a umber for the article I am trying to pull up.
if $id is a number that there is no record for in the database then it will crash.

try {
$this->view->mainArticle = $this->article->find($id)->current()->toArray();
}
catch( Exception $e )
{
Zend_Registry::get('logger')->err($e->getMessage());
Zend_Registry::get('logger')->notice('User tried to do somthing in articles that was not allowed');
$this->_helper->redirector('index','index');
}

The error I was getting is Fatal error: Call to a member function toArray() on a non-object in. My catch code is not ever getting a chance to gracefully handle the problem.

I read thourgh the documentation the result is supposed to be a rowset object even if the query fails. But the toArray() causes the fatal error.

Veja quais são os assuntos do momento no Yahoo! +Buscados
http://br.maisbuscados.yahoo.com

没有评论: