Yii

Using terminal, how do I make OS X use MAMPs version of PHP

一个人想着一个人 提交于 2020-01-11 04:16:25
问题 I'm currently learning the Yii framework, and one of the tutorials I was running through yesterday required me to test the database connection of a project. The details aren't too important here, but basically when I run shell, and type in the command it throws up an error as follows: server:trackstar charlieryan$ protected/yiic shell Yii Interactive Tool v1.1 (based on Yii v1.1.13) Please type 'help' for help. Type 'exit' to quit. echo Yii::app()->db->connectionString; PHP Warning: PDO::_

Filter setup for related model in GridView

流过昼夜 提交于 2020-01-10 20:10:54
问题 I am trying to setup the filter for related model in Yii2's GridView widget, but I am keep getting the error like the filter value must be an integer. I have followed this question. Now, I have a two models Services.php and ServiceCharge.php . In ServiceCharge.php the relation is setup like: public function getServiceName() { return $this->hasOne(Services::className(),['id'=>'service_name']); } In the ServiceChargeSearch.php the code is like this: <?php namespace app\models; use Yii; use yii

Filter setup for related model in GridView

一曲冷凌霜 提交于 2020-01-10 20:09:50
问题 I am trying to setup the filter for related model in Yii2's GridView widget, but I am keep getting the error like the filter value must be an integer. I have followed this question. Now, I have a two models Services.php and ServiceCharge.php . In ServiceCharge.php the relation is setup like: public function getServiceName() { return $this->hasOne(Services::className(),['id'=>'service_name']); } In the ServiceChargeSearch.php the code is like this: <?php namespace app\models; use Yii; use yii

Retain Checkbox values in Yii gridview pagination

随声附和 提交于 2020-01-10 10:15:33
问题 I have a gridview which contains a checkbox column and also uses pagination. When I check some checkboxes in the first page and navigate to the second page and check another one in the second page, the options I checked in the first page is not retained there. Is it posssible to retain the checkbox values during pagination? Code for Gridview is $widget = $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider' => $model->search(), 'cssFile' => Yii::app()->baseUrl . '/media/js/admin

Retain Checkbox values in Yii gridview pagination

我的梦境 提交于 2020-01-10 10:15:32
问题 I have a gridview which contains a checkbox column and also uses pagination. When I check some checkboxes in the first page and navigate to the second page and check another one in the second page, the options I checked in the first page is not retained there. Is it posssible to retain the checkbox values during pagination? Code for Gridview is $widget = $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider' => $model->search(), 'cssFile' => Yii::app()->baseUrl . '/media/js/admin

Hide GET parameter from URL

橙三吉。 提交于 2020-01-10 05:13:11
问题 How to hide URL GET parameters (http://domain.com/MyFirstYii/page?view=about). I've searched lot of posts. They all are saying about rewrite and URL manager, but i couldn't achieve what i want. :( My scenario is, I just want to hide the URL GET parameters. Eg: http://domain.com/MyFirstYii/page***?view=about*** I wanted to hide ***?view=about*** . Then URL should look like this http://domain.com/MyFirstYii/page . Other pages like this http://domain.com/MyFirstYii/post . In a simple words my

Yii2 使用Curl

徘徊边缘 提交于 2020-01-08 04:09:28
composer安装curl 命令行切入到你的项目目录执行 composer require --prefer-dist linslin/yii2-curl "*" 等待安装即可 安装完之后curl的位置 项目根目录/vendor/linslin 有linslin就是安装成功了 Yii2 使用Curl 1 <?php 2 namespace server\api; 3 4 use yii; 5 use yii\helpers\Json; 6 use linslin\yii2\curl\Curl; 7 use server\utils\Jwt; 8 /** 9 * API基础类 10 */ 11 class BaseApi 12 { 13 const API_POST = 'POST';//POST 请求 14 const API_GET = 'GET';//GET 请求 15 const API_HEAD = 'HEAD';// HEAD 请求 16 const API_PUT = 'PUT';// PUT 请求 17 const API_DELETE = 'DELETE'; // DELETE 请求 18 19 20 /** 21 * 调用脚本接口 22 * @param $url 请求地址 23 * @param $params 接口参数 24 * @param $type

创建websocket服务器

故事扮演 提交于 2020-01-07 16:35:34
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> swoole从1.7.9版本开始, 内置了websocket服务器功能,我们只需几行简单的PHP代码,就可以创建出一个异步非阻塞多进程的WebSocket服务器。 首先,我们在apache的工作空间下,新建一个项目,名称为swoole,然后在里面新建一个ws-server.php文件,该php文件主要创建一个websocket服务器,同时相应用户的请求,内容如下: <?php //创建websocket服务器对象,监听0.0.0.0:9502端口 $ws_server = new swoole_websocket_server('192.168.1.169', 9502); //设置server运行时的各项参数 $ws_server->set(array( 'daemonize' => true, //是否作为守护进程 )); //监听WebSocket连接打开事件 $ws_server->on('open', function ($ws, $request) { file_put_contents( __DIR__ .'/log.txt' , $request->fd); //$ws->push($request->fd, "Hello, Welcome\n"); }); //监听WebSocket消息事件

yii2表单提交CSRF验证

对着背影说爱祢 提交于 2020-01-07 15:49:43
Yii2表单提交默认需要验证CSRF,如果CSRF验证不通过,则表单提交失败,解决方法如下: 第一种解决办法是关闭Csrf public $enableCsrfValidation = false; 第二种解决办法是在form表单中加入隐藏域(如果是高级版的name值分前后台区分) <input type="text" name="_csrf-frontend" value="<?= Yii::$app->request->csrfToken ?>" />(前台实例) 第三种解决办法是在AJAX中加入_csrf字段 var csrfToken = $('meta[name="csrf-token"]').attr("content"); $.ajax({ type: 'POST', url: url, data: {_csrf:csrfToken}, success: success, dataType: dataType }); Yii2表单提交默认需要验证CSRF,如果CSRF验证不通过,则表单提交失败,解决方法如下: 第一种解决办法是关闭Csrf public $enableCsrfValidation = false; 第二种解决办法是在form表单中加入隐藏域(如果是高级版的name值分前后台区分) <input type="text" name="_csrf

Yii 1.x imperavi redactor execCommand('strikethrough') not working

一笑奈何 提交于 2020-01-07 06:54:05
问题 After Chrome 58 update few features like Bold, Italic & Underline stopped working. On debugging i found that execCommand('strikethrough') is not striking the selected text. formatMultiple: function(tag) { this.inline.formatConvert(tag); this.selection.save(); document.execCommand('strikethrough'); //HERE, IT IS NOT STRIKING THE TEXT this.$editor.find('strike').each($.proxy(function(i,s) { var $el = $(s); this.inline.formatRemoveSameChildren($el, tag); var $span; if (this.inline.type) { $span