yii2

How can create BaseController extends Controller in Yii 2

喜你入骨 提交于 2019-12-23 10:07:45
问题 As title, I would create custom controller and overwrite core controller in Yii 2, and bellow is my code. / create BaseController, I put this file in root/components. / namespace yii\base; use Yii; class BaseController extends \Controller{ public function init() { parent::init(); } } /* Extends BaseController.*/ namespace app\components; use Yii; class UsersController extends \BaseController { /* more function is here.*/ public actionIndex(){ echo _FUNCTION_; } } I change more way, but this

How to implement mysql record locking in Yii2

蹲街弑〆低调 提交于 2019-12-23 09:31:17
问题 I want to implement record locking functionality in my Yii2 application. If one user opens update link/record (Ex. http://localhost/myproject/backend/web/user/update/1 ) then another user cannot able to access thislink and user will get an ALERT message saying " This record already opened by another user ". So the record/page should lock for another user. (Same like MS Excel locking) Once first user finishes and leaves from that record/page then it should unlock and another user can read

Yii2: ActiveForm field numeric, length => 8

自闭症网瘾萝莉.ら 提交于 2019-12-23 09:19:47
问题 I'm trying to make yii2 to validate my ActiveForm field that should be numeric and of 8 characters long. Following is what I tried in the default LoginForm model of yii2/advanced/backend , but unfortunately the isNumeric validator simply doesn't kick in: public function rules() { return [ // username and password are both required [['username', 'password'], 'required'], // username should be numeric ['username', 'isNumeric'], // username should be numeric ['username', 'string', 'length'=>8],

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

Yii2 DepDrop kartik

大憨熊 提交于 2019-12-23 08:54:20
问题 Ok I am trying to use the Kartik Depdrop widget, but get this error 500 (Internal Server Error) i have parent model Brand and submodel CarModel Here are my files: CarsController.php public function actionSubcat() { $out = []; if (isset($_POST['depdrop_parents'])) { $parents = $_POST['depdrop_parents']; if ($parents != null) { $cat_id = $parents[0]; $out = self::getSubCatList($cat_id); // the getSubCatList function will query the database based on the // cat_id and return an array like below:

Twitter bootstrap select readonly still able to change options

自闭症网瘾萝莉.ら 提交于 2019-12-23 07:27:50
问题 I have a bootstrap select with readonly="true" but I can still change the selected option. I need the disabled="true" behavior, but when I use this the select is not submitted. I need a combination of the 2, the selected option can not be changed but the select has to be submitted. I could use hidden fields, but I was hoping for an easier solution. 回答1: Another possibility could be to use a select replacement with dropdowns there it should be possible to disable the dropdown but still

How to use datepicker in yii2 basic?

拟墨画扇 提交于 2019-12-23 06:50:07
问题 I want to use yii2 datepicker but I'm having trouble to implement this. It does not show the date picker and I don't know what is missing in my code. I'm still new in this yii <?php use yii\helpers\Html; use yii\bootstrap\ActiveForm; ?> <div class="row"> <div class="col-lg-6"> <div class="myproj-index"> <?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?> <? //$form->field($model, 'periodfrom') echo DatePicker::widget([ 'model' => $model, 'attribute' => 'periodfrom', 'language' =>

Yii2 set config file for module

…衆ロ難τιáo~ 提交于 2019-12-23 05:25:10
问题 How can i create my config in Yii2? and return in it for example $new = 'new' and then use it in other class? My structure Module MyModule config (directory) config.php (here must be $new = 'new') function (directory) MyFunc ( here i need use variable from config) Thanks for help! code from <?php namespace module\MyModule\function; class MyFunc { private static function func() { here i need to get $new from config } } 回答1: set config file in Module class like below: class Module extends \yii

Yii2 Update Profile Photo

一笑奈何 提交于 2019-12-23 05:15:28
问题 I have here an Edit Profile page where user can change his/her profile photo/avatar. The avatar displayed is the photo of the current user (of course) and when I click the Update Avatar button, the user can select an image, and then the selected image will preview replacing the current user avatar. Here's the code in my view: <div class="fileUpload btn btn-warning"> <span>Update Avatar</span> <input type="file" accept="image/*" onchange="loadFile(event)" class="upload"/> </div> <script> var

Declaration of bedezign\yii2\audit\components\panels\DataStoragePanelTrait::getUrl() using yii2-audit

孤者浪人 提交于 2019-12-23 04:54:19
问题 I am using yii2-audit extension for audit logs, I followed all steps of installation and also migrate all tables. But when I update table value then it will return error like Audit module cannot be loaded . I have place behaviors() in my model . My Model <?php namespace frontend\models; use yii\base\Model; use yii\web\UploadedFile; use bedezign\yii2\models\AuditTrail; use bedezign\yii2\audit\models\AuditEntry; use bedezign\yii2\Audit; class StudentForm extends \yii\db\ActiveRecord { public