Yii

yii criteria condition between date

痞子三分冷 提交于 2019-12-18 09:42:37
问题 I'm trying to find time overlaps of a specific user, I think my logic would catch all over laps, but this catches only if start OR end is in between a time frame but nothing is found if both are start and end are in between some records time period! $tempModel = clone $this; // clone model $criteria->addCondition(' ( t.user = :user AND (t.startDate >= :start AND t.startDate <= :end )) OR ( t.user = :user AND (t.endDate >= :start AND t.endDate <= :end )) '); $criteria->params = array( ':start'

Hybrid auth with Yii causing a redirect loop

 ̄綄美尐妖づ 提交于 2019-12-18 08:55:21
问题 I am trying to implement twitter sign in on my website using hybridauth. I know there is a hybrid auth plugin for Yii. I am not using it because last time I used I ran into some problems. I am trying to implement the core version of hybrid auth. I am calling $hybridauth = new Hybrid_Auth( Yii::app()->params['hybridauth'] ); $adapter = $hybridauth->authenticate( 'Twitter'); But for some reason it redirects to http://localhost/yiiauth/authtest/?hauth.start=Twitter&hauth.time=1350973441 , which

What does a colon before a literal in an SQL statement mean?

与世无争的帅哥 提交于 2019-12-18 05:55:59
问题 What does it mean to use " : " before a variable ? For example, :userId in this code: public function removeUser($userId) { $command = Yii::app()->db->createCommand(); $command->delete( 'tbl_project_user_assignment', 'user_id=:userId AND project_id=:projectId', array(':userId'=>$userId,':projectId'=>$this->id)); } This is PHP,MySQL code in Yii framework. 回答1: The colon is a common character that indicates a placeholder for a variable value in a SQL statement. In this case, the those

How to validate email and email already exist or not check, in Yii Framework?

风格不统一 提交于 2019-12-18 05:37:36
问题 How to validate email using Yii Model validation rules function code. Also how to check email exist or not using Model validation rules function in Yii. 回答1: You can set your model validations as below public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( //First parameter is your field name of table which has email value array('email', 'email','message'=>"The email isn't correct"), array('email', 'unique','message

yii 表单小部件

筅森魡賤 提交于 2019-12-18 05:21:03
文本框 < span class = "hljs-selector-pseudo" > : textInput ( ) < / span > ; 密码框 < span class = "hljs-selector-pseudo" > : passwordInput ( ) < / span > ; 单选框 < span class = "hljs-selector-pseudo" > : radio ( ) < / span > , < span class = "hljs-selector-tag" > radioList < / span > ( ) ; 复选框 < span class = "hljs-selector-pseudo" > : checkbox ( ) < / span > , < span class = "hljs-selector-tag" > checkboxList < / span > ( ) ; 下拉框 < span class = "hljs-selector-pseudo" > : dropDownList ( ) < / span > ; 隐藏域 < span class = "hljs-selector-pseudo" > : hiddenInput ( ) < / span > ; 文本域 < span class = "hljs

Yii2 ActiveRecord cache

 ̄綄美尐妖づ 提交于 2019-12-18 04:22:40
问题 How to use ActiveRecotd cache for Yii 2? I did't find any examples in official docs. In Google I found 2 examples, first is: $db = self::getDb(); $object = $db->cache(function ($db) use($id) { return self::findOne($id); }); But it doesn't work for Model , I tested with updated framework. Other example is: $data = \Yii::$app->cache->get('some_var_' . $id); if ($data === false) { $data = self::findOne($id); \Yii::$app->cache->set('some_var_' . $id, $data, 60); } It's working fine, but it's not

multi model forms in yii

倾然丶 夕夏残阳落幕 提交于 2019-12-17 22:34:31
问题 How to create a multi-model form in Yii? I searched the entire documentation of Yii, but got no interesting results. Can some one give me some direction or thoughts about that? Any help will be appreciable. 回答1: In my expirience i got this solution to work and quickly understandable You have two models for data you wish collect. Let's say Person and Vehicle . Step 1 : Set up controller for entering form In your controller create model objects: public function actionCreate() { $Person = new

Yii2 How to perform where AND or OR condition grouping?

喜欢而已 提交于 2019-12-17 22:18:37
问题 I am new to Yii-2 framework. How can i achieve following query in Yii-2 framework using activeQuery and models. SELECT * FROM users AS u WHERE u.user_id IN(1,5,8) AND (u.status = 1 OR u.verified = 1) OR (u.social_account = 1 AND u.enable_social = 1) Thanks 回答1: You can try this: //SELECT * FROM users AS u WHERE u.user_id IN(1,5,8) AND (u.status = 1 OR u.verified = 1) OR (u.social_account = 1 AND u.enable_social = 1) $model = arname()->find() ->andWhere(['user_id'=>[1,5,8]]) ->andWhere(['or',

Yii - Hiding module name in URL

百般思念 提交于 2019-12-17 21:13:59
问题 My present URL structure is as below: http://www.mydomain.com/module/controller/action I need to hide the module section of the URL. Is there any way this can be done? Thanks. 回答1: To point the URL http://www.mydomain.com/customer/login to the module, in you config (protected/config/main.php) under urlManager : 'urlManager'=>array( 'urlFormat'=>'path', 'showScriptName' => false, 'rules'=>array( 'customer/login' => 'module/controller/action', '<controller:\w+>/<id:\d+>'=>'<controller>/view', '

Yii - echo the last query

不羁的心 提交于 2019-12-17 20:14:16
问题 I have used Codeigniter before and it has a feature that will echo the last database query - really useful for debugging. eg... $this->getSomeData->findAll(); Yii command to output this single query e.g SELECT * FROM TABLE... Does Yii have a similar feature to simply show the very last query executed? 回答1: Try this in your config file. You can see the query and other details at the bottom of the page. 'db'=>array( 'enableProfiling'=>true, 'enableParamLogging' => true, ), 'log'=>array( 'class'