yii2

Override User afterLogin Method

江枫思渺然 提交于 2019-12-10 17:46:01
问题 How to override afterLogin method in yii2? Where Should I write? protected function afterLogin($identity, $cookieBased, $duration) { } I'm New to yii2. Please Guide me. 回答1: You need to implement the afterLogin method in your User ActiveRecord class. So assuming you have set up your projects you'll find the User class in your models folder. So just add the afterLogin method to that class to do whatever post-login processing you need to. 回答2: Here’s detailed information. You could inherit

Listening for logout event in Yii 2

情到浓时终转凉″ 提交于 2019-12-10 17:38:12
问题 So I know that Yii::$app->user triggers these events in the logout process. const EVENT_BEFORE_LOGIN = 'beforeLogin'; const EVENT_AFTER_LOGIN = 'afterLogin'; But where is the right place to add a listener at the beginning of each request? 回答1: The best place would be in the class which handles the identity of yii/web/User ; usually, this is common/models/User . In that class, you can have the following initialization. public function registerLogoutHook() { $this->on(\yii\web\User::EVENT_AFTER

CKEditor Code Snippet plugin does not do syntax highlighting in yii2 framework

限于喜欢 提交于 2019-12-10 17:37:42
问题 I am using CKEditor and its Code Snippet plugin in yii2 php framework application. I would like to get syntax highlighting when I write some code using CKEditor, but whatever I do I can not make it work. I have tried everything from the guide like including css and highlight.js in the head but I get nothing... Declaring asset bundle also do not help, yii2 will load files, but highlighting still do not work. public $css = [ 'css/site.css', 'highlight/styles/default.css' ]; public $js = [ 'js

How to integrate Stripe payments into Yii2?

a 夏天 提交于 2019-12-10 17:34:33
问题 I have the following code, it runs without error, however it does not insert funds onto the Stripe server. The Stripe library is installed correctly. config.php <?php //require_once('vendor/autoload.php'); $stripe = array( "secret_key" => "sk_test_key", "publishable_key" => "pk_test_key" ); \Stripe\Stripe::setApiKey($stripe['secret_key']); SiteController.php public function actionSend() { $model = new SendForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model-

Call to undefined function mb_strlen() on PHP 7 Ubuntu 14.04

安稳与你 提交于 2019-12-10 17:33:16
问题 I had a Yii installation that was working fine up until today. I installed updates on my machine today after which this error was being thrown on all pages: PHP Fatal Error – yii\base\ErrorException Uncaught Error: Call to undefined function yii\web\mb_strlen() in /application/vendor/yiisoft/yii2/web/ErrorHandler.php:404 I ran composer update but the error persists. I am using yii 2.0.7 on PHP 7 on Ubuntu 14.04. How do I fix this? 回答1: The error is a bit of a red herring since mb_strlen() is

How to use Yii2 kartik gridview editable column with mulitple model relations

半城伤御伤魂 提交于 2019-12-10 17:23:19
问题 Question: I have 2 models, user model and user profile model, both are related with primary and forien key user_id, user table has fields id,username, password, email etc user_profile table has filed id, user_id, company, phone etc I have created gridview in user view. I am using kartik EditableColumn, I want to edit user profile table field company from user gridview. What I have done so far. Please check code what I have done. please note: it is portion of code i am showing here, and I

Client side validation in not working

泪湿孤枕 提交于 2019-12-10 17:15:22
问题 I am working client side validation in yii2 but it is not working for me. View File <?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\captcha\Captcha; ?> <ul class="breadcrumb"> <li><a href="index.html">Home</a></li> <li><a href="#">Pages</a></li> <li class="active">Login</li> </ul> <!-- BEGIN SIDEBAR & CONTENT --> <div class="row margin-bottom-40"> <!-- BEGIN SIDEBAR --> <!--<div class="sidebar col-md-3 col-sm-3"> <ul class="list-group margin-bottom-25 sidebar-menu"> <li class=

Session expiring in Yii2 despite user activity

末鹿安然 提交于 2019-12-10 17:06:42
问题 I have started using Yii2 and need to store more information about user in identity. I already know that in Yii2, this should be done using sessions like Yii::$app->session->set('user.company_id', '121'); This works fine as I am able to get these values later in project using: Yii::$app->session->get('user.company_id'); . However, these session values are getting wiped up despite user activity on same pages. So after 5-10 minutes, the same user sees some fields based on session value, however

yii2 radio inline Html helper

孤街醉人 提交于 2019-12-10 16:54:14
问题 I have this radioList in yii2 Html::radioList('abc',null,$new,['class' => 'form-control input-sm']); It generates this: <div class=radio> but I want: <div class=radio-inline> please help me 回答1: No. Let's say that $new = [1 => 'Hello', 2 => 'World'] ; The generated output will be: <div class="form-control input-sm"> <label> <input type="radio" name="abc" value="1"> Hello </label> <label> <input type="radio" name="abc" value="2"> World </label> </div> If you want to add radio class to

Yii2 error: The view file does not exist

£可爱£侵袭症+ 提交于 2019-12-10 15:57:41
问题 I've been using Yii2 for a few weeks now, and getting the hang of it. However, today, for a reason I do not know, Yii's been routing me to the wrong page, causing errors because web pages have not been found: URL: http://localhost/web/index.php?r=site/index Error: Invalid Parameter – yii\base\InvalidParamException The view file does not exist: C:\xampp\htdocs\views\site\index.php However, I've been able to navigate my site with http://localhost/web/index.php?r=paramA/paramB since I started