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];

你可能感兴趣的:(编程,PHP,windows,cache,cakephp)