yii2

Yii2 check if user is logged before every page [duplicate]

。_饼干妹妹 提交于 2020-01-03 06:35:49
问题 This question already has answers here : Yii2 global filter/behavior to force user to authenticate first (2 answers) Closed 4 years ago . I am new to Yii2. How can i check if user is logged in or not ? If user is not logged in then it should redirect to login page. Is there any global solution? 回答1: I set the 'access' behaviors in all controllers public function behaviors() { return [ 'access' => [ 'class' => AccessControl::className(), 'only' => ['logout', 'signup'], 'rules' => [ [ 'actions'

Yii2 Activerecord get fields from junction table and order by according to them

心已入冬 提交于 2020-01-03 03:31:09
问题 I have items and units table that have many to many relationship. In other words, the item has many units and the unit has many items. I managed the relation through a junction table item_units . The junction table has some extra field more than item_id and unit_id , i.e it has price, and weight (it is an integer to manage the order of units for each item for display purposes). I managed the relations in the models as follows: //In Items model /** * @return \yii\db\ActiveQuery */ public

Restricting controller action to creator of post in Yii2

ぐ巨炮叔叔 提交于 2020-01-02 17:43:39
问题 Is there an easy way to restrict a controller action to the owner/creator of the post without using full blown RBAC? Right now I'm doing this for every controller: public function actionUpdate( $id ) { $model = $this->findModel( $id ); if ( $model->user_id != Yii::$app->user->identity->id ) { throw new NotFoundHttpException( 'The requested page does not exist.' ); } } But I think there must be a better way to restrict certain controllers to the users who created the $model thats being edited.

Restricting controller action to creator of post in Yii2

社会主义新天地 提交于 2020-01-02 17:43:08
问题 Is there an easy way to restrict a controller action to the owner/creator of the post without using full blown RBAC? Right now I'm doing this for every controller: public function actionUpdate( $id ) { $model = $this->findModel( $id ); if ( $model->user_id != Yii::$app->user->identity->id ) { throw new NotFoundHttpException( 'The requested page does not exist.' ); } } But I think there must be a better way to restrict certain controllers to the users who created the $model thats being edited.

How to call stored procedure with parameters in Yii2

为君一笑 提交于 2020-01-02 05:25:13
问题 How to call stored procedure with parameters in Yii2? This my stored procedure ALTER PROCEDURE [dbo].[usp_M_Inventory#InsertData] @ID_Item RunNum, @Item_Name varchar(250), @ID_Mom varchar(50), @Item_Price float, @ID_Inv_Category RunNum, @Item_PIC1 varchar(50), @Item_PIC2 varchar(50), @Item_active BIT, @User UserDataType AS BEGIN SET NOCOUNT ON; INSERT INTO M_Inventory(ID_Item, Item_Name, ID_Mom, Item_Price, ID_Inv_Category, Item_PIC1, Item_PIC2, Item_active, insert_user, insert_date, update

Radio Button group in separate place in yii2

一曲冷凌霜 提交于 2020-01-02 04:09:06
问题 So, I want to have two radio button in separate place, I have been trying to search for the solution and everyone suggests to use radiolist which is not possible in my case. If I put it like this (work_part_time button) : (below) <div class="row"> <div class="col-sm-2"> <?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?> </div>- <div class="col-sm-3"> <?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => 'Hour/Week'])->label

Radio Button group in separate place in yii2

不羁岁月 提交于 2020-01-02 04:09:04
问题 So, I want to have two radio button in separate place, I have been trying to search for the solution and everyone suggests to use radiolist which is not possible in my case. If I put it like this (work_part_time button) : (below) <div class="row"> <div class="col-sm-2"> <?= $form->field($model, 'work_part_time')->radio(['label' => 'yes', 'value' => 1])?> </div>- <div class="col-sm-3"> <?= $form->field($model, 'hour_week')->textInput(['type' => 'number', 'placeholder' => 'Hour/Week'])->label

Yii2 - How do I AutoLoad a custom class?

佐手、 提交于 2020-01-02 01:10:00
问题 I have created the following custom class that I'd like to use in my Yii2 application: @common/components/helper/CustomDateTime.php namespace common\components\helper; class CustomDateTime{function Now() {...}} I want to use this class like this: public function actionDelete($id) { $account = $this->findModel($id); $account->archived = 1; $account->archived_date = CustomDateTime::Now(); $account->save(); return $this->redirect(['index']); } In my @common/config/bootstrap.php file I've created

Yii2 Display image stored in BLOB database field

我只是一个虾纸丫 提交于 2020-01-01 18:23:13
问题 Greetings I need to display images stored in BLOB database fields in a LISTVIEW or similar widget from Yii2 I have the actionCreate that saves the image in table named honra as a BLOB public function actionCreate() { $model = new Honra(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $file = UploadedFile::getInstance($model,'binaryfile'); $model->binaryfile=$file; return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' =>

Could not open input file composer.phar in Windows 7

江枫思渺然 提交于 2020-01-01 16:39:09
问题 I am trying to install an extension in Yii2, while I installing through command prompt using C:\wamp\www\project>php composer.phar require mdmsoft/yii2-admin "~1.0" I am getting an error like this: could not open input file composer.phar 回答1: Where did you install composer? You have to add the directory, for example: php C:\ProgramData\ComposerSetup\bin\composer.phar require ... If you add the directory to your windows path you can simply call composer require ... 回答2: Read here https:/