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

Yii2 How to perform where AND or OR condition grouping?

You can try this: //SELECT * FROM users AS u WHERE u.user_id IN(1,5,8) AND (u.status = 1 OR u.verified = 1) OR (u.social_account = 1 AND u.enable_social = 1) $model = arname()->find() ->andWhere([‘user_id’=>[1,5,8]]) ->andWhere([‘or’, [‘status’=>1], [‘verified’=>1] ]) ->orWhere([‘and’, [‘social_account’=>1], [‘enable_social’=>1] ]) ->all();

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated

Run: sudo mysql -u root -p mysql> SELECT @@global.sql_mode; (Then optionally copy the output to your notes somewhere in case you want to revert to those original settings later.) And change the SQL Mode for your MySQL Server Instance: mysql> SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,’ONLY_FULL_GROUP_BY’,”)); (If you ever want to roll back, you could run something … Read more

Cannot update yii2 via composer bower-asset/jquery could not be found

Finally fixed it, just followed the steps on the UPGRADE.md doc If you are using Composer to upgrade Yii, you should run the following command first (once for all) to install the composer-asset-plugin: composer global require “fxp/composer-asset-plugin:^1.2.0” (See http://www.yiiframework.com/doc-2.0/guide-start-installation.html#installing-from-composer for latest version.) You may also need to add the following code to your project’s composer.json … Read more

Multiple database connections and Yii 2.0

First you need to configure your databases like below: return [ ‘components’ => [ ‘db1’ => [ ‘class’ => ‘yii\db\Connection’, ‘dsn’ => ‘mysql:host=localhost;dbname=db1name’, //maybe other dbms such as psql,… ‘username’ => ‘db1username’, ‘password’ => ‘db1password’, ], ‘db2’ => [ ‘class’ => ‘yii\db\Connection’, ‘dsn’ => ‘mysql:host=localhost;dbname=db2name’, // Maybe other DBMS such as psql (PostgreSQL),… ‘username’ => … Read more

Enable clean URL in Yii2

I got it working in yii2. Enable mod_rewrite for Apache. For basic template do the following: Create a .htaccess file in web folder and add this RewriteEngine on # If a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward it to index.php RewriteRule . index.php Then … Read more

How to make a drop down list in yii2?

It is like <?php use yii\helpers\ArrayHelper; use backend\models\Standard; ?> <?= Html::activeDropDownList($model, ‘s_id’, ArrayHelper::map(Standard::find()->all(), ‘s_id’, ‘name’)) ?> ArrayHelper in Yii2 replaces the CHtml list data in Yii 1.1.[Please load array data from your controller] EDIT Load data from your controller. Controller $items = ArrayHelper::map(Standard::find()->all(), ‘s_id’, ‘name’); … return $this->render(‘your_view’,[‘model’=>$model, ‘items’=>$items]); In View <?= Html::activeDropDownList($model, ‘s_id’,$items) ?>