yii2

Yii not detecting camel case actions

走远了吗. 提交于 2019-12-13 14:22:19
问题 Yii is giving me 404 Error if I declare an action like this: SiteController.php public function actionRegisterUser() This is how I call it in the main.php ['label' => 'Register User', 'url' => ['/site/RegisterUser']], I tried several different combinations. The only combination that will work is this naming convention in both places: public function actionRegisteruser 'url' => ['/site/registeruser'] I used to work on another Yii project (Yii 1.0) and I could name my actions in camel case and

Yii2: Remove controller from URL

醉酒当歌 提交于 2019-12-13 14:16:59
问题 I am using the advanced template. I created all my actions on the SiteController, so all my urls are domain.com/site/something, and I need to remove the word "site" from the url so it will be domain.com/something. I tried the following rules based on this question 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'showScriptName' => false, 'enablePrettyUrl' => true, 'rules' => array( '/<action:\w+>/<id:\d+>' => 'site/<action>', '/<action:\w+>' => 'site/<action>', '/noticia/<slug>' => 'site

File Not uploading in yii2

雨燕双飞 提交于 2019-12-13 14:04:52
问题 I want to upload an image and save it into my database. Here, the field name in database is image_path . When, I am trying to upload my image it shows an error: Call to a member function saveAs() on a non-object on line $customer->file->saveAs('uploads/customer/' . $customer->file->baseName . '.' . $customer->file->extension); If I print var_dump($customer->file); it returns NULL . Can anyone help me to resolve this issue. This is my view: <?php $form = ActiveForm::begin([ 'id' => 'my-profile

yii2 select2 by kartik-v set default value

假装没事ソ 提交于 2019-12-13 13:27:22
问题 I've a question about yii2 kartik-v widget select 2. the widget is attached to a field in my view <?= $form->field($model, 'address')->widget(Select2::className(), [ 'options' => ['placeholder' => 'Inserta an address '], 'pluginOptions' => [ 'allowClear' => true, 'minimumInputLength' => 3, 'ajax' => [ 'url' => Url::to(['register/addresses']), 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }') ], 'escapeMarkup' => new JsExpression('function (markup

How to use send the chosen file in Kartik Input File using Ajax?

扶醉桌前 提交于 2019-12-13 12:41:40
问题 I want to use drag & drop upload file using Kartik Input File in my Yii2 application. They said this "drag & drop" input file model need AJAX for send the data. I just following the main code for Kartik Input File from here, and the AJAX from here. I'm new in programming, and I dont know yet how to use AJAX. So I've tried to combine both of code like this in my view.php (path = app/views/students/view.php): <script> $(".btn-success").fileinput({ uploadUrl: 'students/create', // server upload

Filtering yii2 grid using a form with related model

自作多情 提交于 2019-12-13 10:27:44
问题 Am using a search model with a search form and i would like to filter a grid view based on the value entered in the form. The form field is of a related table Am actually searching tblpritems and filtering its grid on the column pr_solicitation_id by entering supplier_id as in the tblprsuppliers This is the model relationships In the tblpritems public function getPrSolicitation() { return $this->hasOne(Tblprsolicitations::className(), ['pr_solicitation_id' => 'pr_solicitation_id']); } In the

Yii2 GridView filter date by year

╄→гoц情女王★ 提交于 2019-12-13 09:55:47
问题 This question is simple, but in Yii2 I cannot find the solution. Given a birthday field, how is it possible in gridview to filter by year? Typically in an index gridview. 回答1: Maybe you are looking for something like this: add in to your model public static function getYearsList() { $years = (new Query())->select('DISTINCT YEAR(`birthday`) as years')->from('{{%yourTable}}')->column(); return array_combine($years, $years); } and then in gridview [ 'attribute' => 'birthday', 'filter' =>

how to deny the access of url in yii even if we know the url?

[亡魂溺海] 提交于 2019-12-13 09:55:16
问题 In my yii webapplication i disable and enable several url s to set privilege. But the same url can be accessed to a user that haven't the privilege to acces that url by copying the url or getting it form some where. What should i do to avoid this? 回答1: In controller the function behaviors is for this. you can find the doc in yii2 guide filters (core filter / access control). This a medium complexity sample for rules (allow only index, view, mpdf-form for roles viewerApp and viewModule1. Allow

Vendor folder is missing in yii2 and composer fails update

非 Y 不嫁゛ 提交于 2019-12-13 09:36:54
问题 I cloned my project from git. Vendor folder is missing in yii2 and when I update composer, it shows Your requirements could not be resolved to an installable set of packages. Problem 1 - yiisoft/yii2 2.0.9 requires bower-asset/jquery 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable -> no matching package found. - yiisoft/yii2 2.0.8 requires bower-asset/jquery 2.2.*@stable | 2.1.*@stable | 1.11.*@stable -> no matching package found. - yiisoft/yii2 2.0.7 requires bower-asset/jquery 2

Setting Routes for RestApi in Yii2

谁说胖子不能爱 提交于 2019-12-13 09:26:09
问题 I am trying to make rest api with my methods. 'rules' => [ [ 'class' => 'yii\rest\UrlRule', 'controller' => ['ApiController'], 'patterns' => [ 'PUT,PATCH api/{id}/update' => 'update', 'DELETE api/{id}/delete' => 'delete', 'GET,HEAD api/{id}' => 'get', 'POST api/{id}/create' => 'create', 'GET,HEAD' => 'api/index', '{id}' => 'options', '' => 'options', ] ], Api controller: /** * Displays homepage. * * @return string */ public function actionIndex() { // $id = Yii::$app->request->getQueryParam(