yii2

How to use custom templates in gii (using Yii 2)

时光毁灭记忆、已成空白 提交于 2019-12-10 12:46:47
问题 I'm trying to find a way to use custom Gii templates for Yii 2, but looking at the missing documentation in the docs, I assume it's not possible yet? Or am I missing something? 回答1: Copy ie. the crud generator templates from gii/generators/crud/templates to your application app/templates/mycrud . Then define the templates in your config: $config['modules']['gii'] = [ 'class' => 'yii\gii\Module', 'generators' => [ 'crud' => [ 'class' => 'yii\gii\generators\crud\Generator', 'templates' => [

Yii2, error occurs while throwing NotFoundException

元气小坏坏 提交于 2019-12-10 12:42:09
问题 I have a simple code that is running on beforeAction event of my application: 'on beforeAction' => function ($event) { throw new \yii\web\NotFoundHttpException('The requested page does not exist.'); }, I expect it to simply show 404 page of my application, but it throws following error: An Error occurred while handling another error: exception 'yii\web\NotFoundHttpException' with message 'The requested page does not exist.' in /home/files/www/ucms/config/frontend/config.php:9 Stack trace: 0

yii2 routing - pass parameter to route in rules

冷暖自知 提交于 2019-12-10 12:38:06
问题 When a user accesses domain/page , I need to route them to controller/action/100 . I don't want to pass any parameter through the URL, but want to add it in url rules. I added the code below to my config file. 'urlManager' => [ 'rules' => [ 'login' => 'site/login', // working 'about' => 'cms/page/10' // Not Working 'about' => 'cms/page?id=10' // Not Working ], ], The first rule is working fine. Can I pass the parameter for the route in url rules? 回答1: You need to use defaults and declare the

Yii2 GridView cannot set column width

我怕爱的太早我们不能终老 提交于 2019-12-10 12:34:39
问题 this is the first time I am using the Yii2 GridView Widget. I have tried setting a column's width after reading some answers here on stackoverflow, but it just won't work for me and I would love it if the columns had different widths (especially the first one). I have tried setting the width using 'contentOptions' directly for the first column and also with an external CSS file for the product name column. Can someone please tell me if there is an alternative or if there is something I am

YII2 validation check unique between two fields without using active record

China☆狼群 提交于 2019-12-10 12:24:34
问题 I am using two fields "old_password" and "new_password". I want the error message if value in both fields are same. I am not using Activerecords. I tried in model : ['a1', 'unique', 'targetAttribute' => 'a2'] but above code will work only for active record. How can i get error message without using active record ? 回答1: You need to use compare validator instead of unique. ['new_password', 'compare', 'compareAttribute' => 'old_password', 'operator' => '!='], Because unique validator validates

How to write the following mongo lookup query in Yii2

ぐ巨炮叔叔 提交于 2019-12-10 12:14:25
问题 I am using this mongo extension in Yii2. I have 2 collections named ServiceProvider and Parents . In ServiceProvider there is subdocument (PostCommentIDs) containing IDs of parents. Another collection Parents contains all parent information. I wanted to join the 2 collection. I have achieved it through the following mongo query. But using the above extension how do I write this query in Yii2. db.ServiceProvider.aggregate([ { $unwind: "$PostCommentIDs" }, { $lookup: { from: "Parents",

How to disable client side validation messages of activeform in Yii 2?

心已入冬 提交于 2019-12-10 11:24:59
问题 We wish to remove the validation messages to appear on client side validation using activeform on Yii 2.0. Tried: $form = ActiveForm::begin(['clientOptions'=>['hideErrorMessage'=>false]]); Getting: Invalid Call – yii\base\InvalidCallException Setting read-only property: yii\widgets\ActiveForm::clientOptions On docs, the best I could found was: http://www.yiiframework.com/doc-2.0/yii-widgets-activeform.html#getClientOptions()-detail I have no clue what " The Options " are, so I guessed "

Yii2 Url Mapping Suffix

邮差的信 提交于 2019-12-10 11:18:32
问题 i have some simular Url Mapping in Yii2: 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ['pattern'=>'pages','route'=>'pages/index', 'suffix'=>'/'], ['pattern'=>'pages/<id:\d+>','route'=>'pages/single', 'suffix'=>'.html'], ]] So, urls: domain.com/pages/ - works fine domain.com/pages - E404 domain.com/pages/321.html - works fine domain.com/pages/321 - E404 If i remove suffix parameter from config array, then: domain.com/pages/ - E404 domain.com/pages -

Hide web from URL in Yii2

☆樱花仙子☆ 提交于 2019-12-10 11:14:55
问题 I have followed answer described in this question. I have moved Application files and folder to one level up as suggested. public_html/basic/web,config etc.. to public_html/web,config etc.. Removed index.php from url by modifying these configuration: config/web.php 'urlManager' =>[ 'enablePrettyUrl' => true, 'showScriptName' => false, ], htaccess file in web folder RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php So now my url is

Yii 2 ActiveDataProvider query with ->all() gives “Call to a member function andFilterWhere() on array” error

筅森魡賤 提交于 2019-12-10 11:08:22
问题 I need to pass ActiveDataProvider object to view and I can't understand why this: $query = Incarico::find(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); works, while this: $query = Incarico::find() ->joinWith('allegatos') ->all(); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); gives me the following error: Call to a member function andFilterWhere() on array 回答1: You should not apply all() to $query since ActiveDataProvider query property expects valid