yii2

Can you run console jobs from yii2-basic?

喜你入骨 提交于 2019-12-22 04:33:08
问题 I am aware that Yii2-advanced has the ability to run console jobs (php yii controllername) but I was wondering if the basic app has the same ability? I notice a console.php file in the config folder, but cannot seem to get the jobs to run. If it is possible, can someone give an example - where does the controller go (since I put it in controllers, but I get the message 'Error: Unknown command test' when trying php yii test) Any help appreciated. 回答1: Yes, the same functionality exists in the

How to do a bulk database insert in Yii2?

拈花ヽ惹草 提交于 2019-12-22 04:10:10
问题 I'm wondering how you go about doing a bulk database INSERT in Yii2 ? For example a normal INSERT I would like so: $sql = $this->db("INSERT INTO some_table(id,my_value) VALUES(:id,:my_value)"); $sql->bindValues([':id' => $id, ':my_value' => $my_value]); $sql->execute(); Now what if I wanted to create a bulk INSERT ? Without binding values you could it something like: foreach ($foo as $bar) { $data_sql .= '(' . $id . ',' "'" . $bar . "')," } $data_sql = rtrim($data_sql, ','); $sql = $this->db(

How to send mail to multiple recipients in Yii2 mailer OR how to add setCc in yii2 mailer

北城余情 提交于 2019-12-22 04:09:08
问题 How to send mail to multiple recipients in Yii2 mailer? This code for a multiple recipient but not working. $value = Yii::$app->mailer->compose() ->setFrom([$this->email => $this->name]) ->setTo(array($model->email_1,$model->email_2)) ->setSubject($model->status) ->setHtmlBody($model->description) ->send(); How to add setCc in yii2 mailer? This code for adding setCc but this is also not working. $value = Yii::$app->mailer->compose() ->setFrom([$this->email => $this->name]) ->setTo($model-

Yii2 - check if the user is logged in view

淺唱寂寞╮ 提交于 2019-12-22 04:08:44
问题 I am trying to check is the user logged inside my view file, but I keep getting this error: Call to undefined method Yii::app() I tried adding $ before app but the error is still there (this time it is Undefined variable: app ). Is it possible to this is view? This is the code I use the check if the user is logged: <?php if(Yii::app()->isGuest) echo 'User is not logged!'; ?> 回答1: In Yii2 the correct syntax is Yii::$app->user->getIsGuest(); or Yii::$app->user->isGuest; Look at the

Yii2 DropDownList Onchange change Autocomplete Widget “source” attribute?

落爺英雄遲暮 提交于 2019-12-22 04:04:09
问题 I have already tried this : yii2 dependent autocomplete widget but i don't know why it's not working. here my html with script: <?= $form->field($model, 'lbt_holder_type')->dropDownList(['prompt' => '--- Select Holder Type ---', 'S' => 'Student', 'E' => 'Employee'], ['onChange' => 'JS: var value = (this.value); if(value == "S"){$(#libraryborrowtransaction-name).autoComplete({source: '. $s_data.');} if(value == "E"){$(#libraryborrowtransaction-name).autoComplete({source: '. $e_data.');} '])?>

Passing multiple parameters in a hyperlink in yii2 with clean urls, Html::a() doesnt generate clean url

ぐ巨炮叔叔 提交于 2019-12-22 03:48:16
问题 I am trying to generate a hyper link by the method mentioned in http://www.yiiframework.com/doc-2.0/guide-helper-html.html#hyperlinks like this Html::a('<b>Register</b>', ['story/create', array('id' =>39,'usr'=>'11')], ['class' => 'profile-link']) I want to get url like story/create/id/39/usr/11 But it is generating as story/create?1%5Bid%5D=39&1%5Busr%5D=1 I have enabled the clean url functionality of yii2 like 'urlManager' => [ 'class' => 'yii\web\UrlManager', // Disable index.php

Yii2: check exist ActiveRecord model in database

别说谁变了你拦得住时间么 提交于 2019-12-22 01:33:26
问题 How to check existence of model in DB? In Yii 1 version it was so User::model()->exist() 回答1: In Yii2 you can add exists() to your query chain: User::find() ->where( [ 'id' => 1 ] ) ->exists(); (The generated SQL looks like this: SELECT 1 FROM `tbl_user` WHERE `id`=1 .) Here is Query->exists()from Yii2 source: /** * Returns a value indicating whether the query result contains any row of data. * @param Connection $db the database connection used to generate the SQL statement. * If this

Multi Tenant Multiple Database Setup [closed]

被刻印的时光 ゝ 提交于 2019-12-22 01:21:38
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . We're setting up a multi tenant website using Yii2. We want to allow each user to have it's own database while using the same system. We'll also have a system database that holds the users information and information like invoicing. Here are some of our questions. How do we make

How to use constant in the ON condition in Yii2 hasMany relation

隐身守侯 提交于 2019-12-22 01:13:27
问题 I try to create a polymorphic association, what is common in Rails but unfortunately not in Yii2. As part of the implementation I need to define the relation: public function getImages() { return $this->hasMany(RecipeImage::className(), ['imageable_id' => 'id', 'imageable_type' => 'Person']); } But this doesn't work, because 'Person' is treated as an attribute of the current model, but it is a constant (class name for the polymorphic association). If I try to use 'andWhere' it adds the

ActiveForm, custom id for field broke validation

我的梦境 提交于 2019-12-22 00:17:11
问题 I'm pretty new with Yii2 and have the next unpleasant issue. I created two forms at same page like <?php $form = ActiveForm::begin([ // make sure you set the id of the form 'id' => 'create', 'action' => $action, 'options' => ['enctype' => 'multipart/form-data'] ]); ?> <?php $form = ActiveForm::begin([ // make sure you set the id of the form 'id' => 'update', 'action' => $action, 'options' => ['enctype' => 'multipart/form-data'] ]); ?> I use the same model for both form fields like <?= $form-