yii2

validate password for login always false using yii 2

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 16:50:28
问题 This is my validatePassword function in models/user.php public function validatePassword($password) { /* var_dump(Yii::$app->getSecurity()->validatePassword($password, $this->password)); */ return Yii::$app->getSecurity()->validatePassword($password, $this->password); }; this is my setPassword function in models/user.php public function setPassword($password) { $this->password = Yii::$app->getSecurity()->generatePasswordHash($password); } to call setPassword function I use following

Yii2 Modify find() Method in Model search()

可紊 提交于 2019-12-12 15:49:38
问题 I am trying to modify the find() method inside the model search and it throws an error "The data provider property must be set". Here is my search model: public function search($params) { $userID = Yii::$app->user->identity->id; $groups = GroupAccess::find() ->where(['user_id' => $userID, 'item_name' => 'group_creator']) ->asArray() ->all(); foreach ($groups as $group) { $accessGroups[] = $group['group_id']; } $query = Group::find($accessGroups); $dataProvider = new ActiveDataProvider([

Get User Profile - dektrium/yii2-user Yii2

前提是你 提交于 2019-12-12 15:10:11
问题 I have used dektrium/yii2-user in my application. And there is a method named getID() in User.php of vendor/dektrium and this method can be accessed by Yii::$app->user->getID() and returns id of the logged in user. However, there is another method named getProfile() whose function is to return complete profile details of currently logged in user. But, this method is giving 500-internal server error. exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: yii\web\User

yii2:Custom Pagination for Gridview in form view

随声附和 提交于 2019-12-12 15:00:07
问题 I have included the Gridview widget in _form.php file, which is working well. The problem is the filter and pagination. <?php $dataProvider = new ActiveDataProvider([ 'query' => \app\models\ServiceCharges::find(), 'pagination' => [ 'pageSize' => 5, ], ]); ?> <?php $searchModel = New \app\models\ServiceChargesSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); ?> </div> </div> <div> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' =>

Yii2: Ajax Call multiple parameters

被刻印的时光 ゝ 提交于 2019-12-12 14:14:58
问题 I am using this code for auto-fill with ajax call without any problem: Code in my view file: $this->registerJs("$('#dailywardentry-doctor_visit_name').on('change',function(){ $.ajax({ url: '".yii\helpers\Url::toRoute("daily-ward-entry/charges-cash")."', dataType: 'json', method: 'GET', data: {id:$('#dailywardentry-doctor_visit_name').val(), room_category:$('#dailywardentry-room_name').val()// Want to use this additional params }, success: function (data, textStatus, jqXHR) { $('

How to implement kartik yii2 FileInput in form which is using different model

╄→尐↘猪︶ㄣ 提交于 2019-12-12 13:51:33
问题 Here is the code located in myyiiapp\backend\views\product_form.php <?php use yii\helpers\Html; use yii\widgets\ActiveForm; use kartik\widgets\FileInput; /** * @var yii\web\View $this * @var backend\models\Product $model * @var yii\widgets\ActiveForm $form */ ?> <div class="product-form"> <?php $form = ActiveForm::begin(); ?> <?= $form->field($model, 'category_id')->textInput() ?> <?= $form->field($model, 'name')->textInput(['maxlength' => 255]) ?> <?= $form->field($model, 'description')-

scroll pager extension In Yii2

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 12:43:15
问题 i am using Yii2 with a scroll pager extension: http://kop.github.io/yii2-scroll-pager/ Here's my code: echo yii\widgets\ListView::widget([ 'dataProvider' => $boards, 'itemView' => 'boards', 'layout' => $template, 'itemOptions' => ['class' => 'item'], 'pager' => ['class' => \kop\y2sp\ScrollPager::className()] ]); and i am seetting dataProvider from modal The Code is given below $dataProvider = new ActiveDataProvider([ 'query' => Boards::find(), 'pagination' => array('pageSize' => 3), ]);

ActiveForm without model yii2

房东的猫 提交于 2019-12-12 12:20:48
问题 I want to create ActiveForm without model for just in case something. I did try with dynamicModel but i got some error : use yii\base\DynamicModel; $model = DynamicModel::validateData(compact('KOMENTAR'), [ [['KOMENTAR'], 'string', 'max' => 128], ]); This is the form i want to create <br> <?php $form = ActiveForm::begin([ 'method' => 'post', ]); ?> <?= $form->field($model, 'KOMENTAR')->textarea(['rows' => 6])->label(false) ?> <div class="form-group"> <?= Html::submitButton('POST', ['class' =>

How to put line-breaks in Yii2 validation rules messages

拜拜、爱过 提交于 2019-12-12 12:14:50
问题 I need to break a long message used in Yii2 validation rule. I tried like this: public function rules() { return [ ['username', 'required', 'message' => 'long message first line here'."<br>".PHP_EOL.'long message last line here'], ]; } but the <br> appears in the message and the line doesn't break where I need. Just to be clear, what I get is: long message first line here<br>long message last line here and not: long message first line here long message last line here Anyone who can help with

Yii2 saving form with multiple models

删除回忆录丶 提交于 2019-12-12 11:35:00
问题 Hi I am very close to finish a project but got stuck saving a from with multiple models. I have a grid that calls a controllers action that calls a form. public function actionToday() { $ID = $_GET["0"]; $modelCustomers = Customers::find()->where(['ID' => $ID])->one();; $today = date("Y-m-d"); $beforeToday = 'DropinDate>'.$today; $modelAttendance = Attendance::find()->where(['CustomersID' => $ID])->andwhere(['DropinDate' => $today])->one(); return $this->render('//attendance/_form-today