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
25
votes
3 answers

Yii2: validation rule for array?

I can define a rule for a single integer like this: [['x'], 'integer'] Is it possible to tell that x is an integer array? For example: [['x'], 'integer[]'] And could I specify the valid values in the array? Update: From Yii version 2.0.4 we've got…
robsch
  • 9,358
  • 9
  • 63
  • 104
25
votes
2 answers

Yii2 global filter/behavior to force user to authenticate first

In my Yii2 application I'm trying to force all users to be authenticated. If they're not already authenticated they should be redirected to the login page. In Yii1 I did this by creating a class that would check if a user was logged in and attaching…
Jap Mul
  • 17,398
  • 5
  • 55
  • 66
25
votes
7 answers

Yii2 REST query

Hy. I have a ProductController which extends the yii\rest\ActiveController. Question is that how can i make querys via HTTP GET request. Like: http://api.test.loc/v1/products/search?name=iphone And the return object will contains all products with…
Kedves Hunor
  • 815
  • 1
  • 11
  • 19
25
votes
5 answers

How to count and group by in yii2

I would like to generate following query using yii2: SELECT COUNT(*) AS cnt FROM lead WHERE approved = 1 GROUP BY promoter_location_id, lead_type_id I have tried: $leadsCount = Lead::find() ->where('approved = 1') ->groupBy(['promoter_location_id',…
deacs
  • 4,259
  • 2
  • 27
  • 37
25
votes
2 answers

Trying to use PHP DateTime Class with Yii2 receiving class not found errors

Hello I am trying to create my own custom helper class to use with Yii2. It is going to handle times so I'll be working with PHP's DateTime class. I have
slick1537
  • 745
  • 2
  • 8
  • 19
25
votes
2 answers

Assets bundles in yii2 generate empty files

Asset bundle generate empty JavaScript and CSS files namespace frontend\assets; return [ 'bundles' => [ 'frontend\assets\AppAsset', ], 'targets' => [ 'frontend\assets\AppAsset' => [ 'basePath' =>…
Vitaliy
  • 331
  • 4
  • 14
24
votes
5 answers

Twitter bootstrap select readonly still able to change options

I have a bootstrap select with readonly="true" but I can still change the selected option. I need the disabled="true" behavior, but when I use this the select is not submitted. I need a combination of the 2, the selected option can not be changed…
Ruben
  • 8,956
  • 14
  • 63
  • 102
24
votes
2 answers

How to change background of 1 row in Yii2 Gridview

I'm working with Yii 2, and it's grid view to show information. Now, my problem is that whenever a user scans two identical serial numbers and/or mac addresses, it should highlight the row (change color to red), and show some error sign or…
Paramone
  • 2,634
  • 4
  • 31
  • 58
24
votes
3 answers

Extend GridView ActionColumn with additional icon

I'm building a webapp with Yii2 framework that will provide users (logged in) the capability to download pre-uploaded files by administrators. I've created the action actionDownload in the specific controller that call the sendFile() method. How can…
AleCat83
  • 1,443
  • 3
  • 22
  • 41
24
votes
3 answers

How can I get current controller in yii2

I'm trying to get current page controller in yii2? How can I achieve this in Yii2? In Yii 1.0 Yii::app()->controller->action->id Yii2 ?
rdanusha
  • 913
  • 3
  • 15
  • 24
24
votes
6 answers

How to add class to ActiveForm in Yii 2.0 framework?

I'd like to add a class to the form like:
How should I rewrite this for Yii 2.0 ActiveForm class? The same question is for this structure inside of the form tag:
Павел Иванов
  • 1,863
  • 5
  • 28
  • 51
24
votes
6 answers

How to upload a file to directory in yii2?

i have an ActiveForm, and i want to add a field where the user can upload their photos. the problem is that i don't have an attribute for the image in the users table and every input field in 'yii' expects a model and an attribute as follows.
tareq
  • 1,119
  • 6
  • 14
  • 28
23
votes
2 answers

Yii2 add LIKE condition with "%" wildcard on the one side

I want to add like condition with % wildcard on the one side, like: where name like 'value%' My code: Table::find()->filterWhere(['like', 'name' , $_GET['q'].'%' ]) ->all(); But query result is: where name like '%value\%%'
Hossam Aldeen Ahmed
  • 772
  • 1
  • 8
  • 20
23
votes
1 answer

Yii2 - WHERE IN with active record

Is it possible to make WHERE IN condition with active record? I am going through documentation, but I can't find this case. I need to perform this query and return count value. This is the method I am using for now: public function static…
Sasha
  • 8,521
  • 23
  • 91
  • 174
23
votes
7 answers

Yii2: Not Found (#404): Unable to find debug data tagged with '5578effb0790c4.13707485'

I'm getting this at the bottom of my page, where the debug bar should be. What is the problem? This request: http://localhost:81/xxx/web/debug/default/toolbar?tag=5578f180963e82.28312577 is returning 404. I need to see the error message & stack…
Chloe
  • 25,162
  • 40
  • 190
  • 357