Yii2 – ActiveRecord to Array

Try this! $model = Post::find($id)->limit(10)->asArray()->all(); $model = Post::find($id)->select(‘id,name as full’)->asArray()->one(); $model = Post::find($id)->select(‘id,name as full’)->asArray()->all(); $model = Post::find()->where([‘slug’=>$slug])->asArray()->one();

Execute my code before any action of any controller

In case you need to execute a code before every controller and action, you can do like below: 1 – Add a component into your components directory, for example(MyGlobalClass): namespace app\components; class MyGlobalClass extends \yii\base\Component{ public function init() { echo “Hi”; parent::init(); } } 2 – Add MyGlobalClass component into your components array in config … Read more

What’s the difference between Yii 2 advanced application and basic?

The following table shows the similarities and differences between the basic and advanced templates: Source: https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-comparison.md As you can see, the main differences are: Advanced template supports front- and back-end apps; Advanced template is ready to use User model; Advanced template supports user signup and password restore.

Yii2 redirect to previous page

You could use Yii::$app->request->referrer which returns the last page the user was on. Usage is straightforward: return $this->redirect(Yii::$app->request->referrer); You need also take into account that referrer can be null: return $this->redirect(Yii::$app->request->referrer ?: Yii::$app->homeUrl); See the docs.

How to use not equal to inside a Yii2 query

In this case you need to use operator format: [operator, operand1, operand2, …]. So your code should look like this: $details = MovieShows::find() ->where([‘movie_id’=>$id]) ->andWhere([‘location_id’=>$loc_id]) ->andWhere([‘<>’,’cancel_date’, $date]) ->all(); More about using where method and operator format

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)