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
19
votes
6 answers

Yii2: How to prepare for debug and production environment?

I know Yii defines and uses the constants YII_DEBUG and YII_ENV. Of course, they are set to to 'true' and 'dev' on my local machine. This is because the basic app template has prepared it this way in the index.php file. This file tells me also that…
robsch
  • 9,358
  • 9
  • 63
  • 104
19
votes
8 answers

ActiveRecord where and order on via-table

I have three database table: product (id, name) product_has_adv (product,advantage,sort,important) advantage (id, text) In ProductModel I defined this: public function getAdvantages() { return $this->hasMany(AdvantageModel::className(),…
rakete
  • 2,953
  • 11
  • 54
  • 108
19
votes
3 answers

How to use datepicker in yii2 basic?

I want to use yii2 datepicker but I'm having trouble to implement this. It does not show the date picker and I don't know what is missing in my code. I'm still new in this yii
ashTon
  • 1,101
  • 4
  • 14
  • 23
19
votes
4 answers

Which folder to add custom helper functions to in Yii

I am trying to create a helper function in Yii 2. To which folder is the PHP file to be added to create a custom helper function in Yii 2 and how do I use it in controllers?
user7282
  • 5,106
  • 9
  • 41
  • 72
19
votes
4 answers

How to create pager in Yii2?

I was searching how to create pager in Yii2 using LinkPage widget. Is there any example? I am new in Yii, so any help would be good.
newYii
  • 193
  • 1
  • 1
  • 4
19
votes
3 answers

PHP, Yii2 GridView filtering on relational value

Following on from this: Yii2 how does search() in SearchModel work? I would like to be able to filter a GridView column of relational data. This is what I mean: I have two tables, TableA and TableB. Both have corresponding models generated using …
Mr Goobri
  • 1,449
  • 5
  • 19
  • 42
19
votes
2 answers

How do I set a default configuration for GridView in Yii2 without the widget factory?

This is what a gridview looks like in Yii2: $dataProvider, 'filterModel' => $searchModel, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], ... ['class' =>…
ippi
  • 9,857
  • 2
  • 39
  • 50
19
votes
5 answers

Yii2 dropdown empty option

How to implement the following Yii code to Yii2: dropDownList($model, 'project', $model->getProjectOptions(), array('empty' => 'Empty string') …
Nahid Hossain
  • 772
  • 2
  • 7
  • 20
18
votes
2 answers

"An error occurred while handling another error: yii\web\HeadersAlreadySentException"

I am trying to submit a comment on a guestbook application based on the Yii 2 Framework. On localhost on my PC works everything fine, but on the shared hosting when I want to submit a comment in View, I get this error. Here is the error: An error…
Mahdi Kashani
  • 213
  • 1
  • 2
  • 6
18
votes
4 answers

How to add a new column with Yii 2 migrations on a specific position in a table?

Let's say I have this table structure: +----+------------+-----------+---------+------+---------+---------+---------------------+---------------------+ | id | first_name | last_name | country | city | address | zipcode | created |…
Zlatan Omerović
  • 3,863
  • 4
  • 39
  • 67
18
votes
4 answers

yii2 ActiveForm numeric textfield

I've created an ActiveForm using yii2 like this: field($item, 'finalPrice', [ 'options' => [ 'tag' => 'div', …
Ofershap
  • 687
  • 2
  • 7
  • 22
18
votes
3 answers

In Yii2, how can I exclude layout from rendering in a view file?

I have an admin login page that I want to render without the layout. How can I render a view in Yii2 without rendering the main layout?
learner
  • 391
  • 1
  • 2
  • 11
18
votes
3 answers

Yii2 Override generic create Action in Rest ActiveController

I have a Rest API in Yii2, and Yii generates all actions view / update / create / delete I want to change the comportement of createMethode et garde the other methods, SO I can't use the class Controller, I should use the class ActiveController But…
Touhami
  • 759
  • 1
  • 11
  • 26
18
votes
9 answers

Yii2 dropdown selected value

I want to show selected value in Yii2 dropdown, $_GET Value: $id = $_GET["cid"]; Drop down code $form->field($model, 'userid') ->dropDownList( [User::getUser()], //[ArrayHelper::map(User::findAll(['active' => '1']),…
Muhammad Shahzad
  • 9,340
  • 21
  • 86
  • 130
18
votes
1 answer

Yii2 - How to list the files inside a folder

Hi, i'm making an Yii2 Basic application and have a file upload form in the admin area. The file upload sends files to app/web/uploads. I followed the great tutorial on uploading files from samdark. It can be seen here:…
André Castro
  • 1,527
  • 6
  • 33
  • 60