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

CakePHP 编程笔记3

1. 用户登录验证流程

users controller : beforefilter

-> app controller : beforefilter

-> auth component : startup

-> auth component : login

-> auth component : admin_login

->render view template for login

->press submit, post form data to controller, repeat the above process again.

2. 取消关联查询

You can use recursive or unbind whenever you want to unbind associations from models. This is very useful because there are cases when you want to execute a simple query and you do not want to join other tables. Here comes unbind. Unbind allows us to unbind all but some model associations. On the other hand if you want to unbind all associations you can use recursive like this:

$this-> Model-> recursive = - 1;
3. 访问不完整对象错误
在enable persist Component后,可能会遇到如下的错误提示:
Notice (8): Model:: resetAssociations() [<a
href=' http://php.net/model.resetassociations' >model.resetassociations</
a>]: The script tried to execute a method or access a property of an
incomplete object.
这样的错误可能是1.3的persist component 和 cache 存在bug引起的, 某个类在序列化和cache的时候有点问题, 导致反序列化时找不到类定义。解决方法:把\app\tmp\cache\persistent 和 \app\tmp\cache\model目录清空重新加载。
4.设置和读取url参数

读取参数

http://book.cakephp.org/view/55/The-Parameters-Attribute-params

$this->params['url']

Stores the current URL requested, along with key-value pairs of get variables. For example, if the URL /posts/view/?var1=3&var2=4 was called, $this->params['url'] would contain:

[url] => Array
(
    [url] => posts/view
    [var1] => 3
    [var2] => 4
)
设置参数
http://book.cakephp.org/view/1448/url
URL with GET params and named anchor
Plain Text View
<?php echo $this->Html->url(array(
    "controller" => "posts",
    "action" => "search",
    "?" => array("foo" => "bar"),
    "#" => "first"));
?>

//Output
/posts/search?foo=bar#first
  1. <?php echo $this->Html->url(array(
  2. "controller" => "posts",
  3. "action" => "search",
  4. "?" => array("foo" => "bar"),
  5. "#" => "first"));
  6. ?>
  7. //Output
  8. /posts/search?foo=bar#first

5. how to get current url in view

if you want to take current URL in cakePHP view than check out below code :

echo Router::url($this->here, true);

This will output current URL. If you want relative path and not full URL than you can do like this :

echo $this->here;

By this you can get relative path in the view.

6. how to get domain name

// get host name from URL
preg_match("/^(http:\/\/)?([^\/]+)/i", windows.location, $matches);
$host = $matches[2];

相关文章:

  • Floyd模板(详细操作最基础版)
  • Sendmail大全
  • 内核配置备份
  • Query 使用手册
  • 循环冗余校验码CRC,求解步骤
  • 求职中的平常心——Leo网上答疑48
  • 实验三 数据查询(4学时)
  • 北京簋街 美食完全攻略 + 簋街好吃的夜宵去处-----店铺介绍大全
  • 随书赠送的台历样式
  • Interview2---3g
  • 整合Bullet物理引擎到Ogre on iPhone
  • CDMA的定位方式
  • Bullet的3D Max插件
  • 判断字符串中字符最多的那一个及个数
  • 两个最容易被人忽略的基本代码优化技术
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • 4个实用的微服务测试策略
  • JAVA_NIO系列——Channel和Buffer详解
  • SegmentFault 2015 Top Rank
  • Vue 2.3、2.4 知识点小结
  • 阿里中间件开源组件:Sentinel 0.2.0正式发布
  • 汉诺塔算法
  • 每个JavaScript开发人员应阅读的书【1】 - JavaScript: The Good Parts
  • 漂亮刷新控件-iOS
  • 让你成为前端,后端或全栈开发程序员的进阶指南,一门学到老的技术
  • 时间复杂度与空间复杂度分析
  • 一个普通的 5 年iOS开发者的自我总结,以及5年开发经历和感想!
  • 赢得Docker挑战最佳实践
  • CMake 入门1/5:基于阿里云 ECS搭建体验环境
  • ​linux启动进程的方式
  • ​油烟净化器电源安全,保障健康餐饮生活
  • # Swust 12th acm 邀请赛# [ A ] A+B problem [题解]
  • (day 12)JavaScript学习笔记(数组3)
  • (zt)最盛行的警世狂言(爆笑)
  • (安卓)跳转应用市场APP详情页的方式
  • (搬运以学习)flask 上下文的实现
  • (二)丶RabbitMQ的六大核心
  • (附源码)spring boot校园拼车微信小程序 毕业设计 091617
  • (附源码)ssm户外用品商城 毕业设计 112346
  • (附源码)计算机毕业设计SSM疫情下的学生出入管理系统
  • (黑客游戏)HackTheGame1.21 过关攻略
  • (力扣记录)1448. 统计二叉树中好节点的数目
  • (免费领源码)Java#Springboot#mysql农产品销售管理系统47627-计算机毕业设计项目选题推荐
  • (三) diretfbrc详解
  • (十一)手动添加用户和文件的特殊权限
  • (新)网络工程师考点串讲与真题详解
  • (转)ORM
  • (转载)Linux 多线程条件变量同步
  • .a文件和.so文件
  • .Net core 6.0 升8.0
  • .Net Memory Profiler的使用举例
  • .net 后台导出excel ,word
  • .Net通用分页类(存储过程分页版,可以选择页码的显示样式,且有中英选择)
  • .NET下的多线程编程—1-线程机制概述
  • .sys文件乱码_python vscode输出乱码