Submitted by gouki on 2011, September 4, 9:33 PM
如果到facebook上关注一下yii framework的群组,会发现有人在介绍yiicookbook.org,里面是一本关于1.1的书。
然后去yii framework官方上搜索一下phpstorm,会发现同一个人在说自己用phpstorm,问phpstorm有没有什么支持。结果官网说暂时好象不支持。。。
然后再搜索了一下,发现在yii的官网有一个简单的例子在说如何让项目支持yii framework。看了一下,发现,大多数都用过,只有第一点,说是把yiilite.php过滤掉。这个其实很重要了,否则有些变量就会出现提示两次。
OK,来看官网的wiki吧:http://www.yiiframework.com/wiki/92/configuring-phpstorm-ide-for-yii
Code completion
- Exclude yiilite.php from index:
- File → Settings → IDE Settings → File Types.
- yiilite.php to Ignore files and folders.
- Exclude not used directories, specify resources.
- File → Settings → Project settings → Directories.
- Mark framework/cli/views, protected/runtime and assets as excluded.
- Mark website root as resource root.
- Specify path to your PHP.
- File → Settings → Project settings → PHP → PHP Home.
- If your project uses common Yii framework folder you need to include it.
- File → Settings → Project settings → PHP → PHP Home → Add.
- Specify a path to framework directory.
- If you are writing unit tests you can include PHPUnit to get code completion:
- File → Settings → Project settings → PHP → PHP Home → Add.
- Specify a path to PHPUnit.
- Complete code: Ctrl+Space.
- Show method arguments: Ctrl+Q.
Testing
You should install PHPUnit to run unit tests.
- PHPUnit.
- Follow official PHPUnit installation guide.
- In your IDE: Run → Edit configurations.
- Press "+".
- Name: anything.
- Test: depending on what do you want to test select an appropriate option. Specify path.
- Use XML configuration file: specifying path to phpunit.xml. Often it's path_to_your_webroot/protected/tests/phpunit.xml.
- To run tests use SHIFT+F10.
OK,现在这样就可以简单的支持yii framework了。只是phpstorm还是有点小问题,因为提示的时候不会显示phpdoc的信息。纠结,啥时候会有doc的提示呢?
Tags: phpstorm, yii, facebook
Software | 评论:0
| 阅读:23835
Submitted by gouki on 2011, August 17, 12:44 AM
YII是一个PHP框架。
ZendFramework也是一个PHP框架
在Yii里配置ZF框架,刷刷的就一个RSS阅读器就出来了。
代码很简单,把Zend整合COPY到protected/extensions目录下
在控制器的init方法里加入:
Yii::import("ext.*");
require_once("Zend_Feed_Reader.php");
然后在需要的方法里加入
$feed = Zend_Feed_Reader::import("http://neatstudio.com/rss.php");
这样就创建了一个读的对象了。然后。。。。。
你懂的:
PHP代码
- $data = array(
- 'title' => $feed->getTitle(),
- 'link' => $feed->getLink(),
- 'dateModified' => $feed->getDateModified(),
- 'description' => $feed->getDescription(),
- 'language' => $feed->getLanguage(),
- 'entries' => array(),
- );
-
- foreach ($feed as $entry) {
- $edata = array(
- 'title' => $entry->getTitle(),
- 'description' => $entry->getDescription(),
- 'dateModified' => $entry->getDateModified(),
- 'authors' => $entry->getAuthors(),
- 'link' => $entry->getLink(),
- 'content' => $entry->getContent()
- );
- $data['entries'][] = $edata;
- }
- print_r($data);
就这样,一个刚刚的RSS阅读器就出来了。
当然,它没有缓存,没有这没有那的,不过,都解析完了,剩下的功能还会远吗?
Tags: yii, zend
PHP | 评论:0
| 阅读:18196
Submitted by gouki on 2011, August 8, 10:20 PM
在项目中遇到文件上传的问题,这时候需要用到CFileValidator,但是官方的验证中少了一点点的处理,比如,对于图片,我只想上传尺寸正好是300x500的图片。怎么办?
所以我做了一点小小的扩展,于是我在rules里面加了这么两条:
PHP代码
- array('picname', 'application.validators.Myfile', 'on'=>'insert','types'=>'jpg,png','wrongType'=>'只允许上传jpg或者PNG','maxSize' => 1024*300,'tooLarge' => '图片最大只支持300K','imageSize'=>'768x1024','wrongImageSize'=>'对不起,图片尺寸只支持768*1024'),
- array('picname', 'application.validators.Myfile', 'on'=>'update','types'=>'jpg,png','wrongType'=>'只允许上传jpg或者PNG','maxSize' => 1024*300,'tooLarge' => '图片最大只支持300K','imageSize'=>'768x1024','wrongImageSize'=>'对不起,图片尺寸只支持768*1024','allowEmpty'=>true,),
数组的第二个字段就是一个全路径,告诉rules,对于picname用的是application.validators.Myfile类。这个类其实很简单,只是简单的扩展了官方的CFileValidator类,大致如下:
PHP代码
- class Myfile extends CFileValidator{
- public $imageSize;
- public $wrongImageSize;
-
-
-
-
-
-
-
- protected function validateFile($object, $attribute, $file){
- parent::validateFile($object,$attribute,$file);
- if($this->imageSize!=''&&strpos($this->imageSize,"x")!==false){
- list($width,$height) = @getimagesize($file->getTempName());
- $imageSize = sprintf("%sx%s",$width,$height);
- if($imageSize != $this->imageSize){
- $message=$this->wrongImageSize!==null?$this->wrongImageSize : Yii::t('yii','The file "{file}" cannot be uploaded. Only files with these size are allowed: {imagesize}.');
- $this->addError($object,$attribute,$message,array('{file}'=>$file->getName(), '{extensions}'=>$this->imageSize));
- }
- }
- }
- }
我这种只是简单的判断是否与指定尺寸相符,如果需要检测小于指定范围的图片,那就需要多一点的判断了,也不会太难啦。主要是一个思路(感谢烂桔提供思路)
Tags: yii
PHP | 评论:0
| 阅读:16657
Submitted by gouki on 2011, June 29, 3:24 PM
Yii:
XML/HTML代码
- Yii is a high-performance PHP framework best for developing Web 2.0 applications.
-
- Yii comes with rich features: MVC, DAO/ActiveRecord, I18N/L10N, caching, authentication and role-based access control, scaffolding, testing, etc. It can reduce your development time significantly.
PHPRPC:
XML/HTML代码
- PHPRPC 是一个轻型的、安全的、跨网际的、跨语言的、跨平台的、跨环境的、跨域的、支持复杂对象传输的、支持引用参数传递的、支持内容输出重定向的、支持分级错误处理的、支持会话的、面向服务的高性能远程过程调用协议。
-
- 目前该协议的最新版本为 3.0。该版本目前已有以下几种语言的实现:
-
- ASP,ActionScript,Delphi/C++Builder/Kylix,Java,JavaScript,NET,PHP,Python,Ruby,Perl,Lazarus(Free Pascal)
-
- 其中 ASP、.NET、Java、Ruby、Python 和 PHP 版本除了提供客户端实现外,还提供了服务器端实现。
HPROSE:
XML/HTML代码
- Hprose (High Performance Remote Object Service Engine) 是一个商业开源的新型轻量级跨语言跨平台的面向对象的高性能远程动态通讯中间件。它支持众多语言,例如 C++, .NET, Java, Delphi, Objective-C, ActionScript, JavaScript, ASP, PHP, Python, Ruby, Perl 等语言,通过 Hprose 可以在这些语言之间实现方便且高效的互通。
-
- Hprose 易学易用,且功能强大,您只需很短时间的学习,就可以用它方便地构建出跨语言跨平台分布式的电信级应用系统。
如何在Yii中使用Hprose或者PHPRPC呢?我这里简单介绍一下Yii下hprose的应用方法
1、下载hprose的PHP版本,嗯,别看了,是混淆过的,但不影响你使用。
2、将下载后的hprose拷贝到yii项目的/protected/extension/hprose目录下
3、新建一个apicontroller:
我这样的方式是最简单的,将一些actionIndex的方法都公开了,在实际应用中当然不可以这样。不过我这里是测试,当然是无所谓的
访问http://localhost/project/test/ (project是我的项目名称,test是controller, index是action,由于默认action是index,所以我省略了)
浏览器中返回了:
XML/HTML代码
- Fa4{s11"actionIndex"s11"afterAction"s5"hello"s3"sum"}z
由此其实我们也可以基本确认有四个方法可以使用actionIndex,afterAction,hello,sum,这主要是因为我把当前类当成发布对象了。(不主张啊不主张)
4、继续下一步,
PHP代码
- <?php
- include("./protected/extensions/hprose/hproseHttpClient.php");
- $client = new HproseHttpClient("http://localhost/project/test");
- $result = $client->sum(1,2,3,4,5);
- print_r($result);
OK,浏览器输出了15,就这样完成了一个简单的HPROSE应用。
当然我这样的方式太简单了,文档在这里有下载,我就不再画蛇添足的提供了:http://www.hprose.com/documents.php。
因为只是简单的的一些应用,暂时也看不到hprose的性能比phprpc提升了多少。
---------------备注
由于Yii对于大小写敏感,因此在new HproseHttpServer();的时候,Hprose的H不能大写,否则,它会自动寻找HproseHttpServer.php,但由于PHP的hprose的文件中首字母都是小写。因此在new的时候就需要:new hproseHttpServer();
Tags: yii, hprose, phprpc
PHP | 评论:0
| 阅读:28177
Submitted by gouki on 2011, May 26, 6:02 PM
笔记。。。
Yii的cache大家用起来可能是比较爽,直接Yii::app()->cache->get,就over了。在这个时候,我们可以配置相应的cache方式,比如数据库,memcache,apc,eacc.....(太长,记不住),等等。但是,怎么样能够让memcache缓存与文本缓存或其他缓存共用呢?
所以,不要纠结于普通的想法。嗯,在main.php的cache数组元素下,建一个同级数组。如:
'fc' => array(
'class' => 'CFileCache',
'directoryLevel'=>1,
),
然后在项目中就可以直接Yii::app()->fc->get,或者Set了。是不是很方便 ?
Tags: yii, memcache, filecache, apc
PHP | 评论:1
| 阅读:20108