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

Yii2 - ActiveRecord to Array

Is there any way to convert ActiveRecord to an array in Yii2? I do know we can do that for ActiveQuery, for example User::find()->asArray()->one();, but can we convert Model to array when it is already fetched? I want to do that in beforeSave()…
Volodymyr
  • 1,377
  • 2
  • 12
  • 19
28
votes
5 answers

Yii2 BootstrapAsset is not loading bootstrap.js

yii\bootstrap\BootstrapAsset is not loading bootstrap.js, and such elements as "modal" and others are not working. class AppAsset extends AssetBundle { public $basePath = '@webroot'; public $baseUrl = '@web'; public $css = [ …
ccdiego5
  • 646
  • 1
  • 7
  • 14
28
votes
1 answer

How to add a class to tags in a GridView

I need to add classes to td of a GridView. I've found renderTagAttributes(), but I can't find examples how to use it. Could you explain me this function or offer me other option? My gridview:
Kevin7
  • 553
  • 1
  • 5
  • 13
28
votes
5 answers

Get the name of the user in yii2

How can I get the name of the logged-in-user in yii2? I can get the user-id with Yii::$app->user->id; and I know that I could find the name in the database but I want a direct way. The name-column in the database has the name "username", but…
Patricia Heimfarth
  • 2,688
  • 2
  • 22
  • 29
28
votes
5 answers

How to change label text of the ActiveField?

I have created new Yii2 basic project and want to dig in. There is a Username field on login page: I want to change label 'Username' to a custom one, e.g. 'My superb label'. I have read the…
Vadim
  • 969
  • 1
  • 11
  • 23
27
votes
4 answers

Securing non authenticated REST API

I have been reading about securing REST APIs and have read about oAuth and JWTs. Both are really great approaches, but from what I have understood, they both work after a user is authenticated or in other words "logged in". That is based on user…
Eric B.
  • 4,412
  • 2
  • 13
  • 32
27
votes
1 answer

Yii2: How to use orWhere in andWhere

I want create this query with yii2 search model select * from t1 where (title = 'keyword' or content = 'keyword') AND (category_id = 10 or term_id = 10 ) But I don't know how to use orFilterWhere and andFilterWhere. My code…
ingenious
  • 696
  • 1
  • 7
  • 22
27
votes
25 answers

Yii2: How to add textarea in yii2

What is the mapping of textarea in yii2 ? How to write this in yii2 format? What is an alternative or way to define textarea in yii2?
user4428957
27
votes
4 answers

Yii 2.0 How to generate form without

'contact-form']); ?> field($model, 'email', [ 'inputOptions' => [ 'placeholder' => 'Ihre E-Mail Adresse', 'class' => 'newsletter-cta-mail' ] …
rakete
  • 2,713
  • 9
  • 49
  • 98
27
votes
4 answers

How to enable and disable sort in Yii2 GridView?

How to enable and disable sort in Yii2 GridView ?
rdanusha
  • 856
  • 3
  • 14
  • 23
27
votes
6 answers

Yii2: update field with query builder

How can I update field with query builder in Yii2? I can't find this in documentation. Thanks! UPD This is the solution: // UPDATE $connection = Yii::$app->db; $connection->createCommand()->update('user', ['status' => 1], 'age > 30')->execute();
arfname
  • 329
  • 1
  • 4
  • 9
27
votes
2 answers

Yii2 how does search() in SearchModel work?

Please can someone explain how the search method in a Yii2 SearchModel works? I generated it using Gii. Here it is: public function search($params){ $query = MyModel::find(); $dataProvider = new ActiveDataProvider([ 'query' =>…
Mr Goobri
  • 1,331
  • 5
  • 18
  • 39
26
votes
1 answer

Yii2 + AngularJS in a single application - how?

I have experience with both Yii 2 and AngularJS, but separately. I have two questions: Is it possible to use AngularJS in Yii 2's view? I am asking possible instead of feasible, because I think the problem may have arrived at routing. Also, is it…
Neel Shah
  • 741
  • 1
  • 6
  • 17
26
votes
5 answers

Create button with link in Yii2

I am trying to setup a button with a link to a view. However yii\bootstrap\Button does not have a property url. I would rather use Yii as supposed to just use flat out php. The code as below would be the ideal situation, but since the url option…
Wijnand
  • 1,144
  • 3
  • 16
  • 28
26
votes
2 answers

Yii2 save related records in single save call in single transaction

In yii2 how can i save multiple related records into db into single save call and single transaction. I have two tables: User - id, name UserAddress - id , user_id , city User table has one to many relation to UserAdress table What i want to do is…
Gaurav Singla
  • 1,230
  • 1
  • 13
  • 15