Reputation: 92
I need help to remove fatal error of toArray()
in zend framework.
Fatal error: Call to a member function toArray() on a non-object
I am using following code in my controller
$obj = new Admin_Model_UserMapper();
$where = array('id = ?'=>$decryptId);
$data = $obj->fetchAll($where);
// $currentData = $data->current();
$dataArr = $data->toArray();
$form = new Admin_Form_UserForm();
$form->setAction('edit-user');
$form->populate($dataArr);
I am getting fatal error in both condition when I use toArray()
or current()
.
I have already used following code, but not getting any solution and it produces the same error:
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select()->from('user')->where('id= ?',$decryptId);
$stmt = $select->query();
$result = $stmt->fetchAll();
if(count($result) > 0){
$dataArr = $result->toArray();
}
How can I resolve this?
Upvotes: 0
Views: 3445
Reputation: 6470
Your fetchAll
returns no data. Wrap it in a condition...
$where = array('id = ?'=>$decryptId);
$data = $obj->fetchAll($where);
if ($data->count()){
// $currentData = $data->current();
$dataArr = $data->toArray();
}else{
// no records found!
}
The problem is with your $where
, you cannot use it like key/value array. Use code below:
$where = $this->getAdapter()->quoteInto('id = ?', $decriptId);
Upvotes: 5