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

Yii 笔记二

Yii的用户登录,如果不算上权限的话,恐怕真的是很简单的登录。
简单的判断,简单的处理一下就完事了。
但我今天还真的被简单的折腾了一下。
User登录,需要写几个地方
1、components目录下的UserIdentity.php中,需要加一个判断用户的方法,返回errorCode,当然没有错的话就返回0,这是常用ERROR_NONE
2、model目录下的loginForm,里面有简单的判断处理,如果登录成功,调用CWebUser中的login方法。起初的时候,我一直没找到Yii::app()->user是哪个类。。
3、由于Yii::app()->user->login方法的特殊性,因此,必须要在UserIdentity.php中设定好getId,getName,和states变量。当然最简单的就是判断是否取到用户数据,如果取到的话,直接$this->setPersistentStates($usermodel->getAttributes());如果没有id,name的变量,那么即使你登录了,还是会显示没有登录的。我就是在这里被折腾了好久。

over。。。

Tags: yii, 重构

初用Yii

Yii是在iorange的推荐下使用的,这两天我才刚刚在使用。做点笔记而己,没有其他

1、就象我在neatcn.com写的,创建项目非常简单,yii.bat这个命令就可以完成了。详细就在http://www.neatcn.com/show-57-1.shtml

2、项目目录中components中的文件,会在autoload中被引用,也只有这一个目录下的会被autoload,其他的都是有固定规范的。(不知道有没有理解错)

3、model目录下居然是tablemodel和form两种的集合,有点乱(官方的例子是这样的),不过想着form的validation也是用tablemodel来完成的,又能够理解这种做法,普通的tablemodel类继承cActiveRecord。

4、Controllers目录下是控制类,默认是SiteController,和其他框架默认是indexController有点不一样。继承自CController类。controller类中有一个layout的变量,可以设定layout。一般可以手工指定,如果同一个类里有不同的layout,估计还是要写个方法才行

5、Model的activeRecord返回的是对象,而不是象其他框架默认返回数组,因此取集合时要用getAttributes方法,当然,如果是只有一条数据,也可以直接$model->fieldname这样的方式来获取值 。

才学了这么一点,慢慢来吧。。重构路是漫长的。

Tags: yii, 重构

关于godaddy优惠的一点郁闷

众所周知,godaddy是国外最早支持支付宝的域名销售商,当然它是支持paypal的,而我正好paypal里还有不少的美金,因此我就想在godaddy上买点域名玩玩啥的。

当我选好域名后,发现付款选项里果然有paypal和支付宝。OK,于是我选择了一个优惠码,优惠比率比较高大约为40%,可是接下来让我郁闷我的事情发生了,在使用了优惠码后,paypal不能用了,支付宝也不能用了,只能使用信用卡。

所幸我的信用卡是双币的,买了个qqapi.com域名,也算是简单的投资吧。

至此,我现在手里关于api的域名就有了好几个,朋友说我成了api控了。

ucapi.com,tbapi.com,aliapi.cn,tbapi.cn,qqapi.com,大约就这么几个了。

其中ucapi.com是算正式运营着的。其他四个都是没有使用。

Tags: godaddy, 优惠, 支付宝, paypal, 信用卡

JS:截取文章一部分显示(无损html)

很多做站的朋友都会有一个问题,在显示摘要的时候,如果摘要前有很多图片,那么显示出来的页面是不太正常的。比如,摘要显示100个字符,可是如果前面有很多图片,去掉图片代码后,100个字符已经几乎用完了。怎么办?
我个人是这样处理的。在PHP中,先用strip_tags去除内容中的标签,然后trim一下,再进行截取。这样的话就几乎没有什么问题了。
而这篇文章就有点意思,用作者的话来说,是无损html。来吧看看他写的内容。

最近在做一些内容搜索的工作,搜索出来的内容为html格式,列表部分需要显示每项内容的一部分。因为是html格式的内容,直接截取内容的前多少字符显 然不合适了。而如果直接去掉所有html格式然后再截取又无法达到想要的效果,再网上搜了一通之后,写下如下代码应该可以满足基本的要求了。(js写的, 因为容易调试)

