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
23
votes
1 answer

Yii2: Cannot perform RBAC migration (You should configure "authManager"...)

As it is described here I'm trying to do the migration in order to let yii create the user authentication tables. However I get the error: Exception 'yii\base\InvalidConfigException' with message 'You should configure "authManager" component to…
robsch
  • 9,358
  • 9
  • 63
  • 104
23
votes
5 answers

yii2 active record find column not equal

I have this code to find a user from db which status is active and role is user public static function findByUsername($username) { return static::find(['username' => $username, 'status' => static::STATUS_ACTIVE, 'role'=>'user']); } I need to find…
Sarvar Nishonboyev
  • 12,262
  • 10
  • 69
  • 70
22
votes
7 answers

Yii2: How to set default attribute values in ActiveRecord?

This may seem like a trivial question, however all of the obvious solutions that I can think of have their own flaws. What we want is to be able to set any default ActiveRecord attribute value for new records only, in a way that makes it readable…
mae
  • 14,947
  • 8
  • 32
  • 47
22
votes
2 answers

How to make field enum migration yii2

I make field ENUM and the result is error when I use yii migrate/up on CMD windows. public function up() { $tableOptions = null; if ($this->db->driverName === 'mysql') { $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci…
CrashBurn
  • 345
  • 1
  • 3
  • 20
22
votes
1 answer

Yii2 - Pass variable from view to Gridview custom action columns

I want to save the last place that a user visited before he click onto "Edit" button in the gridview widget of a page. I created a variable named $lastAddress but I really dont know how to pass it onto the gridview and append it to the $url variable…
Lê Sỹ Hoàng
  • 409
  • 1
  • 3
  • 15
22
votes
3 answers

Yii2 subquery in Active Record

How can I convert this sql into active record query SELECT * FROM `base_twitter` WHERE id NOT IN (SELECT base_id from base_followers)
Ngoun Thavy
  • 437
  • 2
  • 5
  • 8
22
votes
4 answers

Change layout file within a view in Yii2

I am doing a small project using Yii2. Suppose I have same layout (header, footer) in a view (eg site) except a login.php in this view. I want a different or no header / footer in this file. What can I do the remove the header / footer only from…
Moid
  • 1,447
  • 1
  • 13
  • 24
22
votes
4 answers

How do I manage assets in Yii2?

For example, I created a new page, and I'd like to use, for example, backbone.js, custom css file and some collection of images. Where should I declare all this stuff in Yii2? I found the AppAsset.php module, but this is only for css/js files and I…
Павел Иванов
  • 1,863
  • 5
  • 28
  • 51
21
votes
4 answers

Yii2 - Bad Request (#400) Unable to verify your data submission

My yii2 application was working fine till yesterday however today on submiting form it is showing error. "Bad Request (#400) Unable to verify your data submission.". I found many such questions on stackoverflow, where people are suggesting to…
Ninja Turtle
  • 1,293
  • 2
  • 24
  • 50
21
votes
6 answers

Yii2 | requires bower-asset/jquery

I'm trying to install Yii2 via composer: composer global require "fxp/composer-asset-plugin:~1.1.1" composer create-project --prefer-dist yiisoft/yii2-app-basic basic ~/.composer/composer.json { "require": { "fxp/composer-asset-plugin":…
Atanov Vladimir
  • 403
  • 1
  • 5
  • 9
21
votes
3 answers

Yii 2 - radioList Template

I want to add template to radioList in yii2, which I tried, but I am unable to get the proper o/p. The HTML is
21
votes
5 answers

yii2 registering JS files to a View

I have A.php view file in /views/A/ folder. And I have A.js js file in /views/A/ folder Please help me register js file in view file. As I understand I must write $this->registerJsFile('path/to/file.js'); in view file. But (Question A) I get method…
David
  • 4,332
  • 13
  • 54
  • 93
21
votes
3 answers

How to set uniqueness for multiple fields in ActiveRecord (Yii2)?

How to set uniqueness for multiple fields in ActiveRecord (Yii2)? I have tried as written in manual ['a1', 'unique', 'targetAttribute' => ['a1', 'a2']] But it doesn't work.
almost_done
  • 397
  • 2
  • 4
  • 15
21
votes
6 answers

Yii2: How do change Pagination-Per-Page into RESTful Web Service API?

I am developing an application using AngularJS for the frontend and Yii2 for the backend. The frontend requires a comprehensive array of all users. In the documentation of Yii2, http://www.yiiframework.com/doc-2.0/guide-rest-quick-start.html I can…
Janka
  • 1,908
  • 5
  • 20
  • 41
21
votes
8 answers

Yii2 Gii Forbidden code 403 You are not allowed to access this page

I have a server machine and I am trying to allow my PC ip address to use gii. My PC ip address is 192.168.1.101 The server machine ip is 192.168.1.102. I used composer to install the gii module. This is how my composer.json settings look…
Ionut Flavius Pogacian
  • 4,750
  • 14
  • 58
  • 100