yii2

Issue in yii2 timezone formatter

梦想与她 提交于 2019-12-07 03:40:15
问题 in php.ini timezone is UTC. system timezone is UTC. yii defaultTimeZone is UTC. But my datetime attribute gets converted to my timezone "Asia/Kolkata" before saving into db. Eg: UTC time 12:00Hrs my input 17.30hrs what I expect in db is 12:00hrs and in view 17.30hrs But what I got in db is 17:30hrs and in view I got 23:00hrs. web.php: 'formatter' => [ 'class' => 'yii\i18n\Formatter', 'dateFormat' => 'php:d-m-Y', 'datetimeFormat' => 'php:d-m-Y H:i a', 'timeFormat' => 'php:H:i A', 'timeZone' =>

Yii2 create a form without a model

自闭症网瘾萝莉.ら 提交于 2019-12-07 01:56:46
问题 I was wondering how can I create a form without a model in Yii2 framework as I am creating a mailchimp signup form so a model isn't necessary the below code generates a form however as you can see it uses a model. <?php $form = ActiveForm::begin(['id' => 'login-form']); ?> <?= $form->field($model, 'title')->textInput(['maxlength' => 255]) ?> <?php ActiveForm::end(); ?> Do I still use activeform, how can I remove the $model variable without it throwing up an error? 回答1: Yii2 has this nice

How to specify a validation rule in Yii2 which will be greater than or less than of a specific number or value?

痞子三分冷 提交于 2019-12-07 01:26:03
问题 I have a model with a validation rule like: [['x'], 'integer'], [['x'], 'unique'], Now how can I add a rule like: x < 100 or something like x >= 100 回答1: It should be: ['x', 'compare', 'compareValue' => 100, 'operator' => '<'], and ['x', 'compare', 'compareValue' => 100, 'operator' => '>='], accordingly. Read more in official docs. 回答2: You could also use the min attribute on number, or integer validators: ['age', 'integer', 'min' => 0], ['amount', 'number', 'min' => 0], There is also a max

FCM push notification issue :- “error”:“NotRegistered”

故事扮演 提交于 2019-12-07 01:05:58
问题 I am getting weird issue of sending push notification to android using FCM. Goal :- Having error while sending push notification Below is the scenario I do have function for sending push notification to android public static function SendMultipleNotificationAndroid($groups) { //your api key SERVER API KEY $apiKey = Yii::$app->params['android_api_key']; $url = 'https://fcm.googleapis.com/fcm/send'; $headers = array( 'Authorization:key=' . $apiKey, 'Content-Type: application/json' ); $ch = curl

How to upgrade Yii 1.x to Yii 2.0

ぐ巨炮叔叔 提交于 2019-12-06 23:23:59
问题 How to upgrade Yii 1.x version to Yii 2.0 latest release version? I am using ubuntu OS , Process to updating my old Yii to new Yii release version 2.0? 回答1: The Yii2 guide has excellent documentation in this regard see Upgrade from v1 I recently migrated couple of moderately complex applications from Yii 1.x to Yii 2.0. There are two ways to go about it , either you can run Yii 1.x and Yii 2 at the same time see using-yii-2-with-yii-1. Then migrate part by part, while it is possible it was

How to add current timestamp in the database. What is the format?

我只是一个虾纸丫 提交于 2019-12-06 22:29:29
问题 I want to add the current system time into database while inserting new record into database as in "time_created" column. PHP's time() function don't have support in yii2. I want yii2 specific time function that will help me save current timestamp. Anyone knows???? 回答1: Yii 2 has special behavior for this. Just attach it to the model. Add this to your model to behaviors() method: use yii\behaviors\TimestampBehavior; use yii\db\Expression; public function behaviors() { return [ // Other

How to implement single search form in yii2

一世执手 提交于 2019-12-06 22:27:53
问题 Yii2 has a searchModel to search each field in the GridView . Is it possible to just create a single search field outside the GridView where the user can input keywords and by the time Search button is hit, the results will display in the GridView based on the keywords entered. CONTROLLER public function actionIndex() { $session = Yii::$app->session; //$searchModel = new PayslipTemplateSearch(); $PayslipEmailConfig = PayslipEmailConfig::find()->where(['company_id'=> new \MongoId($session[

How to switch on\off frontend form validation for some fields in yii2?

爷,独闯天下 提交于 2019-12-06 22:16:07
问题 I have got difficult form in yii2 view, where some fields show or hide. It decide from user field choises, select options in the form. I write this frontend logic with custom jquery file. All is ok. But when I submit form - hidden fields stay without validation and nothing is happend.How I can kill ofrontend validation, when fields are hiiden and switch on it, when fields are visible? 回答1: To disable client side validation. Begin your active form like this. ActiveForm::begin([

How to write global functions in Yii2 and access them in any view (not the custom way)

筅森魡賤 提交于 2019-12-06 20:59:57
问题 Yii1.1 had a CComponent class that had a CBaseController which was the base class for CController. There was a /protected/components/Controller.php class which enabled any function in that class to be accessed in any view. Yii2 no longer possess the CComponent class. The Yii2 guide indicates that "Yii 2.0 breaks the CComponent class in 1.1 into two classes: yii\base\Object and yii\base\Component". Does anyone know how to write global functions in Yii2 and them in any view, just like it was in

Yii2 and storing data in database as UTC

只愿长相守 提交于 2019-12-06 20:43:27
I'm using Yii2 and I was wondering how it decides what timezone to store the data in the database as? I have noticed the $defaultTimezone which seems to indicate it simply controls what timezone your input data is supposed to be when passing it to functions such as the the asTime function and it uses the formatter timezone to convert said data into the correct time output. But I'm wondering how do you make sure it is inserting the data into your database in the right timezone so then the value of $defaultTimezone can be trusted? Is there a need to run something like this for MySQL : SET time