当前位置: 首页 > news >正文

美食网站html模板众包网站建设

美食网站html模板,众包网站建设,网站申请名称和域名,云客网平台yii 常用一些调用 (增加中) 调用YII框架中 jquery#xff1a;Yii::app()-clientScript-registerCoreScript(‘jquery’); framework/web/js/source的js,其中registerCoreScript key调用的文件在framework/web/js/packages.php列表中可以查看 在view中得到当前contro…yii 常用一些调用 (增加中) 调用YII框架中 jqueryYii::app()-clientScript-registerCoreScript(‘jquery’); framework/web/js/source的js,其中registerCoreScript key调用的文件在framework/web/js/packages.php列表中可以查看 在view中得到当前controller的ID方法 Yii::app()-getController()-id; 在view中得到当前action的ID方法 Yii::app()-getController()-getAction()-id; yii获取ip地址 Yii::app()-request-userHostAddress; yii判断提交方式 Yii::app()-request-isPostRequest 得到当前域名: Yii::app()-request-hostInfo 得到proteced目录的物理路径 YII::app()-basePath; 获得上一页的url以返回 Yii::app()-request-urlReferrer; 得到当前url Yii::app()-request-url; 得到当前home url Yii::app()-homeUrl 得到当前return url Yii::app()-user-returnUrl 项目路径 dirname(Yii::app()-BasePath) 项目目录 Yii::app()-request-baseUrl 只输出一个连接url?php echo $this-createUrl(admin/left_menu);? //**.php?radmin/left_menu 输出一组urlyii url 默认样式 ?php $this-widget(zii.widgets.CMenu,array( itemsarray( array(label主菜单, urlarray(/admin/left_menu)), array(label内容发布, urlarray(/admin/page)), array(label内容维护, urlarray(/site/contact)), array(label系统主页, urlarray(/site/login)), array(label网站主页, urlarray(/site/logout)), array(label会员中心, urlarray(/site/login)), array(label注销, urlarray(/site/login)), ), )); ? //除域名外的URL Yii::app()-request-getUrl(); 除域名外的首页地址 Yii::app()-user-returnUrl; 6、//除域名外的根目录地址 Yii::app()-homeUrl; YII FRAMEWORK的COOKIE使用方法 设置cookie: [php] view plain copy $cookie new CHttpCookie(‘mycookie’,‘this is my cookie’); c o o k i e − e x p i r e t i m e ( ) 60 ∗ 60 ∗ 24 ∗ 30 ; / / 有限期 30 天 Y i i : : a p p ( ) − r e q u e s t − c o o k i e s [ ′ m y c o o k i e ′ ] cookie-expire time()60*60*24*30; //有限期30天 Yii::app()-request-cookies[mycookie] cookie−expiretime()60∗60∗24∗30;//有限期30天Yii::app()−request−cookies[′mycookie′]cookie; 读取cookie: [html] view plain copy $cookie Yii::app()-request-getCookies(); echo $cookie[‘mycookie’]-value; 销毁cookie: [html] view plain copy $cookie Yii::app()-request-getCookies(); unset(cookie[name]); 在控制器添加CSS文件或JAVASCRIPT文件 [php] view plain copy public function init() { parent::init(); Yii::app()-clientScript-registerCssFile(Yii::app()-baseUrl.‘/css/my.css’); Yii::app()-clientScript-registerScriptFile(Yii::app()-baseUrl.‘/css/my.js’); } YII FRAMEWORK的用户验证与授权 yii提供了CUserIdentity类,这个类一般用于验证用户名和密码的类.继承后我们需要重写其中的authenticate()方法来实现我们自己的验证方法.具体代码如下: [php] view plain copy class UserIdentity extends CUserIdentity { private $_id; public function authenticate() { r e c o r d U s e r : : m o d e l ( ) − f i n d B y A t t r i b u t e s ( a r r a y ( ′ u s e r n a m e ′ recordUser::model()-findByAttributes(array(username recordUser::model()−findByAttributes(array(′username′this-username)); if($recordnull) t h i s − e r r o r C o d e s e l f : : E R R O R U S E R N A M E I N V A L I D ; e l s e i f ( this-errorCodeself::ERROR_USERNAME_INVALID; else if( this−errorCodeself::ERRORU​SERNAMEI​NVALID;elseif(record-password!md5($this-password)) $this-errorCodeself::ERROR_PASSWORD_INVALID; else { t h i s − i d this-_id this−i​drecord-id; $this-setState(‘title’, $record-title); KaTeX parse error: Expected EOF, got } at position 45: …ONE; }̲ retu…this-errorCode; } public function getId() { return $this-_id; } } 在用户登陆时则调用如下代码: // 使用提供的用户名和密码登录用户 [html] view plain copy i d e n t i t y n e w U s e r I d e n t i t y ( u s e r n a m e , p a s s w o r d ) ; i f ( identitynew UserIdentity(username,password); if( identitynewUserIdentity(username,password);if(identity-authenticate()) Yii::app()-user-login($identity); else echo $identity-errorMessage; 用户退出时,则调用如下代码: [html] view plain copy // 注销当前用户 Yii::app()-user-logout(); 其中的user是yii的一个components.需要在protected/config/main.php中定义 [html] view plain copy ‘user’array( // enable cookie-based authentication ‘allowAutoLogin’true, ‘loginUrl’ array(‘site/login’), ), YII FRAMEWORK中TRASACTION事务的应用 [html] view plain copy $modelPost::model(); t r a n s a c t i o n transaction transactionmodel-dbConnection-beginTransaction(); try { // find and save are two steps which may be intervened by another request // we therefore use a transaction to ensure consistency and integrity p o s t post postmodel-findByPk(10); $post-title‘new post title’; $post-save(); $transaction-commit(); } catch(Exception $e) { $transaction-rollBack(); } Yii Framework中截取字符串(UTF-8)的方法 Helper.PHP [php] view plain copy class Helper extends CController { public static function truncate_utf8_string($string, $length, $etc ‘…’) { $result ‘’; s t r i n g h t m l e n t i t y d e c o d e ( t r i m ( s t r i p t a g s ( string html_entity_decode(trim(strip_tags( stringhtmle​ntityd​ecode(trim(stript​ags(string)), ENT_QUOTES, ‘UTF-8’); s t r l e n s t r l e n ( strlen strlen( strlenstrlen(string); for ( i 0 ; ( ( i 0; (( i0;((i KaTeX parse error: Expected EOF, got at position 9: strlen) ̲ (length 0)); KaTeX parse error: Expected }, got EOF at end of input: … if (number strpos(str_pad(decbin(ord(substr($string, KaTeX parse error: Expected }, got EOF at end of input: … if (length 1.0) { break; } r e s u l t . s u b s t r ( result . substr( result.substr(string, $i, $number); $length - 1.0; $i $number - 1; } else { r e s u l t . s u b s t r ( result . substr( result.substr(string, $i, 1); $length - 0.5; } } r e s u l t h t m l s p e c i a l c h a r s ( result htmlspecialchars( resulthtmlspecialchars(result, ENT_QUOTES, ‘UTF-8’); if ($i $strlen) { $result . $etc; } return $result; } } 将Helper.php放进protected\components文件夹下。 使用方法 Helper::truncate_utf8_string(content,20,false);//不显示省略号Helper::truncateutf8string(content,20); //显示省略号 CBREADCRUMBS简介~俗称:面包屑 功能介绍:zii.widgets 下的CBreadcrumbs类,其继承关系: CBreadcrumbs » CWidget » CBaseController » CComponent .源代码位置: framework/zii/widgets/CBreadcrumbs.php 面包屑类显示一个链接列表以表明当前页面在整个网站中的位置. 由于面包屑通常会出现在网站的近乎所有的页面,此插件最好在视图的layout中进行部署. 你可以定义一个breadcrumbs属性并且在布局文件中指派给(网站)基础控制器插件,如下所示: [html] view plain copy t h i s − w i d g e t ( ′ z i i . w i d g e t s . C B r e a d c r u m b s ′ , a r r a y ( ′ l i n k s ′ this-widget(zii.widgets.CBreadcrumbs, array( links this−widget(′zii.widgets.CBreadcrumbs′,array(′links′this-breadcrumbs, )); 于是乎,你需要时,只需要在每个视图脚本中,指定breadcrumbs属性(就可以显示出网页导航了). 以上是官方提供的文档文件的介绍. 下面介绍视图文件中写法: [html] view plain copy $this-breadcrumbsarray( ‘Users’array(‘index’), ‘Create’, // 形式 : ‘key’ ‘value’ key的位置相当于最后显示出来的a标签内的名字, value则相当于a标签的href属性. // Create’表示当前页 故没有设置链接. ); YII FRAMEWORK中验证码的使用 1.在controller中修改 [html] view plain copy public function actions() { return array( // captcha action renders the CAPTCHA image displayed on the contact page ‘captcha’array( ‘class’‘CCaptchaAction’, ‘backColor’0xFFFFFF, //背景颜色 ‘minLength’4, //最短为4位 ‘maxLength’4, //是长为4位 ‘transparent’true, //显示为透明 ), ); } 2.在view的form表单中添加如下代码 [html] view plain copy ?php if(CCaptcha::checkRequirements()): ? ?php echo $form-labelEx($model,verifyCode); ? ?php $this-widget(CCaptcha); ? ?php echo $form-textField($model,verifyCode); ? Please enter the letters as they are shown in the image above. Letters are not case-sensitive. ?php echo $form-error($model,verifyCode); ? ?php endif; ? YII FRAMEWORK的CHTML::LINK支持锚点 CHtml::link(‘链接文字’,array(‘article/view’,‘id’‘3’,‘#’‘锚名称’); CUrlManager的 createUrl是可以支持 ‘#’ 的 params array(‘userid’ 100, ‘#’ ‘锚名称’);this-createUrl(route,params); YII FRAMEWORK在WEB页面查看SQL语句配置 [html] view plain copy ‘components’array( ‘errorHandler’array( // use ‘site/error’ action to display errors ‘errorAction’‘site/error’, ), ‘log’array( ‘class’‘CLogRouter’, ‘routes’array( array( ‘class’‘CFileLogRoute’, ‘levels’‘error, warning’, ), // 下面显示页面日志 array( ‘class’‘CWebLogRoute’, ‘levels’‘trace’, //级别为trace ‘categories’‘system.db.*’ //只显示关于数据库信息,包括数据库连接,数据库执行语句 ), ), ), ), YII FRAMEWORK打印AR结果 [html] view plain copy KaTeX parse error: Expected }, got EOF at end of input: … var_dump(v-attributes); } yii 数据save后得到插入id post−save();//得到上次插入的Insertidid $post-attributes[‘id’]; 如此很简单 yii获取ip地址 Yii::app()-request-userHostAddress; yii execute后获取insert id $id Yii::app()-db-getLastInsertID(); yii获取get,post过来的数据 Yii::app()-request-getParam(‘id’); yii如何设置时区 可以在config/main.php 里’timeZone’‘Asia/Chongqing’,设定时区. yii如何将表单验证提示弄成中文的 将main.php里的app配置加上language‘zh_cn’,系统默认的提示就是中文的了要自定义消息就像楼上说的定义message yii如何获得上一页的url以返回 Yii::app()-request-urlReferrer; yii多对多关联条件 [html] view plain copy c r i t e r i a − a d d I n C o n d i t i o n ( ′ c a t e g o r y s . i d ′ , criteria-addInCondition(categorys.id, criteria−addInCondition(′categorys.id′,in); c r i t e r i a − a d d S e a r c h C o n d i t i o n ( ′ S h o p . n a m e ′ , k e y w o r d ) ; s h o p s S h o p : : m o d e l ( ) − w i t h ( a r r a y ( ′ c a t e g o r y s ′ a r r a y ( ′ t o g e t h e r ′ t r u e ) ) ) − f i n d A l l ( criteria-addSearchCondition(Shop.name,keyword);shopsShop::model()-with(array(categorysarray(togethertrue)))-findAll( criteria−addSearchCondition(′Shop.name′,keyword);shopsShop::model()−with(array(′categorys′array(′together′true)))−findAll(criteria); 同时要在Shop模型中加入alias‘categorys’ ,另外togethertrue放在模型的关联中也可 yii如何防止重复提交 提交后Ccontroler-refresh(); yii过滤不良代码 [html] view plain copy $purifiernew CHtmlPurifier; $purifier-optionsarray(‘HTML.Allowed’‘div’); c o n t e n t content contentpurifier-purify($content); 或者 [html] view plain copy ?php $this-beginWidget(CHtmlPurifier); ? …display user-entered content here… ?php $this-endWidget(); ? 显示yii的sql语句查询条数和时间 在config/main.php中配置在log组件的routes中加入 [html] view plain copy array( ‘class’‘CProfileLogRoute’, ‘levels’‘error, warning’, ) 同时在db组件中加入’enableProfiling’true,同时在这种情况下可以用CDbConnection::getStats() 查看执行了多少个语句用了多少时间print_r(CDbConnection::getStats()); Yii多数据库操作 大多数情况下我们都会采用同一类型的数据库只是为了缓解压力分成主从或分布式形式而已。声明你可以在app config里声明其它的数据库连接 ?php ...... componentsarray( db....// 主链接 db1...// 从连接1 db2...// 从连接2 ) ......操作在代码里可以通过Yii::app()-db1和Yii::app()-db2获得两个从连接。高级操作更高级自动的主从数据库功能将在1.1实现。
http://www.w-s-a.com/news/431417/

