Questions tagged [yii2]

Yii 2 is the latest version of the Yii framework - a high-performance, component-based PHP framework

Yii Framework

Yii is a generic Web programming framework, meaning that it can be used for developing all kinds of Web applications using PHP. Because of its component-based architecture and sophisticated caching support, it is especially suitable for developing large-scale applications such as portals, forums, content management systems (CMS), e-commerce projects, RESTful Web services, and so on.

Yii 2.0 is the current version of the Yii PHP framework, released on October 12, 2014. The latest version can be downloaded from the Yii website. Guidelines on how to upgrade minor Yii 2.0 version and changelog can be found here.

Yii 2.0 is a complete rewrite of Yii 1.1 based on PHP 5.4 improvements and aims for simplicity, performance and extensibility. The framework adopts namespaces and traits, PSR standards, , and . Yii 2.0 implements the dependency injection container and service locator. It makes the applications built with Yii more customizable and testable.

Official documentation can be found in the Definitive Guide to Yii 2.0. Further important documentation sources:

More information on the current project status can be found in the Yii 2.0 release announcement and the project roadmap.

15456 questions
20
votes
3 answers

Yii2: How to add two fields in orderby() of Find()

How to add more than one field to sort in find() method? I have tried as below $model::find()->orderBy([['id_date' => SORT_DESC],['item_no'=>SORT_ASC]); But it is throwing error with query. Orderby Query produced by yii2 is: ORDER BY 0, 1
Kumar V
  • 8,810
  • 9
  • 39
  • 58
20
votes
7 answers

Correct way to bind parameters using MySQL "IN" syntax in Yii2?

Ok, I'm using Yii2 and I'm familiar with preparing/binding data when using mysql queries, such as: $sql = $this->db->createCommand("UPDATE some_table SET something='foo' WHERE some_id=:some_id"); $sql->bindValue(':some_id', $some_id); But what…
Brett
  • 19,449
  • 54
  • 157
  • 290
20
votes
1 answer

How to use registerMetatag in Yii 2

i'm trying to render meta tag on page header by use: In my View: registerMetaTag(['name' => 'keywords', 'content' => 'yii, framework, php']); ?> and in my layout i put this code in head tag position: head()?> But it does…
Chicken's King
  • 203
  • 1
  • 2
  • 5
20
votes
3 answers

Yii2 GridView Customize Header Row

In my view code I have this: $dataProvider, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], ['label' => 'Training Score', 'attribute' =>…
Wonka
  • 285
  • 2
  • 3
  • 6
20
votes
2 answers

How to get last inserted id in yii2 using createCommand?

I am using yii2 php framework. I want insert record into database using transaction. How can I get last inserted id using createCommand(). Please check following code, $db = Yii::$app->db; $sql = $db->createCommand()->insert('user', [ …
Rahul
  • 223
  • 1
  • 2
  • 10
20
votes
3 answers

Redirect to a page other than login in Yii 2 behaviors

Is there any way to redirect to a page other than login in behaviors method in Yii 2? My behaviors method content: public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), 'actions'…
user7282
  • 5,106
  • 9
  • 41
  • 72
20
votes
4 answers

How to add more user identity session attributes in Yii2?

In Yii2 you can access the identity interface for the current user by using the identityInterface object from within the \yii\web\User class with something like this \Yii::$app->user->identity->id; Is there a way to get and set additional…
Manquer
  • 7,390
  • 8
  • 42
  • 69
19
votes
2 answers

How to get values from params.php in Yii2

I'm using Yii2 for my application. In params.php file I have defined an array like: return ['setValue'=>100]; And I have include params.php in web.php: $params, ]; return…
shanthi Jagadeesh
  • 213
  • 1
  • 3
  • 10
19
votes
6 answers

Yii2 cors filters error that No 'Access-Control-Allow-Origin' header is present

Following This question i have set my rest controller behaviour as public function behaviors() { $behaviors = parent::behaviors(); $auth= $behaviors['authenticator'] = [ 'class' => HttpBearerAuth::className(), 'only' =>…
Geoff
  • 6,277
  • 23
  • 87
  • 197
19
votes
6 answers

How to print converted SQL query from yii2 query

I want to print query: $demo = Demo::find()->all(); I want to see converted SQL query with parameters: createCommand()->getRawSql(); is showing me an error message: yii2 Call to a member function createCommand() on a non-object Please help me…
Paritosh Mahale
  • 1,238
  • 2
  • 14
  • 42
19
votes
1 answer

yii2 ActiveRecord Find OrderBy with calculation

Trying to fetch a description from my database. The query returns the result but I would like to order the result to only show the one with the highest vote. The vote should be calculated by the upvoted column subtracted by the downvoted…
william
  • 529
  • 2
  • 5
  • 14
19
votes
6 answers

Yii2 - The directory is not writable by the Web process | frontend/web/assets

I have searched this issue on internet but none of them helped me. Also this one doesn`t: chgrp apache /path/to/mydir chmod g+w /path/to/mydir My server is centos 7. Can you help me?
Shaig Khaligli
  • 4,955
  • 5
  • 22
  • 32
19
votes
10 answers

model->save() Not Working In Yii2

Previously, I was not using $model->save() function for inserting or updating any data. I was simply using createCommand() to execute query and it was working successfully. But, my team members asked me to avoid createCommand() and use…
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
19
votes
3 answers

How to create composite primary key by using Migration in Yii2?

I tried to run yii migrate, but it showed the following error: create table news-cate ...Exception: SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a…
user1571234
  • 261
  • 3
  • 4
  • 9
19
votes
2 answers

Repeat Password does not work in Yii2

I have written rules in the model as: public $password_repeat; /** * @inheritdoc */ public function rules() { return [ .... .... ['password', 'required'], ['password', 'string', 'min' => 6], …
StreetCoder
  • 9,871
  • 9
  • 44
  • 62