手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2013年01月23日的文章

yii with的排序

Yii在自己的AR中实现了relations,于是我们可以利用relations实现一些left join或者其他join能做的事情,常见的大家都懂,什么 belongs_to,has_one,has_many,many_to_many之类的
但用的最多的,一般都是has_one,has_many,毕竟查关联数据这个最方便了。

于是我们就会Table::model()->with('a','b')->findAll($cdbcriteria);
这个时候,如果需要用到a或b的排序,就有点痛苦,直接在$cdbcriteria中写的话,往往会报字段不存在,因此可以尝试这样
1、直接在relations中,在写成a时,直接加入'order'=>'id DESC'之类的内容
2、在with()中写: with(array('a'=>array('order'=>'id DESC'),'b'))

这样是不是就很方便了呢?
当然上面的代码是通过:

PHP代码
  1. public function with()  
  2. {  
  3.     if(func_num_args()>0)  
  4.     {  
  5.         $with=func_get_args();  
  6.         if(is_array($with[0]))  // the parameter is given as an array  
  7.             $with=$with[0];  
  8.         if(!empty($with))  
  9.             $this->getDbCriteria()->mergeWith(array('with'=>$with));  
  10.     }  
  11.     return $this;  
  12. }  

看了这段代码就基本上了解用法了,手册里也说了:
Specifies which related objects should be eagerly loaded. This method takes variable number of parameters. Each parameter specifies the name of a relation or child-relation. For example,

// find all posts together with their author and comments
Post::model()->with('author','comments')->findAll();
// find all posts together with their author and the author's profile
Post::model()->with('author','author.profile')->findAll();
The relations should be declared in relations().

By default, the options specified in relations() will be used to do relational query. In order to customize the options on the fly, we should pass an array parameter to the with() method. The array keys are relation names, and the array values are the corresponding query options. For example,
Post::model()->with(array(
    'author'=>array('select'=>'id, name'),
    'comments'=>array('condition'=>'approved=1', 'order'=>'create_time'),
))->findAll();
所以,有时候看看手册还是很重要的。

Tags: yii, with, cdbcriteria

关于github的DNS被污染的临时解决方法

这两天校长发标了,所以github就不能看了。
好吧,我只是在上面开了两个小项目:yii_extensions和yii_rest_test。
我自己的项目没有人访问没关系,象astaxie就要哭了。
当然,其实我也在哭,我用的phpredis就无法下载了。所幸,大家都是很牛叉的,比如下面这几行:

207.97.227.239 github.com
65.74.177.129 www.github.com
207.97.227.252 nodeload.github.com
207.97.227.243 raw.github.com
204.232.175.78 documentcloud.github.com
204.232.175.78 pages.github.com

至于是什么 意思,怎么改,我就不说了。如果你连这也不会,那也不用多说了。

从python官网,到sf.net到code.google.com再到github.com,我没有为他做过什么,当然我也没有资格说什么,我这样的小人物只能忍忍了。
我没能力呼吁,对了,我呼吁了也没啥用,你嚼得呢?

Tags: github

博客没有更新,那是有原因的

这两天博客没有更新,嗯,确实 有点点的原因。
我在抽空写脚本导到typecho,虽然之前有用过typecho,但已经忘了是怎么搞的了。
在导入的过程中,也额外写了点插件。比如说:
1、slug-》将标题转为拼音
2、内容 markdown 化。因为现在发现各种HTML版式反而搞乱了我的内容,还不如直接用markdown来处理呢。。

现在的问题是在附件上,typecho的附件与内容是在同一个表里,而sablog不是。所以在这上面会略花点时间 ,不过也快了。黑黑。而且我还想保留原来sablog的那种 [ attach=13 ]的类似格式,就更慢了一点。
每天中午写上半小时,所以就更慢了一些些了。。
sablog功能虽然够了,但毕竟不方便扩展,而且我用typecho的话,我还得额外写个小插件,则让多种routes并存(或者写成rewrite规则)。
快了。快了。年前一定能够出来了。黑黑