我有一个扩展 CComponent 的模型类
class CompanyModel extends CComponent{
private $company_pk;
public function getCompany_pk()
{
return $this->company_pk;
}
public function setCompany_pk($value) {
$this->company_pk = $value;
}
}
我有一个填充这个模态的函数
public function getCompanyList() {
$companyList=array();
$company_obj = new CompanyModel();
$sql = "SELECT company_pk,name FROM tbl_company WHERE status = ".Constants::ACTIVE_COMPANY;
$command=$this->connection->createCommand($sql);
$command->setFetchMode(PDO::FETCH_ASSOC);
$rows=$command->queryAll();
foreach ($rows as $row){
$company_obj->company_pk = $row['company_pk'];
array_push($companyList,$company_obj);
}
return $companyList;
}
和我的控制器
Class UserController extends CController {
public function actionGetCompanyList() {
$model = new UserAction();
$ret_val = $model->getCompanyList();
echo CJSON::encode((array)$ret_val[0]);
}
}
我得到的 JSON 是
{"\u0000CompanyModel\u0000company_pk":"2"}
我怎样才能删除那些垃圾值