public function testProject_Ok() { $user = User::findByLogin('test'); $result = Project::find('all', array('joins' => array('members'), 'select' => 'projects.identifier,members.user_id,members.role_id', 'conditions' => array('user_id = ?', $user->id))); $this->assertEquals(4, $result[0]->role_id); $this->assertEquals(3, $result[1]->role_id); }
/** * @param $id * @return array|null|\yii\db\ActiveRecord * @throws HttpException */ public function findModel($id) { $model = Project::find()->published()->andWhere(['id' => (int) $id])->one(); if (!$model) { throw new HttpException(404); } return $model; }
public function get($id) { $project = Project::find($id); $asArray = $project->to_array(); $canEncode = json_encode($asArray); if ($canEncode === false) { throw new \Exception("Cannot encode to json"); } // var_dump($asArray); return json_encode($asArray); }