backend\controllers\SchoolController::actionNameFilter PHP Метод

actionNameFilter() публичный Метод

public actionNameFilter ( $q = null, $id = null )
    public function actionNameFilter($q = null, $id = null)
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        $output = ['results' => ['id' => '', 'text' => '']];
        if (!is_null($q)) {
            $sql = 'SELECT id, name AS text FROM ' . School::tableName() . ' WHERE name LIKE :like ORDER BY name ASC LIMIT 25';
            $output['results'] = Yii::$app->db->createCommand($sql, [':like' => "%{$q}%"])->queryAll();
        } elseif ($id > 0 && ($school = School::findOne($id))) {
            $output['results'] = ['id' => $id, 'text' => $school->name];
        }
        return $output;
    }