这是我的用户控制器的索引动作:
$users = new Application_Model_DbTable_Users();
$this->view->users = $users->fetchAll(
$users->select('userid,username')
->order('userid ASC')
->limit(10, 0));
这是我的观点:
<?php
echo "<pre>";
echo print_r($this->users);
?>
在输出中我想要用户表的结果的JSON,但视图中的数组是它 是
Zend_Db_Table_Rowset Object
(
[_data:protected] => Array
(
[0] => Array
(
[userid] => 1
[username] => rahul
[firstname] => rahul1
[lastname] => Khan2
[password] => ��2jr�``�(E]_�=^
[email] => salman@gmail.com
[avatar] => 4cfe07efd2e1c.jpg
[updatedon] => 2011-01-23 18:45:49
[createdon] => 0000-00-00 00:00:00
[featuredgibs] =>
[defaultgib] =>
)
完整的
但我只想要json:
{
"userid":"1",
"username": "rahul"
}
答案 0 :(得分:2)
你必须在from部分中定义所需的列,试试这个:
$users = new Application_Model_DbTable_Users();
$select = $users->select()
->from('table', array('userid', 'username')) // important
->order('userid ASC')
->limit(10, 0);
$this->view->users = Zend_Json::encode($users->fetchAll($select)); // output json