yii2

Yii2: how to specify multiples database schemas?

走远了吗. 提交于 2021-02-20 04:51:10
问题 I am using PostgreSQL and the default database schema in my Yii2 application. I created a new schema called laboratory and I need to define it in the common/config/main-local.php file. This is my current main-local.php file: <?php return [ 'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'pgsql:host=localhost;dbname=travel', 'username' => 'aaaa', 'password' => 'bbbb', 'charset' => 'utf8', ], ], ]; How can I add the laboratory schema in this file? I need both schemas. Is

How to show relational data in yii2

我们两清 提交于 2021-02-19 08:59:21
问题 I'm having trouble understanding how relations work in yii 2 I have 2 tables in a mysql database, author and book. book has a column named author which links to the id of the author table via foreign key. I've generated CRUD using gii, and I want the author name to appear in the list view, as well as dropdowns for the author name in the create and update views. But I cant seem to get the relation working even in the list view. Here's my code Book Model: <?php namespace app\models; use Yii;

Yii2 remove index.php from url

纵然是瞬间 提交于 2021-02-18 11:20:48
问题 When I set the option in Yii to remove index.php from the URL I get a 404 error and this error in the error logs File does not exist: /var/live/var . In my browser I get this error The requested URL /var/decat/frontend/web/index.php was not found on this server. but the file is exactly in that location. What might explain that is that my document root is /var/live and decat is an alias as shown in the conf file. This url works fine http://13.21.16.180/decat/index.php/site/login but when I

Yii2: Conditional Validator always returns required

若如初见. 提交于 2021-02-17 21:39:12
问题 I am trying to use Yii2's conditional validator as given in the guide like: Model code public function rules() { // $discharged = function($model) { return $this->discharged == 1; }; return [ [[ 'admission_date','discharge_date', 'doctor_appointment_date', 'operation_date'], 'safe'], [[ 'package','tpa_name', 'discharged', 'bed_type', 'room_category', 'ref_doctor', 'consultant_doctor', 'operation_name'], 'integer'], [['advance_amount', 'operation_charges'], 'number'], [['patient_name', 'ref

Yii2: Conditional Validator always returns required

孤人 提交于 2021-02-17 21:38:42
问题 I am trying to use Yii2's conditional validator as given in the guide like: Model code public function rules() { // $discharged = function($model) { return $this->discharged == 1; }; return [ [[ 'admission_date','discharge_date', 'doctor_appointment_date', 'operation_date'], 'safe'], [[ 'package','tpa_name', 'discharged', 'bed_type', 'room_category', 'ref_doctor', 'consultant_doctor', 'operation_name'], 'integer'], [['advance_amount', 'operation_charges'], 'number'], [['patient_name', 'ref

Yii2: Conditional Validator always returns required

喜夏-厌秋 提交于 2021-02-17 21:37:20
问题 I am trying to use Yii2's conditional validator as given in the guide like: Model code public function rules() { // $discharged = function($model) { return $this->discharged == 1; }; return [ [[ 'admission_date','discharge_date', 'doctor_appointment_date', 'operation_date'], 'safe'], [[ 'package','tpa_name', 'discharged', 'bed_type', 'room_category', 'ref_doctor', 'consultant_doctor', 'operation_name'], 'integer'], [['advance_amount', 'operation_charges'], 'number'], [['patient_name', 'ref

Display in view image loaded in controller with yii2

情到浓时终转凉″ 提交于 2021-02-11 15:22:52
问题 I'm trying to display in a view an image loaded in a controller (the image folder is not available directly from the view). I can correctly load the image in the controller but I did not find the correct way in order to provide the view with it. I tried to exploit the Yii::$app->response solution but it seems useful for the download of the image and not for showing it in the view page. Controller code (partial) public function actionView($id) { $imgFullPath = '/app/myfiles/img/65/img.jpg';

CORS header 'Access-Control-Allow-OrigCross-Origin Request Blocked yii2

和自甴很熟 提交于 2021-02-11 06:16:34
问题 I'm using yii2 rest api. I want to get my information by ajax but I'm getting this error. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://........... (Reason: CORS header 'Access-Control-Allow-Origin' missing). How can I fix this problem? 回答1: You should read this : Cors filter and REST Api and CORS filter Cross-origin resource sharing CORS is a mechanism that allows many resources on a Web page to be requested from another domain outside

CORS header 'Access-Control-Allow-OrigCross-Origin Request Blocked yii2

梦想与她 提交于 2021-02-11 06:16:32
问题 I'm using yii2 rest api. I want to get my information by ajax but I'm getting this error. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://........... (Reason: CORS header 'Access-Control-Allow-Origin' missing). How can I fix this problem? 回答1: You should read this : Cors filter and REST Api and CORS filter Cross-origin resource sharing CORS is a mechanism that allows many resources on a Web page to be requested from another domain outside

Yii2 - Update database field when switchinput widget is clicked

泄露秘密 提交于 2021-02-10 16:00:58
问题 I am using the switchinput Kartik widget which I have related to a database true/false field (field1). What I want to do is to be able to update this database field value when I change the switch. Here is the view code: <?php echo $form->field($model, 'field1')->widget(SwitchInput::classname(), [ 'type' => SwitchInput::CHECKBOX, 'name' => 'status_11', 'pluginOptions' => [ 'size' => 'medium', 'onColor' => 'success', 'offColor' => 'danger', 'handleWidth'=>80, 'onText'=>'ACTIVE', 'offText'=>