/** * fourth sequence * Method untuk meload data tenant berdasarkan primary key */ public function loadModel($id) { $model = Tenant::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionGetTenant() { $keyword = $_GET['q']; $models = Tenant::model()->findAll(array('select' => 'id_tenant, tenant_name', 'condition' => 'tenant_name LIKE :keyword', 'params' => array(':keyword' => '%' . $keyword . '%'), 'order' => 'tenant_name', 'limit' => 5)); $suggest = array(); foreach ($models as $model) { $suggest[] = array('id' => $model->id_tenant, 'text' => $model->tenant_name); } echo CJSON::encode($suggest); }