Yii

Set session in Yii framework

蹲街弑〆低调 提交于 2019-12-31 02:15:27
问题 I am developing a website with Yii. I have a button in the page. I need to set a session variable when user clicks it and get the session value when user clicks on another button. How can I do that? 回答1: Use CWebUser state methods //set session variable Yii::app()->user->setState("state_name", "value"); //check session variables Yii::app()->user->hasState("state_name"); //get session variable Yii::app()->user->getState("state_name"); //delete session variable (thanks @Kailas) Yii::app()->user

keep getting upload php $_FILES error = 3 (partially uploaded)

我与影子孤独终老i 提交于 2019-12-31 00:45:23
问题 I am using dropzone extension for Yii framework to upload some files by registered users. Everything working well but some users for some files that they trying to upload it's return error = 3 which it's happens when the uploaded file was only partially uploaded. $file_error = $_FILES['Project']['error']['file']; if ($file_error != 0) { mail('myemail@gmail.com', 'fileError',json_encode($_FILES['Project'])); } i'am receiving a lot of emails from this function JSON received {"name":{"file":"3

关于Yii中CGridView关联表字段的filter问题解决方法

筅森魡賤 提交于 2019-12-30 22:29:55
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 当你想用CGridView控件来生成一个Grid表格的时候,是非常方便的,你只需要简单的指定几个属性就可以了,比如: $this->widget('zii.widgets.CGridView', array( 'id'=>'order-grid-view', 'dataProvider'=>$model->search(), 'filter'=>$model, 'columns'=>array( 'id', 'customer_cd' ), ) 问题是,当你需要多多表进行查询的时候,filter就需要多作一点工作了,很遗憾,我没有找到Yii官方对此问题的简易方法,所以,只能靠迂回的方式了。 首先,让关联表字段显示在Grid表格里面很容易,你可以在dataProvider属性加上关联表,然后columns属性里直接加上要显示的关联表属性就可以,比如,修改后的dataProvider为 'dataProvider'=>$model->with('relationNameToOtherTable')->search(), 修改后的columns属性为: 'columns'=>array( 'id', 'customer_cd', 'customer_nm'=>array( 'name'=>

Yii 多表关联relations

六月ゝ 毕业季﹏ 提交于 2019-12-30 22:27:38
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1,首先多表关联是在models/xx.php的relations里配置的。而且是互配,但有区别。 格式: 'VarName'=>array('RelationType', 'ClassName', 'ForeignKey', ...additional options) 需要弄清楚的几点: 1,VarName指什么? 详见下面例2。 2,RelationType。一共有4种,分别为self::HAS_MANY, self::BELONGS_TO, self::MANY_MANY, self::HAS_ONE。 3,ClassName。即关联的另一个../model/类名.php。 4,ForeignKey。谁是谁的外键?写了是用主键关联,为空两个表不是用主键关联需要on 5,附加条件 两个表不是用主键关联 'user' => array(self::BELONGS_TO, 'OaskUser', '' ,'on'=>'name=userName' , 'select'=>'TrueName'),'varchar'=>array(self::HAS_ONE, 'CustomerEntityVarchar', 'entity_id','select'=>'varchar.value','on'=>'varchar

yii2 in 集合查询排序失效解决方法

强颜欢笑 提交于 2019-12-30 22:10:14
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> yii2 in 集合查询排序失效解决方法 $resData = (new \yii\db\Query()) ->select('*') ->from('product') ->where(['id' => $productIdsArray]) ->all(); //查出的结果是升序排列的要想实现指定数组内的排序顺序可以使用下面的方法 $productIds = implode(',' , $productIdsArray); $orderBy = (new \yii\db\Query()) ->select('*') ->from('product') ->where(['id' => $productIdsArray]) ->orderBy([new \yii\db\Expression("FIELD (id, $productIds)")]) ->all(); 来源: oschina 链接: https://my.oschina.net/hongjiang/blog/3151124

yii2 数据库查询结果字段类型的问题

泄露秘密 提交于 2019-12-30 16:03:06
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> yii2 数据库查询默认返回的为 AR 对象,此时字段类型与数据库的基本相符,但如果使用 asArray 以数组的方式返回时,默认字段类型全都是 string ,如果这样 json_encode 后返回给 App 端的话,会被 Android/IOS 这些强类型语言端的工程师们喷死, php 会再次被推向风口。 原因是 pdo 在 yii2 盛行时还不够完善,一些特性是后期加进来的,比如我们急切需要的返回的结果数据类型与数据库一致。 <?php return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii2basic', 'username' => 'root', 'password' => '123456', 'charset' => 'utf8', 'tablePrefix' => 'yii_', 'attributes' => [ PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false, ] // Schema cache options (for production environment) //

php和redis怎么实现消息队列

本秂侑毒 提交于 2019-12-30 13:48:31
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 把瞬间服务器的请求处理换成异步处理,缓解服务器的压力,实现数据顺序排列获取。本文主要和大家分享php和redis如何实现消息队列,希望能帮助到大家。 redis实现消息队列步骤如下: 1).redis函数rpush,lpop 2).建议定时任务入队列 3)创建定时任务出队列 文件:demo.php插入数据到redis队列 <?php $redis = new Redis(); $redis->connect('127.0.0.1',6379); $password = '123456'; $redis->auth($password); $arr = array('h','e','l','l','o','w','o','r','l','d'); foreach($arr as $k=>$v){ $redis->rpush("mylist",$v); } 文件:index.php定时扫描出队列 <?php $redis = new Redis(); $redis->connect('127.0.0.1',6379); $password = '123456'; $redis->auth($password); //list类型出队操作 $value = $redis->lpop('mylist'); if(

How to detect the last insert ID within a transaction in Yii using DAO?

五迷三道 提交于 2019-12-30 08:20:09
问题 That's the source code, I need to detect the ID (see the marked position between the two queries below). $connection = Yii::app()->db; $transaction=$connection->beginTransaction(); try { $q = "INSERT INTO `someTable1` .... "; $connection->createCommand($q)->execute(); // Single Row Inserted // HERE!! How to get the last insert ID from query above $q = "INSERT INTO `someTable2` .... WHERE id = LAST_INSERT_ID_FROM_FIRST_QUERY "; $connection->createCommand($q)->execute(); $transaction->commit();

php.exe is not recognized:create webapp

允我心安 提交于 2019-12-30 08:19:07
问题 I am toying with my new install of yii framework, and trying to compile my first webapp through the command line. when I run yiic webapp ../testdrive i receive this error in my console: "php.exe" is not recognized as an internal or external command, operable program or batch file Do I need to edit my php.ini file? I am currently running on WAMP Webserver on Windows 7 回答1: You need to add complete path in your php.exe in `yii\framework\yiic.bat for example in my case it is if "%PHP_COMMAND%" =

Use limit range in yii2?

早过忘川 提交于 2019-12-30 06:09:11
问题 I want to get data from db using limit 12,20 . Here is my code: $Query = new Query; $Query->select(['um.id as USERid', 'um.first_name', 'um.last_name', 'um.email', 'COUNT(g.id) as guestCount']) ->from('user_master um') ->join('LEFT JOIN', 'guest g', 'g.user_id = um.id') ->limit(12,20) ->groupBy('um.id') ->orderBy(['um.id' => SORT_DESC]); $command = $Query->createCommand(); $evevtsUserDetail = $command->queryAll(); It is not working. It is giving me all rows. I also tried ->limit([12,20]) ,