yii2-basic-app

Yii2 - RBAC rule to allow/view own data

旧时模样 提交于 2020-01-25 09:43:09
问题 I have installed yii2mod/yii2-rbac from this url - https://github.com/yii2mod/yii2-rbac in yii2-basic. everything is working fine except using/allowing owner data. from this link:https://www.yiiframework.com/doc/guide/2.0/en/security-authorization I have created a folder in root rbac and file AuthorRule.php and code: namespace app\rbac; use yii\rbac\Rule; //use app\models\Post; /** * Checks if authorID matches user passed via params */ class AuthorRule extends Rule { /** * @var string */

Auto login using “remember me” not working

橙三吉。 提交于 2020-01-11 11:48:13
问题 I am new to Yii2. I'm using Yii 2 basic template. I have the "remember me" functionality implemented on my web application, but it is not working as I think it was supposed to. I can successfully log in (with a checked "remember me" checkbox). But after closing the browser and opening the website again I am not logged in, but instead redirected to the login page. I have set enableAutoLogin to true in the config file 'user' => [ 'identityClass' => 'app\models\User', 'enableAutoLogin' => true,

Textfield Mandatory On basis of radio button selection- Yii2

和自甴很熟 提交于 2020-01-05 02:03:08
问题 I'm having radio button with two value i.e, Individual and Firm. I am looking for one scenario where if radio button having value Firm is selected, then CompanyName textinput should act as mandatory (required) field. And, when radio button having value Individual is selected, Then CompanyName textinput should act as Optional field. I was not getting how to do it. I tried to add addAttribute in CompanyName textinput as mandatory. but it didn't worked as RegisterForm.php (model) is having few

Enable debugger tool for particular user through custom controller in Yii2

可紊 提交于 2019-12-25 02:26:21
问题 To enable debugger tool, we modify web/index.php file defined('YII_DEBUG') or define('YII_DEBUG', false); defined('YII_ENV') or define('YII_ENV', 'prod'); How to override or change these variables in custom controller? class CommonController extends Controller { public function init() { $user_id = 1; if($user_id == 1){ defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); } } } Goal is to enable the debugger for particular user. I know there is a

URL Routing - yii-basic-app - Yii2

天大地大妈咪最大 提交于 2019-12-24 15:11:09
问题 i was trying to pass ID in URL. I was getting difficulty to do it. So, i was going through tutorials like Larry Ullman - URL Routing. My problem is: I created confirm.php page and created a controller too but error like NOT FOUND (#404) coming. SiteController.php <?php namespace app\controllers; use Yii; use yii\filters\AccessControl; use yii\web\Controller; use yii\filters\VerbFilter; use yii\swiftmailer\Mailer; use app\models\LoginForm; use app\models\ContactForm; use app\models\EntryForm;

How to get previous and next row model ID in yii2 gridview data row

早过忘川 提交于 2019-12-24 10:37:59
问题 While in GridView widget and displaying ActiveDataprovider results that i fetched from a customized query, i want to get next and previous row $model->id while displaying the records, what i need to do is to show links to previous and next posts while in reading mode, my gridview already generates link to the post view but there doesnt seem to be an option to get next DB row's record ID i have already tried to use default values in the function available but they dont seem to hold any related

Write info message in app.log file using yii2

泪湿孤枕 提交于 2019-12-24 08:10:55
问题 I want to write info message in app.log file for debugging. For that I am using that code in web.php file:- log' => [ 'traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], ], [ 'class' => 'yii\log\FileTarget', 'levels' => ['info'], 'categories' => ['orders'], 'logFile' => '@app/runtime/logs/requests.log', 'maxFileSize' => 1024 * 2, 'maxLogFiles' => 20, ], [ 'class' => 'yii\log\FileTarget', 'levels' => ['info'], 'categories' => [

Validating unique email using DynamicFormWidget - Yii2

邮差的信 提交于 2019-12-24 00:34:20
问题 I am using DynamicFormWidget for multiple input fields like: first_name , last_name , email & mobile_no . And, I don't want user to type the existing email . Means, email should be unique. It is working when I am not using DynamicFormWidget . Actually, I don't know how to validate unique email in multiple input forms using Yii2. addmembers.php (View) <?php use yii\helpers\Html; use yii\widgets\ActiveForm; use wbraganca\dynamicform\DynamicFormWidget; ?> <?php DynamicFormWidget::begin([

Yii2 full calendar event filtering not working

不想你离开。 提交于 2019-12-23 09:08:13
问题 I'm using Philipp Frenzel FullCalendar in Yii2 framework and its working perfectly. I want to implement basic filter events on calendar base on option select but my codes still not working. Help would be highly appreciated. This is inside EventController : <?php namespace app\controllers; use Yii; use app\models\Event; use app\models\EventSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; /** * EventController implements the CRUD actions for Event

In Yii2 framework, better place to define common function which is accessible everywhere like controller, model, view

做~自己de王妃 提交于 2019-12-23 03:26:42
问题 Like i want to create function with name "dt()" function dt(){ return date('Y-m-d H:i:s'); } and want to access it like this:- echo dt(); //retrun current date and time format Which is better place in Yii2 framework to do that? 回答1: You can use it this way: http://www.yiiframework.com/extension/yii2-helpers/ Create a folder /common/helpers/ , then create a helper class there and add your static methods. namespace common\helpers; class DateHelper { public static function dt(){ return date('Y-m