yii2

How to get count of items which are created today in yii2?

杀马特。学长 韩版系。学妹 提交于 2019-12-13 03:14:29
问题 Sample data in my collection : created_at : 2018-04-29 05:25:28.000Z I'm using TimestampBehavior , 'timestamp' => [ 'class' => TimestampBehavior::className(), 'attributes' => [ ActiveRecord::EVENT_BEFORE_INSERT => 'created_at', ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at', ], 'value' => function() { $now = new \DateTime('NOW'); return new \MongoDB\BSON\UTCDateTime(strtotime($now->format("Y-m-d H:i:s"))*1000); }, ], This is my count function : public function count_users () { $cnt = Users

Search in Related Model using GridView Filter Field

你说的曾经没有我的故事 提交于 2019-12-13 02:48:43
问题 Question: Let's Say i have two tables, Table1 Table2 -authorId -username As of now my sql query on search model looks like this, ->andFilterWhere(['"Table1"."authorId"' => $this->authorName]); It only helps to search and filter using the authorID. Expected Result I would like to search based on the authorname instead of authorId. I faced similar difficulty in reflecting data in view but i was able to fix it with following getter function in base model. public function getAuthorName() { return

Namespace with alias on Yii2 different from directory structure

孤街浪徒 提交于 2019-12-13 02:36:09
问题 I made a bunch of classes and put them inside the directory common/a/b/c . So, inside file Class1.class.php I have: <?php namespace x\y\b\c; class Class1 ... Namespace is different from the directory structure organization, because I wanted that way. ( x\y should map to common/a directory) On my common/config/bootstrap.php I tried this: Yii::setAlias('common', dirname(__DIR__)); Yii::setAlias('x/y', '@common/a'); And tried importing this class in another file using use x\y\b\c\Class1; With no

Main Search Form in Yii2

主宰稳场 提交于 2019-12-13 02:19:09
问题 I'm really new in Yii2 and I still don't know how to configure it properly. I noticed that the GridView has search fields on each column. What I need now is to create a main/single search field wherein a user can input keywords then results will show in the GridView after hitting the search button. Is this possible? I also used this Kartik widget in my search form field which has a dropdown list in it. Image here. We're told to use this dropdown search and when the user inputs some keywords

Yii2 client side validation for dynamically added multiple inputs

烂漫一生 提交于 2019-12-13 02:11:00
问题 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 ? 回答1: After adding dynamic input using jQuery use below code to validate jQuery('#form-id').yiiActiveForm("add", { "id": "input-id", "name": "input-name", "container": "#container-id or unique .container-class of this input", "input": "#input-id or unique .input-class", "validate": function (attribute, value, messages, deferred

Yii2 join 6 tables + dropdown filter in grid

帅比萌擦擦* 提交于 2019-12-13 02:07:29
问题 I have the following tables/models: A, B, C, BC, D, BCD (A:B 1:N) Connecting table D to BCD would be no problem. However I would like to filter key attributes as dropdown from A, B, C and D to find results in BCD (because in the end I need BCDid). In BCD next to BCid and Did I can store of course Aid, Bid and Cid, and it would seem to me quite an easy workaround, however I know it's totally against db normalisation. Is there another, better way (with eager loading of course)? I've now this in

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

北慕城南 提交于 2019-12-13 01:33:21
问题 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 specific ID = 1 (http://localhost/KDMA/web/index.php/volunteers/1) the data will display like this: { "volunteer_id": "1", "state_id":"12", "nama":

Include additional library to yii2

China☆狼群 提交于 2019-12-13 01:25:36
问题 There is yii2 which instaled via composer. What specific steps should be taken to connect the additional library library to the current project. Also same question if need connect only simple class. 回答1: Composer found at https://getcomposer.org is your best friend while adding new libraries to yii2 framework. e.g. you would like to add kartik yii2 widgets found at http://demos.krajee.com/ to your yii2 application. for that you need to have php installed in your development machine and have

Yii2: custom validation for multiple attributes using OR not working

折月煮酒 提交于 2019-12-13 01:24:00
问题 I am trying to write a rule that validates if attribute_a or attribute_b is set; one of the following attributes must be set : licitatii_publice or licitatiile_atribuite The following code does not work; <?php namespace common\models; use yii\base\Model; class AbonamentValidare extends Model { public $licitatii_publice; public $licitatiile_atribuite; public $zone; public $judete; public $tari; public static $targetAttribute = []; public function rules() { return [ [['zone'], 'required'], [[

YII2 Redirect to backend after user registration from frontend

十年热恋 提交于 2019-12-13 00:48:22
问题 After installation of advance template in yii2, I got a user registration from at the frontend but I want it to redirect to backend after registration. How can that be done??? public function actionSignup() { $model = new SignupForm(); if ($model->load(Yii::$app->request->post())) { if ($user = $model->signup()) { if (Yii::$app->getUser()->login($user)) { return $this->goHome(); // I WANT TO CHANGE THIS TO REDIRECT TO LOCALHOST/MYAPP/BACKEND/WEB } } } return $this->render('signup', [ 'model'