JavaScript代码
  1. var br = {};  
  2. br.spTags = ["img","br","hr"];/*不需要成对出现的标记*/  
  3. br.contain = function(arr,it){  
  4.     for(var i=0,len=arr.length;i<len;i++){  
  5.         if(arr[i]==it){  
  6.             return true;      
  7.         }  
  8.     }  
  9.     return false;  
  10. }  
  11. br.subArtc = function(article,worldNum){  
  12.     var result = [];  
  13.     /*首先截取需要的字串*/  
  14.     var wcount = 0;  
  15.     var startTags = [],endTags = [];  
  16.     var isInTag = false;  
  17.     for(var i=0,len=article.length;i<len;i++){  
  18.         var w = article[i];  
  19.         result.push(w);  
  20.         if(w=="<"){  
  21.             isInTag = true;      
  22.         }  
  23.         if(!isInTag){  
  24.             wcount++;  
  25.             if(wcount==worldNum){  
  26.                 break;      
  27.             }  
  28.         }  
  29.         if(w==">"){  
  30.             isInTag = false;      
  31.         }  
  32.     }  
  33.     /*对字串进行处理*/  
  34.     var j=0;  
  35.     isInTag = false;  
  36.     var isStartTag = true;  
  37.     var tagTemp = "";  
  38.     while(j<i){  
  39.         w = result[j];  
  40.         if(isInTag){  
  41.             if(w==">" || w==" " || w=="/"){  
  42.                 isInTag = false;  
  43.                 if(isStartTag){  
  44.                     startTags.push(tagTemp);      
  45.                 }else{  
  46.                     endTags.push(tagTemp);      
  47.                 }  
  48.                 tagTemp = "";  
  49.             }  
  50.             if(isInTag){  
  51.                 tagTemp+=w;      
  52.             }  
  53.         }  
  54.         if(w=="<"){  
  55.             isInTag = true;  
  56.             if(result[j+1]=="/"){  
  57.                 isStartTag = false;  
  58.                 j++;  
  59.             }else{  
  60.                 isStartTag = true;      
  61.             }  
  62.         }  
  63.         j++;  
  64.     }  
  65.     /*剔除img,br等不需要成对出现的标记*/  
  66.     var newStartTags = [];  
  67.     for(var x=0,len=startTags.length;x<len;x++){  
  68.         if(!br.contain(br.spTags,startTags[x])){  
  69.             newStartTags.push(startTags[x]);  
  70.         }  
  71.     }  
  72.     /*添加没有的结束标记*/  
  73.     var unEndTagsCount = newStartTags.length - endTags.length;  
  74.     while(unEndTagsCount>0){  
  75.         result.push("<");  
  76.         result.push("/")  
  77.         result.push(newStartTags[unEndTagsCount-1]);  
  78.         result.push(">");  
  79.         unEndTagsCount--;  
  80.     }  
  81.     return result.join("");  
  82. };  

基本思路:

1.绕过标记,取得实际内容字数 ,如需要显示内容前100个字,绕过标记检索,得到第一百个字实际的索引。然后截取此索引前面的字串。
2.根据一得到的字串,得到这个字串中存在的开始标记和结束标记。注:此处的开始标记标识以"<"开通,且下一个字符不为"/"。
3.剔除2中 得到的开始标记中的不需要成对出现的标记。如br,img,hr等。
4.对比经过3处理的开始标记和2中得到的结束标记,没有配成对的在合适的位置为其配对。

此功能没有经过严格的测试,大家若有兴趣可以可以帮忙测试,有更好的想法的也可以回帖讨论。 

--EOF--http://www.cnblogs.com/bravfing/archive/2010/05/02/1725924.html

我没有用PHP的试过,因为在PHP中本身对多字节的支持就不是特别的好不象js,认为中文就是一个字符。不过思路可以考虑一下,但真正要显示摘要的话,当然还是不要含 HTML代码,因为那可能会影响页面布局。

 

Tags: substr, html, 页面布局

杯具:泰诺林和美林口服液都已经被FDA禁用??

在QQ微勃上看到一条别人的转发,大意是:强生公司的泰诺林和美林口服液都已经被FDA禁用,已经开始召回。这两个药物在儿童降温时普遍使用。

然后还给了一个链接,由于我英文不好所以,我就贴上链接以及文章全文。

http://www.reuters.com/article/idUSTRE6401AK20100502

Johnson & Johnson's recalls infant, children's Tylenol, Motrin
  1. Johnson & Johnson's recalls infant, children's Tylenol, Motrin  
  2.   
  3. (Reuters) - The Food and Drug Administration on Saturday urged consumers to stop using liquid Tylenol, Motrin, Benadryl and Zyrtec medicines for children and infants after a broad recall announced by the manufacturer, although it said the chance of serious problems was remote.  
  4.   
  5. U.S.  |  Health  
  6.   
  7. Johnson & Johnson's consumer division announced a broad recall of products, including certain liquid infant's and children's Tylenol, Motrin, Zyrtec, and Benadryl products late on Friday.  
  8.   
  9. A full list of the over 40 affected products made by McNeil Consumer Healthcare is available at www.mcneilproductrecall.com  
  10.   
  11. "We want to be certain that consumers discontinue using these products," FDA Commissioner Margaret Hamburg said in a statement.  
  12.   
  13. "While the potential for serious health problems is remote, Americans deserve medications that are safe, effective and of the highest quality. We are investigating the products and facilities associated with this recall and will provide updates as we learn more," she said.  
  14.   
  15. McNeil said it was recalling the products in consultation with the FDA after discovering manufacturing deficiencies that could affect the quality, purity or potency of the medicines.  
  16.   
  17. The FDA said some of the products may not meet required quality standards, and parents and caregivers should stop administering them to children and switch to generic brands, which are not affected by the recall.  
  18.   
  19. They said consumers should not administer adult strength medicine to infants or children since that could result in serious harm.  
  20.   
  21. Some of the products affected by the recall may contain a higher concentration of active ingredient than specified; others contain inactive ingredients that may not meet internal testing requirements; and others may contain tiny particles, the FDA said.  
  22.   
  23. The FDA said the chance of an adverse reaction was remote, but urged consumers to contact their doctors and the FDA if their children exhibited any symptoms.  
  24.   
  25. McNeil Consumer said it was recalling all lots of the over-the-counter products. The medicines were manufactured in the United States and distributed in the United States, Canada, the Dominican Republic, Dubai, Fiji, Guam, Guatemala, Jamaica, Puerto Rico, Panama, Trinidad and Tobago, and Kuwait.  
  26.   
  27. It said consumers with questions about the recall could contact the company at 1-800-222-6036 or the website.  
  28.   
  29. (Reporting by Andrea Shalal-Esa; Editing by Eric Beech)  
不知道具体是啥意思,只知道杯具了。我怕跨国。

Tags: 强生, 泰诺林, 美林, fda