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
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,953
  • 11
  • 54
  • 108
27
votes
4 answers

Yii2 request parameter from url

In YII I could request a parameter from url and populate a form field called companyAdd_id with the following code, trying to do the same in YII2 but getting errors, looking for advice on how to do the same in YII2. thanks
davidndunoon
  • 295
  • 1
  • 5
  • 10
27
votes
9 answers

yii2 redirect in controller action does not work?

I am posting a form to /user/save in order to save user data. The problem occurs when i try to redirect the user if the $_SERVER['REQUEST_METHOD'] is NOT 'post'. My user controller code namespace app\controllers; use Yii; use yii\web\Controller; use…
Andreas
  • 5,305
  • 4
  • 41
  • 60
26
votes
5 answers

Get response in JSON format in Yii2

I'm trying to convert and array of response into JSON format. I have tried all the answers that were posted on SO and other websites like web1,web2 adding header('Content-Type: application/json') and then echo…
ASN
  • 1,655
  • 4
  • 24
  • 52
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
  • 791
  • 1
  • 6
  • 17
26
votes
2 answers

How to handle CSRF Validation in Yii2 Framework?

I'm having problem with CSRF Validation in yii2. The validation works fine with the default form generated by the gii but when I edit the form with html tags then the form submission throws a bad request error. I have disabled csrf validation to …
msucil
  • 806
  • 1
  • 8
  • 15
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,192
  • 4
  • 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,405
  • 1
  • 17
  • 17
26
votes
2 answers

Yii2: check exist ActiveRecord model in database

How to check existence of model in DB? In Yii 1 version it was so User::model()->exist()
Hett
  • 3,484
  • 2
  • 34
  • 51
25
votes
6 answers

Yii2: Remove "(not set)" in GridView and DetailView for null values

How can I remove or replace strings (not set) in my GridView and ListView?
robsch
  • 9,358
  • 9
  • 63
  • 104
25
votes
3 answers

Install Yii2 extension manually without using Composer

I want to install Select 2 extension widget manually with Yii2 Framework without using composer. I done the following steps but it's not working. 1) Added yii2-widget-select2 to vendor/yii-soft 2) Added following code in my…
J.K.A.
  • 7,272
  • 25
  • 94
  • 163
25
votes
1 answer

Yii2 ActiveQuery 'OR LIKE' filter

I have a task - add to the search model searching by full name. Full name is first name + last name. So I need to build query like WHERE first_name LIKE '%var%' OR last_name LIKE '%var%' The only way I could do it : $query->andFilterWhere([ …
Colohanin Nik
  • 393
  • 1
  • 5
  • 11
25
votes
13 answers

Yii2: how to use custom validation function for activeform?

In my form's model, I have a custom validation function for a field defined in this way class SignupForm extends Model { public function rules() { return [ ['birth_date', 'checkDateFormat'], // other rules …
Luigi Caradonna
  • 1,044
  • 2
  • 12
  • 33
25
votes
5 answers

yii2:drop-down list for multiple values concat in one line

for my drop-down list I am using this code. field($medicinerequest, '[' . $id . ']' . 'medicine_name') ->DropDownList(ArrayHelper::map(\app\models\Medicine::find() ->asArray()->all(), 'id', 'medicine_name','medicine_id' ), [ 'prompt' =>…
Pawan
  • 3,864
  • 17
  • 50
  • 83