FAQ Database Discussion Community


yii2 login page for advanced templet with admin lte and yii2-user extension

yii2,yii2-user
has anybody tried using admin lte theme with yii2-user extension. the login to the admin page couldn't work for me. i am using localhost for frontend and localhost/admin for backend. the frontend is working fine but i couldn't get it work for backend due to the adminlte theme. any clues?...

Dependent Dropdown in Yii2 making values reset while updating the Active form

yii2
Here my problem is i have a form . In that i have dependent dropdown. for example if i select company name it automatically selects the dependent company email and company phone number. This is working perfectly while creating. but the problem is while am updating the same form, the...

how to display relation data into json format from two table in yii2 restful api

php,json,rest,yii2,relation
I got the problem to display the data from two table into JSON format and working on yii2 restful api. this is my structure database: TABLE `volunteer`( `volunteer_id` int(11) NOT NULL auto_increment, `state_id` int(11) null TABLE `state`( `state_id` int(11) NOT NULL auto_increment, `state` varchar(225) null volunteerController.php public $modelClass = 'app\models\Volunteer';...

Yii2 rewrite URLs with query string to be SEO

.htaccess,yii2,friendly-url
What I have could able to make pretty URL in Yii example.com/readings/view?BookID=9955 First, readings is my default controller, so I don't want its actions to be prefixed by its name i.e: example.com/view?BookID=9955 Second I need to neglect ?BookID= to be: example.com/view/9955 Also I have books paging: example.com/readings/view?BookID=9955&start=2 I need it...

Button not working on Pjax Reload

javascript,php,jquery,yii2,pjax
I am using Yii2 php framework and my page looks like this: Based on the photo, when I click one of the radio buttons, for example "Pending", the GridView would only display all pending reimbursements. The problem is that, in the Action column, the buttons don't work anymore. As you...

Javascript in Yii2 AssetBundle is not published on update

javascript,yii2,assets,assetbundle
I have a quite simple AssetBundle: use yii\web\AssetBundle; /** * ImagizerAsset */ class ImagizerAsset extends AssetBundle { public $sourcePath = [email protected]/components/widgets/imagizer/assets'; public $css = [ 'css/imagizer.css' ]; public $js = [ 'js/imagizer.js', ]; public $depends = [ 'app\assets\BowerCropperAsset' ]; } If I change the JavaScript in the bundle, it is...

Yii2 route using yii\rest\UrlRule with several parameters

php,rest,yii,routing,yii2
I am trying to use Yii 2 routing for REST API. Following tutorial at http://www.yiiframework.com/doc-2.0/guide-rest-routing.html, I have already defined (with success) a lot of rule for API entry point like so : 'urlManager' => [ 'enablePrettyUrl' => true, 'enableStrictParsing' => true, 'showScriptName' => false, 'rules' => [ [ 'class' =>...

Run string as static class function in Yii2

php,yii,yii2
I'm receiving prepared function as strings like these: "\app\models\AddrModel::getText('A_00001724');" Now I need to convert and run this string as static function call, to retrieve the value if the A_00001724 id. How do I do that? PS: When I call it as $value = new $function; I get Class '\app\models\AddrModel::getText('A_00001724')' not...

error: Call to a member function validatePassword() on a non-object (yii2)

php,yii2
I'm new in this framework actually this is my first time to use framework. Can someone help me on this error I don't know how to fixed this error. here is my code: User.php: <?php namespace app\models; use Yii; class User extends \yii\db\ActiveRecord implements \yii\web\IdentityInterface { public $id; public $username;...

How to use find all condition in the layout file main.php in yii2

php,yii2
Iam new to yii 2.0 i want to display all the project names in the layout file. i can use the following code in layouts->main.php <?php $model = Project_manage::find()->all(); ?> When i use this code in the main .php The following Error will come Error (#1) An internal server error...

How to block an action or controller without using AccessControl in Yii2? [on hold]

yii2,access-control
I am using yii2-basic. I created a controller with init() method in it. This init() method will check some cookies and deny access to all actions if the condition doesn't meet. But I don't know how to do it, could anyone help me? Sorry for bad English.

Yii2: Change Gridviews' DataProvider on button click

javascript,php,gridview,yii2,pjax
I have 3 seperate dataProviders for my Gridview, one with Saved data, one with Unsaved data and one with both. Now this is what I'm trying to accomplish: If you click on saved, the dataProvider changes to the one with saved data. I'm trying it like this: <?php if($i ==...

yii2 show hidden field

javascript,field,yii2
I have problem to show the hidden field. this is my script : <script> function showOther(obj){ if(obj=="Lainnya"){ document.getElementById('user-bank_other').style.display="block"; return false; }else{ document.getElementById('user-bank_other').style.display="none"; return false; } } Then this is my form : <?= $form->field($model, 'bank_id')->dropDownList([ '1' => 'Bank Central Asia', '2' => 'CIMB Niaga', '9999' => 'Lainnya', ], ['prompt' =>...

Data is not getting from model - Yii2

yii2
I have inserting data from activeForm in yii <?php $form = ActiveForm::begin([ 'id' => 'register-form', 'options' => ['class' => 'form-horizontal'], 'fieldConfig' => [ 'template' => "<div class=\"\">{label}{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]);?> <?= $form->field($model, 'firstname')->textInput(['placeholder' => 'First Name']) ?> <?= $form->field($model,...

Yii 2.0 Loading css and js in renderPartial

css,twitter-bootstrap,yii2
How can I load css and javascript files if I render a page using renderPartial() ? The problem is that I NEED my page to be mobile responsive. This does not seem to be a problem when I use render() I tried including the boostrap css and js in my...

Getting an error Call to a member function getCount() on a non-object

yii2
i am using sqldataprovider and i am geting a Call to a member function getCount() on a non-object error. i dont know what have i done wrong. below is my controller code public function actionTicketbookingreport() { $count = Yii::$app->db->createCommand(' SELECT COUNT(*) FROM screen_ticket_booking_history WHERE status=:status ', [':status' => 0])->queryScalar(); $dataProvider...

How to create layout that use header and footer partials

php,layout,view,yii2
I have red the guide about views and layouts, I have googled how to to this, but I still can not make it work. Here is the problem: I want to have 2column.php and 3column.php layouts, where both are using _header.php and _footer.php partials. 2columns.php layout example: render _header.php $content...

Yii2 - create dropdown (select) with another model

php,yii2
At the begging of the view file I am loading model: use app\models\Countries; And a bit down in the code I am trying to create dropdown (model is generated via gii): <?php echo $form->field(Countries::find()->all(), 'Country') ->dropDownList( ['prompt'=>'Select Country'] ); ?> I am getting this error: PHP Fatal Error – yii\base\ErrorException...

yii2 asset bundle - single file position

yii2,assetbundle
I am doing a web app on Yii2 framework. Defined (extended) new AssetBundle class NeonAsset extends AssetBundle { public $sourcePath = [email protected]/themes/neon/'; public $css = [ 'css/font-icons/entypo/css/entypo.css', '...', '...' ]; public $js = [ 'js/be_in_head_tag.js', '...', '...', ]; } When rendered, CSS files are being published in <head> tag, and...

Yii2 GridView pagination with only next and prev links and no TotalCount

php,gridview,pagination,yii2
There is a huge DB table with millions of rows and it needs to be outputed in a GridView with only prev and next links in the paginator. I don't want to use 'select count(*)' on such tables, so there's no TotalCount. Also I want to prevent users from setting...

Yii2 disable asset of a vendor module

module,yii2,assets,vendor,assetbundle
I have install yii2-admin module, located in /vendor/mdmsoft/yii2-admin and I want don't want it to load it's own asset bundle. It there anyway to disable this module asset bundle?

yii2 join model as dataProvider

yii2
I've joined 2 tables like following: $model = SalesEntry::find() ->joinWith('salesItems') ->all(); then in view used DataProvider like following: GridView::widget([ 'dataProvider' => $model, 'columns' => [ 'date', // sample field from first table to see if ok ], ]); and I’ve got following error: Call to a member function getCount() on...

Warning on GCM with PHP

php,android-gcm,yii2
I'm using GCM in php. Everything is fine. But im getting response as "Field \"data\" must be a JSON array: example\n" My code for GCM is function sendNotification($registrationIdsArray, $messageData) { $data = array( 'data' => $messageData, 'registration_ids' => $registrationIdsArray ); var_dump($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header); curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");...

Form Not working in YII2

php,yii2
I am new to yii framework. I have created a from like this. When i try to view the form in the browser like this http://localhost/basic/web/index.php?r=site/user i see a blank white page. I checked the apache log, No errors logged. I have added the files to git hub.. https://github.com/sathyabaman/yii_basic_learning Model...

MongoDB on Amazon EC2 - Configuring Mongo Client for Php

php,mongodb,yii,amazon-ec2,yii2
I am pretty new to Amazon EC2. I followed the instructions given in mongodb official site for installing mongodb on Amazon Linux. I have a Yii-2(basic) project to host on my amazon Linux server. mongoDB is already installed in the and even I Imported some dumps over there. But when...

yii2 Pjax + java script prompt

yii2
It there any way to make 'data-confirm' => Please enter the number' not just confirm but some like JS prompt and get imputed values to sent it to controller? <?php \yii\widgets\Pjax::begin(['id' => 'pjax-orders_table','clientOptions' => ['method' => 'POST'], 'enablePushState'=>false]) ?> <?= GridView::widget([ 'dataProvider' => $dataProvider, 'id'=>'orders_table', 'columns' => [ ['class' =>...

How to update/insert array of values to database using Yii2 ( many values for one id that repeats )

php,mysql,yii2
I am collecting some data from database and then display it in index view. There I have check box near every row, so I can allow users to pick their favorites. Picture and text is selected from one table cpv. That table has fields: id, title, image. Since logged in...

How to use active query method of another model class via relation in Yii2

php,yii2
I have models like below /** * @property integer $id * @property string $title */ class Book extends ActiveRecord { public static function find() { return new BookQuery(self::class); } } class BookQuery extends ActiveQuery { public function andWhereTitleLike($string) { return $this->andWhere(['like', 'title', $string]); } } /** * @property integer $id...

Use Faker to fill table without knowing table structure

mysql,yii,yii2
Can I use (and if yes -- then how) Yii2 Faker to fill entire table (all columns) with random data for n records without knowing table structure? Can Faker check schema and do this for me or do I have to write my own code, that will use it in...

How to log in user to my web application when he click on some link in his email

php,mysql,email,login,yii2
Every day I need to send emails to my users with links for articles that they may be interested in on my news site. Example of link: <a href="http://example.com/article/5/some-seo-title>title of article </a> I am keeping data about users in my user table: id, username, email ... When user clicks some...

how to define a relationship in Yii2 with orOnCondition

yii2,database-relations
I am logging changes in my database to a table called audit_field. For a given model I would like to retrieve all the audit_fields for this model as well as some of the related models. For example: <?php class Job extends ActiveRecord { public function getAuditFields() { $link = [];...

Yii2 GridView - Generate filtered or sorted URL

php,gridview,yii2,crud
I use gii generate the CRUD page of Product, I can access the the list by index.php?r=product and in code, the url is ['/product']. Now I want to access the product index page with filtered parameter and sorted parameter? Is there any tool or standard way to achieve these? For...

No error message show in yii2

yii2,yii2-advanced-app
I cann't not show the error message. This is my site code. <div class="login_wrapper"> <div class="row"> <div class="left_block"> <div class="row"> <form class="col-md-12 col-sm-12 col-xs-12"> <h2 class="login_heading">Login</h2> <div class="row"> <?php $form = ActiveForm::begin([ 'fieldConfig' => [ 'template' => "{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}", ]]); ?> <div class="input-field col-md-12 col-sm-12 col-xs-12"> <?= $form->field($model, 'username', [...

Multiple alias in one account

yii2,yii2-advanced-app,fortrabbit
I never used fortrabbit before and i have a question about it. I know i can create apps and define the document root, but lets imagine the following: I want to go with Yii2 Framework (Advanced template) Advanced template have "two apps" in it (2 folders) the backend and the...

Yii2 jQuery not working in IE11

jquery,yii2,internet-explorer-11
The Problem I'm trying to create a page that updates a specific records field in a table when a checkbox is clicked (ideally without refreshing the page). I thought jQuery/AJAX would work for me. Apparently not. I've been struggling with this for a while, so I decided to scale it...

Yii2 : how to cache active data provider?

php,caching,yii2,dataprovider
In my PostSearch model I have this code : public function search($params) { $query = Post::find()->where(['status' => 1]); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort'=> ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => [ 'pageSize' => 10, ] ]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere([ 'id' =>...

Yii2 - JSONP response returns nothing (blank) and does not work, but JSON does

php,json,yii,jsonp,yii2
I am using Yii2, and for what it's worth, I know the basics, and have been programming for a while. This is probably from a lack of documentation in this area (Yii2 JSONP and Responses). All I find is examples of returning a JSON response, none showing a JSONP response....

Working with memcache with Yii and ActiveRecords

php,yii,memcached,yii2
So I've been trying to get memcache working on my site running Yii 2. I've got the caching working for the DB schema stuff, but it doesn't seem to work for ActiveRecord queries. This is my config for the DB: 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=127.0.0.1;dbname=db_name', 'username'...

Yii2 display the base path

php,yii2
How to get the base path in yii2. <?php echo Yii::app->getBaseUrl() ?> not working KIndly fix this...

Spanish location for yii2-date-picker-widget

datepicker,yii2
I am working on the basic template of Yii2. I use the 2amigos yii2-date-picker-widget. Datepicker is working fine, but it keeps showing me the default language (that is English) instead of Spanish. As you can see in the code below, the language param is set to 'es': <?= $form->field($model, 'alta')->widget(...

How to change current user in Yii2

login,yii2
I'm still new in yii2 and I'm trying to make my admin user able to switch to another user so he can see the pages exactly like this users (If they report any problem/bug). I found the switchIdentity() method, but I just can't figure out how to call this $identity...

How to install DateTimePicker in Yii2

yii2,yii-extensions,yii-components
I have creating form fields. Here, i want to add DateTimePicker. I have referred in google about some date time picker. i got so many. DateTimePicker jQuery plugin Bootstrap DateTimePicker. My question is which plugin is best among them. and How can i install that plugin? Download directory and place...

Setting ID attribute of input field when using ActiveField in Yii2?

yii,yii2
I'm trying to set a custom id for an input field whilst using ActiveField in Yii2. I tried the below, but it instead set the id of the field container instead of the input field itself. $form->field($model, 'some_id', ['options' => ['id' => 'some_id']])->hiddenInput(['value' => $some_id])->label(false); Is there a way I...

Yii2: How to add validation rules to the model class dynamically?

php,reflection,model,yii2
As per the Yii2 docs validation rules can be applied either to the implicit properties (table fields) or to the userDefined properties. Is there a way to create validation rules for the properties which are dynamically added to the model class ? For example: Let there be model class named...

Undefined offset: 0 in yii2

php,yii2,gammu
I just have that code in my model, and as a result of that, I got Undefined offset: 0 what should I do to solve that? I've tried declare new variable, but still nothing change. Thank you public function sendSMS() { $model2 = SibuStudent::find()->innerJoin('Sibu_Payment', 'Sibu_Payment.virtual_id=Sibu_Student.virtual_id' )->where('Sibu_Student.phone1 != "NULL" ' )...

Yii2, how to run a command from another command?

yii2
I would like to make a shortcut to a long command. The command I have is: ./yii gii/giiant-crud --modelClass="app\models\Job" --controllerClass="app\modules\admin\controllers\JobController" --searchModelClass="app\models\search\Job" --template="admin" The command I want is: ./yii gii-q/crud job I created a command controller, but I'm not sure how to run another command controller from here: <?php namespace app\commands;...

Yii2 : Getting unknown property when using findBySql

mysql,sql,web,frameworks,yii2
i'm using findBySql() to get data from database, i want to show the data in view with table. This is code on my controller : $sql = "SELECT presensi.presensi_tanggal 'tanggal', sum(if( hadir.keteranganhadir_id='1',1,0)) 'hadir', sum(if( hadir.keteranganhadir_id='2',1,0)) 'tidak_hadir', count(*) 'total' FROM hadir, keteranganhadir, presensi where hadir.keteranganhadir_id = keteranganhadir.keteranganhadir_id and hadir.presensi_id = presensi.presensi_id...

Yii2 two submitButtons going to wrong URL

php,html,yii2
I have a form with a modal window where you can submit extra data to be input into the form. The modal has its own 'submit' button separate from the submit button on the main form. The problem is, when I click the submit button on the modal, it goes...

yii2 disable page cache on post request

php,caching,yii2,yii2-advanced-app
I have a page where I submit a form that I want to cache but only for get requests. I cannot figure out if there is a way to do this but the Yii2 guide seems to hint at it http://www.yiiframework.com/doc-2.0/yii-filters-pagecache.html#$enabled-detail, it says you can enable it only for Get...

IIS and Yii2 pretty URL

.htaccess,iis,web-config,yii2
What is the .htaccess equivalent for IIS to enable pretty URLs in Yii2 on IIS. Indeed, I don't know what could I do with web.conf to allow those URLs.

how to run yii form validation before my js file

javascript,jquery,yii2
I added some js and css files using assets to my app. My problem is that I want to run some function when the user click the submit button, but only after yii validator checked if theres no errors. Right now my function running before yii validator. How can I...

Yii 2: Load a module's view as a partial view on another application view

php,yii2,yii-modules
I need to load a module's view as a partial view inside another view of the application. I find no clue about how to do this in the manual. The view is completely independent of the module: <?php // This is the module's class. Do I need it here? use...

yii2 - Why use yii\helpers\Html instead of just typing

html,yii2
Just a basic newbie question to understand the reasoning. Why should one use HTML helpers available in Yii2, or can't we just type the tags if we are strong in our HTML skills. Example: Seen in the basic views... <h1><?= Html::encode($this->title) ?></h1> Why should I not just type... <h1>My Title</h1>...

“Undefined variable” error, when rendering data in a view

php,view,yii2
I want to render static array in _form.php view, using actionCreate method in Yii2. Here is my code: if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { $data = array('1'=>'AA','2'=>'BB'); return $this->render('create', [ 'model' => $model, 'data' => $data , ]); } When I try to...

yii2 error when trying to install all generats files

php,frameworks,yii2
When I am trying to type init --env=Development --overwrite=n in command line on Linux I have an error bash: --env=Development: command not found...

How do I get a list of key, value pairs from the database for a select list in Yii?

php,yii2
How do I get a list of key/value pairs to populate the options to a relation in a select list in Yii? Similar to the following in Rails: = f.select :age_group_id, AgeGroup.order(:name).pluck(:name, :id) ...

Yii2 Query Builder with ActiveRecord

php,mysql,yii2
I have three models Employer , Job, and Transaction Employer can have many Job Job can have many Transaction I am trying to use ActiveRecord to get all Employer that do not have a Transaction record. Within my Employer model, I have defined relations to find all jobs and transactions...

Yii 2: Module class not found

php,yii2,yii2-advanced-app,yii-modules
In the backend/config/main file, there is a reference to the module class: 'modules' => [ 'cropk' => [ 'class' => 'app\modules\cropk\CropK', ] ], In the vendor/xxx/cropk directory, there is the following class CropK: namespace app\modules\cropk; class CropK extends \yii\base\Module { public function init() { parent::init(); } } The vendor/xxx/cropk/controllers/DefaultController: namespace...

Using Gii afer updating model files

yii,yii2,gii
I am learning Yii and I wonder if I generate model and CRUD files using Gii and then I modified these files manually then I changed my database should I run Gii again ? is it going to overwrite my changes in the model files ? if so what is...

Is it possible multi-database call for YII2 or LARVEL 5

php,laravel-5,yii2
I'm developing a big project by using YII framework ( MySql database engine ). I'm preparing to continue developing the rest part of the project by migrating to YII2 or Laravel 5. In this my question I'm not asking which one frameworks is better, because it is clear there no...

Order By count(*) from other table in yii 2

php,mysql,activerecord,order,yii2
I have 2 table: videos and likes video table has fields: id, title .. likes table has fields: id, video_id, user_id I would like to get the 10 most like videos. I can do it in sql by command: SELECT videos.*, COUNT( likes.video_id ) AS countlike FROM videos LEFT JOIN...

Can the Yii2 assets pipeline watch subdirectories?

php,yii2
I try to follow the SASS guidelines for my style sheets. The guidelines suggest putting all code in files topically sorted into 7 folder (6 in our case, due to how Yii handles dependencies). The Yii2 assets pipeline seems to watch only the $sourcePath for changes, ignoring the subdirectories. Changing...

How to set page size in GridView in yii2 [closed]

gridview,yii2
I want to set item per page in GridView in view file in a Yii2 project. I know I can set it in DataProvider instance, but I want to set in each view file separately. How can I do it?...

Yii2 REST giving a 405 on POST, PUT, etc

yii2,yii2-advanced-app
I'm trying to build a REST API in a Yii2 advanced application for managing simple queries to my database. Following some tutorials, finally build step by step the example in the Guide, in Quick Start, and get my model working for GET and HEAD methods. Created my API service inside...

Yii2 URL manager rules and forms with GET method

php,yii2,yii-url-manager
I have a global search form that submits to search action of a controller: <?=Html::beginForm(['/feqh/search'], 'get', ['class' => 'navbar-form navbar-left', 'role' => 'search', 'id' => 'searchForm']);?> <div class="form-group has-feedback Right"> <input id="q" type="text" class="form-control" placeholder="<?=yii::t('app','Search');?>" name="q" value="<?= Html::encode(\Yii::$app->getRequest()->getQueryParam('q',""));?>" /> <i class="form-control-feedback glyphicon...

Yii2 required validation on update

php,validation,yii2
I've Yii2 form containing form fields depending on action of page. Ex. Few fields appears when then action is create and few appears when action is update. I want to add required validation based on this scenario. Ex. <?= $form->field($model, 'unique_identifier')->textInput(['maxlength' => 45]) ?> I am showing this field only...

Creating dependent dropdown in Yii2

php,yii2
I need to create a dependent dropdown in Yii2 I have two tables, admin and employee, when admin selects employee name, employee's details such as email, age, dateofbirth and phone should get filled automatically. How do I go about doing this?...

Codeception Acception: How to validate a changed Url

php,yii2,codeception,acceptance-testing
I am trying to validate and post login action. But the problem occur after login, when the user is redirected to the index page. There is a welcome message shown only for authenticated users. Can someone help me out. I'm using Yii 2 Framework! use \AcceptanceTester; class LoginCest { public...

Yii 2: Using module's image declared as asset

php,yii2,yii-modules
I have a image in a module within the following structure: vendor/myvendorname/mymodulename/assets/img/delete-icon.png I need to add an <img> to the page via JavaScript, and it may have the src attribute pointing to that delete-icon.png. $("#delete").attr("src", "?"); How can I reference the image if it will be put in an asset...

Yii2 client side validation for dynamically added multiple inputs

yii2
Multiple inputs with same name are added in a form dynamically using jQuery. So now how can I validate these dynamic inputs using yii2 validation rules at client side ?

Importing data from xls,csv to Mysql using Yii 2.0 Framework

import,yii2,mysqlimport
I need to import data from XLS,CSV file into MySql database using YII 2.0 Framework, XLS, CSV files contains datas which should to imported to one table in Mysql DB, Please provide any information to proceed....

Removing the number of first page in Yii2 Pagination from the URL

.htaccess,pagination,seo,yii2
For SEO purposes I need to remove the first page number from the URL. i.e I have the following: example.com/pages/view/1 and example.com/pages/view the two URLs points to the same contents of the view action. I want to make the pagination free from 1 in the URL. i.e first Page link...

Yii2 enforce 404 or 500 error

yii2,yii2-basic-app
In my controller's action of Yii2 application suppose the following: public function actionView($i) { if ($i < 20) { //I want execute error 404 } } All what I can to do now is just setting a flash message and redirect to another action. However, I want to generate 404...

Yii2 Active record query multiple where clause from array

yii2
Yii2's index page's default data provider is like following: $dataProvider = new ActiveDataProvider([ 'query' => ModelName::find(), ]); Now, I've got an array like $arr = [1, 2, 4, 6]; I want to add a where clause like: WHERE parentId=1 OR parentId=2 OR parentId=4 OR parentId=6 How can I do that?...

Yii2 - Kartik Grid Extension Error

php,gridview,yii2
I have made many attempts to install Kartik Grid Extension, but all of them failed due to this error: Setting unknown property: yii\bootstrap\ButtonDropdown::containerOptions The error is located in /Applications/MAMP/htdocs/business/vendor/yiisoft/yii2/base/Component.php at line 197 My view as the code: use kartik\grid\GridView; <?= GridView::widget([ 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [...

Yii2, Model find() with custom attribute

yii2
I want to pull the model data with custom attribute that assigned in a function in model. Example) class Test extends ActiveRecord { public static function tableName() { return '{{%test}}'; } public function rules() { //.... } public function attributeLabels() { return [ 'id' => 'ID', 'first_name' => 'First Name',...

Yii2 - Saving multiple related ActiveRecord models in one form

php,yii2,crud,gii
Here is the table structure: Table BaseTable id (primary key) INT description VARCHAR(255) Table ChildTable id (primary key)(foreign key reference to BaseTable) INT child_property VARCHAR(255) It's a inheritance relation in database table actually. Then I use gii to generate the models with relation function for both, and CRUD operation for...

Error deploying yii2-starter-kit Yii2 installation

web-services,yii2
I'm trying to deploy this Yii2 installation (https://github.com/trntv/yii2-starter-kit/blob/master/docs/installation.md#configure-your-web-server) but I'm having problems. I think problems are related with this configuration step: "Configure your web server". I've the webpage running here: http://vector5.raspctl.com/yii2-starter-kit/frontend/web/ But no one of the options works. For example, "Connect" option (http://vector5.raspctl.com/yii2-starter-kit/frontend/web/user/sign-in/login) I can't found the error, any help?...

Yii2 - check if the user is logged in view

yii,yii2
I am trying to check is the user logged inside my view file, but I keep getting this error: Call to undefined method Yii::app() I tried adding $ before app but the error is still there (this time it is Undefined variable: app). Is it possible to this is view?...

How do I create a complex left outer join in Yii2?

php,activerecord,orm,yii2
How do I perform this query in Yii2? SELECT `keyword`.`id`, `keyword`, `volume`, `cpc`, `competition`, `keyword_id` FROM `keyword` LEFT JOIN `ad_group_keyword` ON keyword.id = ad_group_keyword.keyword_id and ad_group_id = 1 WHERE ((`keyword_id` IS NULL) AND (NOT (`volume` IS NULL))) AND (NOT (`cpc` IS NULL)) ORDER BY volume desc LIMIT 1; I tried...

Change the button action in Gridview based on a model attribute value Yii2

php,yii2
I generated a simple application by CRUD generator... In the View page there is a action column assigned with some buttons like view, update, delete.... all I want is to create a status button.... If the status is inactive it should ask me and change the status into active and...

Can someone explain how Yii minimizing assets is supposed to work on Heroku?

php,heroku,yii,yii2
I just got through getting the minification to work (How do I combine & minify JS and CSS for a Yii app on Heroku?) locally. However, it creates the all-1bc649be34b1e6afc9b2419687cde016.js file under web/assets/. Yii creates a .gitignore to ignore everything in that directory. None of the files will make it...

Create Url in Yii2

yii2
I have created a custom Url in Yii2 using 'urlManager' => [ 'class' => 'yii\web\UrlManager', // Disable index.php 'showScriptName' => false, // Disable r= routes 'enablePrettyUrl' => true, 'rules' => array( '<controller:\w+>/<id:\d+>' => '<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', 'site/GetNewTicketsTechnician' =>...

Yii2: Passing index page to breadcrumbs in view and update actions

gridview,yii2,breadcrumbs,yii2-advanced-app
1) Have several pages of results in index (GridView) with default LinkPager settings. 2) Invoke either update or view actions in ActionColumn. 3) Do whatever, then click breadcrumbs to return to the same page in GridView you came from, but it does not: You're back at page 1 which in...

datepicker yii2 kartik wrong format

yii2,datetimepicker
I have a problem with the kartik datetime picker. The value that has to be entered gets scrambled in the input, following screenshot probably tells it all: I simply followed the demo code: <?php use kartik\datetime\DateTimePicker; echo '<label>Start Date/Time</label>'; echo DateTimePicker::widget([ 'name' => 'startdatetime', 'options' => ['placeholder' => 'Select operating...

yii2 disable the rules if a checkbox is selected

yii2,rules,active-form
In the active form, I have 3 textinput and one checkbox. All the 3 textinputs have rules that says cannot be empty. What I want is if the checkbox is clicked, It will disable the rules and will save the empty record in the database. here is screen shot of...

How to use custom css file for layout of a module in Yii2

php,css,layout,module,yii2
I am using basic pack of Yii2. I created a module named Admin and I want this module has it own layout but i don't know where to put all its css files. Then, how to include them in layout.php. My dirs like this: basic -- module -- admin --...

Yii2: how to pass object to module

yii2,yii2-advanced-app
let's say I'm making ecommerce app with Yii2 and would like to implement all payment methods as modules. After order has been confirmed by user, I would like to redirect user to payment process. I have following code in my CheckoutController: if($order->save()) { $module = Yii::$app->getModule('payment'); $module->init(); } At this...

Yii2 elasticsearch setAttributes() not working

php,elasticsearch,yii2
I am using Yii 2.1 and Yii2-elasticsearch 2.0.3 with a elasticsearch 1.5.0 server to try and index a Member model for a more powerful search. I have a common\indexes\Member model that extends yii\elasticsearch\ActiveRecord and set up the attributes I want to index. namespace common\indexes; use yii\elasticsearch\ActiveRecord; class Member extends ActiveRecord...

How to import CArrayDataProvider to controller

php,yii2
Sorry for my stupid question, I'm realy newbie with Yii, but I don'n know how to import CArrayDataProvider to my controller class. I've found one way Yii::import('application.extensions.CArrayDataProvider'); (after this call I got error Call to undefined method Yii::import()) but it isn't work for me, because I haven't folder extensions at...

Yii2. “With” in ManyToMany

php,yii2,database-relations
I have 3 models: Image, Company and File. So if we look through Company model, we have: /** * @return \yii\db\ActiveQuery */ public function getImages() { return $this->hasMany('galleries\models\Image', ['id' => 'image_id']) ->viaTable('{{%companies_has_images}}', ['company_id' => 'id']); } public function extraFields() { return ['images']; } now an Image model: /** * @return...

Yii2 Restful API : display the data from database into JSON format with specific condition SQL

json,api,rest,yii2
I'm working on Yii2 restful API and want to display the data into JSON format. This is my structure database: TABLE `volunteer`( `volunteer_id` int(11) NOT NULL auto_increment, `state_id` int(11) null `nama` varchar(200) null TABLE `state`( `state_id` int(11) NOT NULL auto_increment, `state` varchar(225) null Basically, when I run at browser with...

Yii2, what the model parameter does in widget?

yii2,yii-widgets
echo Select2::widget([ 'model' => $vendorModel, 'attribute' => 'id', 'data' => $vendor, 'options' => ['placeholder' => 'Select a vendor ...'], 'pluginOptions' => [ 'allowClear' => true ], ]); The above Select2 widget (and most of widgets are same) require the Model attribute, but I don't know what the model does in...

Yii2 db; dsn with ip local

php,database,yii,yii2
i have my localhost configured with and other port, i'm trying to use this in the 'yii\db\Connection' 'dsn' => 'mysql:host=192.168.1.5;dbname=db_empresa_juridico', 'username' => 'db_user_jurid', 'password' => '[removed]', 'charset' => 'utf8', but Yii2 still loading, don't show nothing how i can connecting to the db? using local ip? i need to shared...

how to build Multiple File Upload in yii2 for the all types of files?

php,yii2
How to build a post model and controller with Multiple File Upload in yii2 with the all types of files when creating a new post that I can get a Post with slider?

Yii2 - mailer - send message to email rows in database

arrays,string,yii2,send,mailer
Greetings, i need to send email to several recipients that are stored in a table named mail which has a field called email. In my controller i created an action that Query the table mail for the emails. Later i tried to use the implode() function separated by comma, but...

How to get all ActiveRecord objects in Yii2?

php,yii,yii2
How can I get all ActiveRecord objects in Yii2 like an array, which can be iterated by foreach() . This is the code which should work but it returns zeros instead of actual data. public function getAllCategories(){ $categoriesList=[]; $categories= Category::find()->orderBy("id")->all(); foreach ($categories as $category){ $categoriesList[]+=$category->title; } return $categoriesList; } ...

Yii2 extending Gii CRUD with many-to-many form elements

php,many-to-many,yii2
I have the following 3 tables: Rule -id -name CombinedRule -id -name RuleCombineMapping -id_rule -id_combine I generated a CRUD for Rule and for the CombinedRule table. Inside the CombinedRule model class I created a mapping the class looks like the following: <?php namespace app\models; use Yii; /** * This is...

Add comment to SQL table

migration,yii2
How can I add comment for specific SQL-table in Yii2 migration? SQL code: ALTER TABLE my_table COMMENT 'Hello World' I wand to do in within a migration in ORM way...

Handling Guests in Yii2 to prevent constant checks

php,yii,yii2,yii2-user
I'm wondering what is generally the recommended way to handle guests in Yii2. Like, for example when you have a logged in user you can simply get their details via a call such as: $user = Yii::$app->user->identity; Then you can do stuff like the below, depending on what details you...