yii2

How do I customize URL in Yii2?

送分小仙女□ 提交于 2019-12-12 00:52:58
问题 I'm new in Yii2 so I have Brands table with their types ('brand', 'author', 'company') and their slug name so I need the URL like that www.site.com/{brand_type}/{brand_slug} without controller name so how to do that ? 回答1: This is commonly called pretty URLs. To do achieve that in Yii2 put this in your app config file under 'components' key 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ // ... '<type:\w+>/slug:\w+>' => 'yourcontroller/youraction', // ...

Yii2: Config global template for all forms fields

痴心易碎 提交于 2019-12-12 00:12:56
问题 I have this: <?php use app\models\Location; use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use app\models\Role; ?> <?php $form = ActiveForm::begin(); ?> <div class="row"> <div class="col-sm-6"> <?= $form->field($model, 'roleId', Yii::$app->formtemplate->fieldTemplate())->dropDownList(ArrayHelper::map(Role::find()->all(), 'id', 'name'), array('prompt' => '-- Select a role --', 'class' => 'form-control select2')); ?> </div> <div class="col-sm-6"> <?= $form->field

How to join three tables and get value in grid view

烂漫一生 提交于 2019-12-11 23:56:39
问题 I have three tables : contacts hasMany groups contact_groups hasMany contacts contact_contact_groups columns in table contact contact_id | contact_name columns in table contact_groups group_id | group_name columns in table contact_contact_groups contact_contact_group_id | contact_id | group_id MODEL contacs model public function getContactContactGroups() { return $this->hasMany(ContactContactGroups::className(), ['contact_id' => 'contact_id']); } contact_groups model public function

How to write trait in yii2?

谁说胖子不能爱 提交于 2019-12-11 23:28:42
问题 Traits are much more efficient than behaviors as behaviors are objects that take both time and memory.so can anyone explain how i can write trait in yii2 ? 回答1: In General: A Trait is similar to a class, but only intended to group functionality in a fine-grained and consistent way. It is not possible to instantiate a Trait on its own. <?php trait Hello { public function sayHello() { echo 'Hello '; } } trait World { public function sayWorld() { echo 'World'; } } class MyHelloWorld { use Hello,

How to pass null values for Password in yii2?

浪子不回头ぞ 提交于 2019-12-11 22:28:05
问题 I don't want to show password while edit profile. I am using below syntax for password <?= $form->field($model, 'password',['template' => "{input}"])->passwordInput(['maxlength' => 255]) ?> How can i pass null values for password ? 回答1: You can do: <?= $form->field($model, 'password',['template' => "{input}"])->passwordInput(['maxlength' => 255,'value'=>'']) ?> Key note is 'value'=>'' However, it is suggested to do like below in your controller: $model->password=NULL; Or $model->password="";

Yii2: How to use backend web folders files in frontend

◇◆丶佛笑我妖孽 提交于 2019-12-11 19:16:21
问题 I have many images in backends web folder, I want to use those images in frontend how to get those files? I need to display 1 (first) image which path is saved in database like Img1.jpg;img2.jpg; <?php foreach (explode(';',rtrim($row['images'],';'),1) as $key_img => $value_img) { ?> <?php echo Html::img('@backend/web'.'/'.$value_img);?> <?php } ?> 回答1: <?= \yii\helpers\Html::img('@backend/web/images/your-image.jpg') ?> The src parameter, containing the backend alias, will be processed by Url:

Yii2 - Attach a component on runtime

谁说我不能喝 提交于 2019-12-11 17:34:18
问题 I did asked a question setting value in component dynamically from database, providing example for swiftmailer. The same was answered perfectly here but that answer applies to mailer component only, so how I can achieve the similar functionality for example, I need to added in my config.php values like: 'pp' => [ 'class' => 'app/components/paypal', // note: this has to correspond with the newly created folder, else you'd get a ReflectionError // Next up, we set the public parameters of the

The Content-Type HTTP header is missing charset attribute

耗尽温柔 提交于 2019-12-11 17:25:17
问题 During security check, its reported that "The Content-Type HTTP header is missing charset attribute" is missing for js and css file. Please check below screenshot: My HTML Was look like below before i have added the charset <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script type="text/javascript" src="/backend/web/assets/3faf0a44/jquery.js"></script> </head> </html> Then i have added the charset="UTF-8" in <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8">

how to use UTF8 character in path Address for Scandir php

旧街凉风 提交于 2019-12-11 17:23:27
问题 how to use UTF8 character in path Address for Scandir php my folder name is: 61-تست تست i have error in scandir and DirectoryIterator. after change folder name to 61 fix my problem but in need full name. $folder = '61-تست تست'; $path = 'files/'.$folder; print_r(scandir($path)); foreach (new \DirectoryIterator($path) as $file) { if(!$file->isDir()) { echo $file->getFilename() . "<br>"; } } error: UnexpectedValueException The system cannot find the file specified. (code: 2) DirectoryIterator::_

yii2 with dhtmlx scheduler and select populated from the server

∥☆過路亽.° 提交于 2019-12-11 17:17:01
问题 I am trying to populate the project select dropdown with data from the server. I am using yii2. My controller data action: public function actionData() { $list = new OptionsConnector(null, "PHPYii"); $list->render_table("project", "id", "id(value),name(label)"); $connector = new JSONSchedulerConnector(null, "PHPYii"); $connector->set_options("project", $list); $connector->configure( new Booking(), "id", "start, end, activity, user, subsubproject, status, comment" ); $connector->render(); } I