我在我的app.pagination中使用zend paginator工作得很好但我得到这个错误试图获取非对象的属性
$user = new Zend_Session_Namespace('user');
$user_id =$user->user_id;
$DB = Zend_Db_Table_Abstract::getDefaultAdapter();
$select = $DB->select()
->from(array('p' => 'phone_service'))
->join(array('u' => 'user_preferences'), 'u.phone_service_id = p.phone_service_id')
->where('u.user_preferences_name = ?', 'is_user_package_active')
->where('p.user_id = ?', $user_id);
$adapter = new Zend_Paginator_Adapter_DbSelect($select);
$paginator = new Zend_Paginator($adapter);
$this->view->paginator=$paginator;
在我看来我正在这样做
foreach($this->paginator as $record){
<td><?php echo $record->phone_service_name;?></td>
<td><?php echo $record->phone_service_type;?></td>
<td ><?php echo $record->phone_service_Duration;?></td>}
给出以下错误
Notice: Trying to get property of non-object
当我在我的观点中这样做时
var_dump($this->paginator);
[_tableCols:protected] => Array
(
)
there are no data of columns
任何提示PLZ ???
答案 0 :(得分:1)
看起来您的查询返回一个空记录集。要调试它,请尝试:
$select = $DB->select()
->from(array('p' => 'phone_service'))
->join(array('u' => 'user_preferences'), 'u.phone_service_id = p.phone_service_id')
->where('u.user_preferences_name = ?', 'is_user_package_active')
->where('p.user_id = ?', $user_id);
echo $select;
die();
这应该输出发送到mysql的确切查询,你可以将它复制粘贴到phpmyadmin / heidisql或者用于管理mysql的任何内容,看看它是否返回你期望的内容。从那里你可以尝试使查询工作,然后将其移植回你的PHP代码。
答案 1 :(得分:0)
make it sure column names in DB and in your code are same.mean spelling are same
or $record['phone_service_name']
once i got this error and the problem was i miss spell column name hope it helps