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.

14789 questions
35
votes
8 answers

Yii2 Session, Flash messages

I have a problem with setting flash messages. So, i have an action which in some cases should redirect with flash. It looks like this: if(!$this->_isSameOrg($reports)){ \Yii::$app->session->setFlash('consol_v_error',\Yii::t('app/consol',…
Anton Abramov
  • 2,031
  • 5
  • 21
  • 27
34
votes
2 answers

Dependency issue trying to install php-mbstring on ec2

I am trying to install yii2 on my Amazon Linux AMI instance, it requires the php-mbstring extension to work. When I tried to run sudo yum install php-mbstring it returned this error: Error: php56-common conflicts with…
Bob Lin
  • 343
  • 1
  • 4
  • 7
34
votes
5 answers

Execute my code before any action of any controller

I would like to check if my user have filled certain fields in his profile before he can access any action of any controller. For example if(empty(field1) && empty(field2)) { header("Location:/site/error") } In yii1 I could do it in…
Misko Mali
  • 587
  • 1
  • 6
  • 17
34
votes
4 answers

Yii2 : Active Record add Not In condition

What is the active Record way of adding IN condition to an active Query in yii 1.x you could use CDbCriteria like this $cr = new CDbCriteria(); $cr->addNotInCondition('attribute', $array); There seem to be no equivalent API call in yii2 active…
Manquer
  • 6,902
  • 6
  • 39
  • 67
34
votes
3 answers

What is the difference between $with and $joinWith in Yii2 and when to use them?

In the API documentation it is specified that $joinWith - A list of relations that this query should be joined with $with - A list of relations that this query should be performed with What is the difference between these ActiveQuery property…
NAT3863
  • 481
  • 1
  • 5
  • 8
33
votes
7 answers

Hide label for input field

I am trying to hide the label for a specific field in _form.php without success. I have tried couple of variation like, but none is working: field($model, 'sample_text')->textArea('label'=>false) ?> and alternate code:
Joshi
  • 2,539
  • 5
  • 24
  • 53
33
votes
2 answers

ReferenceError: $ is not defined yii2

Adding a javascript inside my view results in the ReferenceError: $ is not defined. I assume that the problem is due to Yii2 injects scripts last on my page. How to fix this? Or how will I prevent Yii2 from autoloading the script files? My view …
Dency G B
  • 7,856
  • 9
  • 42
  • 74
32
votes
10 answers

Hide Yii2 GridView Action buttons

I want to hide Yii2 GridView Action Column buttons on the base of model field status. If status is = 1 then hide view button only. How I can? Code: [ 'class' => 'yii\grid\ActionColumn', 'contentOptions' => ['style' =>…
Muhammad Shahzad
  • 7,778
  • 20
  • 71
  • 123
32
votes
2 answers

Yii2: Why is the auth key in class User?

As the title clarifies why is the auth key introduced in Yii2? What're it's main usages and how it is useful in authentication?
Ejaz Karim
  • 3,495
  • 6
  • 33
  • 48
32
votes
8 answers

Yii2 assets clear cache

Everytime I update my css or js files in infoweb\menu\module\assets, I have to empty the backend\web\assets folder is there a way to automatically clear the assets cache?
Ruben
  • 7,959
  • 12
  • 58
  • 89
30
votes
7 answers

Yii2 htaccess - How to hide frontend/web and backend/web COMPLETELY

I think I am pretty close. I have the htaccess redirecting to the website (frontend/web) and the /admin path (backend/web). The site appears fine, CSS files loading, etc. If you go to: http://localhost/yii2app/ - it loads the homepage, and doesn't…
Wade
  • 3,509
  • 2
  • 26
  • 45
30
votes
5 answers

Customise grid view in yii2

How to remove summary and sorter for a particular grid view in Yii2. In Yii1.1 we can do that by setting the template property. In yii2 how to achieve this?
Dency G B
  • 7,856
  • 9
  • 42
  • 74
29
votes
4 answers

Yii2 : How to write distinct SQL query?

I want to implement following SQL queries in Yii 2 but with no success. This should give total number of unique company names: SELECT count(DISTINCT(company_name)) FROM clients And this should display company_name with client code and…
JKLM
  • 1,390
  • 3
  • 21
  • 53
29
votes
1 answer

How to use constant in the ON condition in Yii2 hasMany relation

I try to create a polymorphic association, what is common in Rails but unfortunately not in Yii2. As part of the implementation I need to define the relation: public function getImages() { return $this->hasMany(RecipeImage::className(), …
Tibor Nagy
  • 1,017
  • 1
  • 13
  • 27
29
votes
2 answers

Yii2 - ActiveForm ajax submit

How can i use ActiveForm with these requirements? Submit form with ajax. Before submitting with ajax: Check if error exits. After submitting: Display error of field under field's input if the server responses unsuccess saving result.