yii2

Why i getting an error “Call to a member function formName() on a non-object”

試著忘記壹切 提交于 2020-01-07 03:14:06
问题 i try to save multilanguaged content My About model ... public function rules() { return [ [['status', 'date_update', 'date_create'], 'integer'], [['date_update', 'date_create'], 'required'], ]; } ... public function getContent($lang_id = null) { $lang_id = ($lang_id === null) ? Lang::getCurrent()->id : $lang_id; return $this->hasOne(AboutLang::className(), ['post_id' => 'id'])->where('lang_id = :lang_id', [':lang_id' => $lang_id]); } My AboutLang model public function rules() { return [ [[

Yii2 updating two related models does not show data of the second

妖精的绣舞 提交于 2020-01-06 19:55:34
问题 I have two related models in hasToMany relation. The first is Invoices and the second is InvoiceItems . As a prototype process, I'm trying to conjugate the two models through the update view of the InvoicesController using the following code in actionUpdate of InvoicesController : ... use common\models\Invoices; use common\models\InvoicesSearch; use common\models\InvoiceItems; ... public function actionUpdate($id) { $model = $this->findModel($id); $invoiceItems = new InvoiceItems(); if (

How to get clean urls in yii2 like ``post/100``

我的梦境 提交于 2020-01-06 19:37:17
问题 I am quoting the guide: Depending on the urlManager configuration, the created URL may look like one of the following (or other format). And if the created URL is requested later, it will still be parsed back into the original route and query parameter value. /index.php?r=post/view&id=100 /index.php/post/100 /posts/100 I am interested in third option or second without index.php. But how can I get it ? I have .htaccess that is removing index.php ( I may need something for nginx, but do not

yii2 gii CRUD Generator error - Class 'Message' does not exist or has syntax error

主宰稳场 提交于 2020-01-06 19:36:11
问题 I'm creating a basic text only private messaging system for a website using yii2 advanced. I'm using the gii model and CRUD generators but have encountered a problem with the CRUD generation after I have created the model class. I'm wondering whether it might be an issue with the foreign keys on the message table which have a one to many relationship with the users table (i.e. one user can have many messages). When I attempt to run the CRUD generator with- Model Class- Message Search Model

Why can't I create CRUD with GII in Yii2

时光总嘲笑我的痴心妄想 提交于 2020-01-06 18:37:10
问题 I have made the view table with function "join" in sql. but when I try to generate the view table with gii, it was said that "Table associated with Rangkuman must have primary key", and I have made primary key with table that associated with Rangkuman. But still be like this picture Here is Rangkuman model <?php namespace app\models; use Yii; /** * This is the model class for table "rangkuman". * * @property string $Fakultas * @property string $Departemen * @property string $KodeMayor *

yii2 css file won't load because it's MIME type text/html is not text/css on windows7 apache server

假装没事ソ 提交于 2020-01-06 18:06:40
问题 I'm starting on Yii2, and i want to change the theme. So far I've downloaded theme from http://yii2.themefactory.net and followed this steps 'view' => [ 'theme' => [ 'pathMap' => ['@app/views' => '@app/themes/mytheme'], 'baseUrl' => '@web/themes/mytheme', ], ], on config/web.php file. Now when I try to load the site I got this css file won't load because it's MIME type text/html is not text/css 回答1: configure your apache server. Your mime types are probably wrong. You'll need mod_mime apache

Utilising Yii2.0 checkboxlist for Parent-child relation models

蓝咒 提交于 2020-01-06 12:56:11
问题 i have a Questions model and Answers model in which Question to Answer is one-many relation. How do i implement checkboxlist in Yii2 so that it will display in a form as follows: Form: Question 1 description [checkbox] Answer 1 description [checkbox] Answer 2 description Question 2 Description [checkbox] Answer 3 description [checkbox] Answer 4 description Question 3 Description [checkbox] Answer 5 description [checkbox] Answer 6 description [Save button] When i click save and for eg. Answer

Utilising Yii2.0 checkboxlist for Parent-child relation models

混江龙づ霸主 提交于 2020-01-06 12:54:27
问题 i have a Questions model and Answers model in which Question to Answer is one-many relation. How do i implement checkboxlist in Yii2 so that it will display in a form as follows: Form: Question 1 description [checkbox] Answer 1 description [checkbox] Answer 2 description Question 2 Description [checkbox] Answer 3 description [checkbox] Answer 4 description Question 3 Description [checkbox] Answer 5 description [checkbox] Answer 6 description [Save button] When i click save and for eg. Answer

Join tables using model in Yii2

隐身守侯 提交于 2020-01-06 09:06:12
问题 this is table1 id1 Name ------------ 1 value1 2 value2 this is table2 id2 Name id1 --------------------- 1 value1 2 2 value2 1 this is table3 id3 Name id2 --------------------- 1 value1 2 2 value2 1 this is table4 id4 Name id3 --------------------- 1 value1 2 2 value2 1 I Want to join above 4 tables in Yii2 with model select * from table1 left join table2 on table2.id2 = table1.id1 left join table3 on table2.id3 = table1.id2 left join table4 on table2.id4 = table1.id3 回答1: 1. Use Yii2

Join tables using model in Yii2

这一生的挚爱 提交于 2020-01-06 09:06:06
问题 this is table1 id1 Name ------------ 1 value1 2 value2 this is table2 id2 Name id1 --------------------- 1 value1 2 2 value2 1 this is table3 id3 Name id2 --------------------- 1 value1 2 2 value2 1 this is table4 id4 Name id3 --------------------- 1 value1 2 2 value2 1 I Want to join above 4 tables in Yii2 with model select * from table1 left join table2 on table2.id2 = table1.id1 left join table3 on table2.id3 = table1.id2 left join table4 on table2.id4 = table1.id3 回答1: 1. Use Yii2