相关文章:

  • 从零开始学网站建设知乎安防网站下载
  • 打开网站弹出qq应用软件有哪些
  • 温州网站建设seo网站 如何做 中英文切换
  • 聊城做网站的公司资讯信阳 网站建设
  • 天津市工程建设交易网站查汗国珠海 网页设计
  • 龙果学院大型网站稳定性建设汾阳做网站
  • 湖北 个人网站备案时间域名查询备案查询
  • 网站推广方式校园网站怎么建
  • 长沙seo网站排名怎么在百度发帖
  • 织梦贷款网站模板做印章网站
  • 彭州做网站上海百度网络推广
  • 广州网站搭建快速提升网站排名荧光字网站
  • 15年做那些网站能致富做seo是什么意思
  • 各电商网站的特点网站制作2007
  • 用html做一号店网站怎么做公众号注册平台官网
  • 做盈利网站怎么备案vs做网站如何调试
  • 嘉兴做营销型网站廊坊做网站外包
  • 双语网站模板常州做网站的公司
  • 广州市车管所网站建设全国做网站公司前十名
  • 太原手手工网站建设公司视频直播服务
  • 雷达图 做图网站wordpress首页怎么美化
  • 四川做网站设计公司价格vip解析网站怎么做的
  • 网站建设流程域名申请做化工的 有那些网站
  • 软件开发设计流程图seo搜索引擎官网
  • 外国小孩和大人做网站东富龙科技股份有限公司
  • 上线倒计时单页网站模板做网站的资金来源
  • 泸州市建设厅网站中小企业网络需求分析
  • asp网站版权做网页价格
  • 长春网站建设路关键词优化公司哪家好
  • 河南省建设银行网站年报天津设计师网站