yii2

Yii2 Download File function

萝らか妹 提交于 2020-05-25 18:39:19
问题 I need to download file from folder /uploads, but I just get timeOut error when the action is called, Anyone can help me :( public function actionDownload() { $path = Yii::getAlias('@webroot') . '/uploads'; $file = $path . '/1.pdf'; if (file_exists($file)) { Yii::$app->response->sendFile($file); } } 回答1: If a download takes too much time, I see 2 possibilities You can increase the max execution time of your script. That's not the best solution as the script will still time out for too big

Yii2 - Import Multiple users from CSV file

為{幸葍}努か 提交于 2020-05-17 08:46:20
问题 I have two tables. one is user-table -name - user and another table named profile. The format of csv file for user is like this: first_name,last_name,username,email,phone,user_role,status,password_hash,auth_key,created_at,updated_at,key_date,reset_key,access_token Abx,xyz ,8917111039,abca@examplemail.com,891445544,employee,10,$2y$13$jbsLKjG6YtiA1RbilUOeauAS2Zvq5fHB5xh6JnHpfVytvI56IiO32,,,,,, Alek,buhu,7978019779,sahu_alek@examplemail.com,7978444449,employee,10,$2y$13

Yii2 - ActiveRecord to Array

三世轮回 提交于 2020-05-10 07:01:28
问题 Is there any way to convert ActiveRecord to an array in Yii2? I do know we can do that for ActiveQuery , for example User::find()->asArray()->one(); , but can we convert Model to array when it is already fetched? I want to do that in beforeSave() method and store that array in cache. 回答1: From Yii2 guide - use ArrayHelper::toArray(): $posts = Post::find()->limit(10)->all(); $data = ArrayHelper::toArray($posts, [ 'app\models\Post' => [ 'id', 'title', // the key name in array result => property

Yii2 Chart is not defined

谁都会走 提交于 2020-05-05 21:23:44
问题 I am trying to show some data on the chart while using Yii2 . I have installed Yii2 Chart JS via the composer. Below is the code is taken from the documentation use practically\chartjs\Chart; Chart::widget([ 'type' => Chart::TYPE_BAR, 'datasets' => [ [ 'data' => [ 'Label 1' => 10, 'Label 2' => 20, 'Label 3' => 30 ] ] ] ]); Now when I refreshed this page I not seeing any chart. But in inspect->console I am getting an error Uncaught ReferenceError: Chart is not defined Update 1 Here is my

Yii2 Chart is not defined

江枫思渺然 提交于 2020-05-05 21:20:54
问题 I am trying to show some data on the chart while using Yii2 . I have installed Yii2 Chart JS via the composer. Below is the code is taken from the documentation use practically\chartjs\Chart; Chart::widget([ 'type' => Chart::TYPE_BAR, 'datasets' => [ [ 'data' => [ 'Label 1' => 10, 'Label 2' => 20, 'Label 3' => 30 ] ] ] ]); Now when I refreshed this page I not seeing any chart. But in inspect->console I am getting an error Uncaught ReferenceError: Chart is not defined Update 1 Here is my

Array to string conversion while using canvas js in yii2

坚强是说给别人听的谎言 提交于 2020-04-30 09:17:38
问题 I am trying to load a chart on my index page in yii2 project . Below is my code <?PHP $dataPoints1 = array( array("label"=> "2010", "y"=> 36.12), array("label"=> "2011", "y"=> 34.87), array("label"=> "2012", "y"=> 40.30), array("label"=> "2013", "y"=> 35.30), array("label"=> "2014", "y"=> 39.50), array("label"=> "2015", "y"=> 50.82), array("label"=> "2016", "y"=> 74.70) ); $dataPoints2 = array( array("label"=> "2010", "y"=> 64.61), array("label"=> "2011", "y"=> 70.55), array("label"=> "2012",

Adding minutes to date time not working properly

半世苍凉 提交于 2020-04-29 03:39:23
问题 I am working on Yii2 . In it I am trying to insert data into 3 different stages. i.e. I am using 3 queries one by one to insert different types of data. The data insertion is perfect but date-time is not. As I want to add data continuously so I have added a for loop . But the date-time it's inserting is always the same. See my code below for ($i = 0; $i <= 60; $i++) { $dt = date('Y-m-d H:i:s'); $model401->data_date_time = date('Y-m-d H:i:s', strtotime('+5 minutes', strtotime($dt))); $model402

yii2 formwizard checkbox field value set to 1 even if not selected

徘徊边缘 提交于 2020-04-16 03:55:08
问题 I am using yii2-formwizard and I want to insert a checkbox as form input field for the field is_legal in a tabular step. So in fieldConfig array, reading the documentation, I inserted the following code: 'is_legal' => [ 'options' => [ 'type' => 'checkbox', 'template' => '{input}{beginLabel}{labelTitle}{endLabel}{error}{hint}', ], 'labelOptions' => ['label' => \Yii::t('app', 'Legal Representative')], ], If I select the checkbox or not the value of the field is always 1 as shown on: . However,

yii2 formwizard checkbox field value set to 1 even if not selected

不想你离开。 提交于 2020-04-16 03:52:03
问题 I am using yii2-formwizard and I want to insert a checkbox as form input field for the field is_legal in a tabular step. So in fieldConfig array, reading the documentation, I inserted the following code: 'is_legal' => [ 'options' => [ 'type' => 'checkbox', 'template' => '{input}{beginLabel}{labelTitle}{endLabel}{error}{hint}', ], 'labelOptions' => ['label' => \Yii::t('app', 'Legal Representative')], ], If I select the checkbox or not the value of the field is always 1 as shown on: . However,

Yii2 SwiftMailer sending email via remote smtp server (gmail)

假如想象 提交于 2020-04-13 18:35:22
问题 I want to send emails via my gmail account. My mailer config: [ 'class' => 'yii\swiftmailer\Mailer', 'useFileTransport' => false,//set this property to false to send mails to real email addresses 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'smtp.gmail.com', 'username' => 'my@gmail.com', 'password' => 'pass', 'port' => '587', 'encryption' => 'tls', ], ] I wrote command MailController: <?php namespace app\commands; use yii\console\Controller; use Yii; /** * Sanding mail * Class