zoukankan      html  css  js  c++  java
  • cakephp随笔

    1、使用了 

        public $uses = array();          //如果控制器和模型相同的话,不需要加载,如果不是就需要加载,代表的就是模型层
        public $helpers = array('html','Form','Session'); //这里的所有的用到的都必须加载 ,代表的就是视图层
        public $components = array('Session');  //session被cakephp默认加载进去了,用到的还是加载一次吧。//代表的就是控制器曾,这里方法,代表的是控制器的方法

    这个比较关键,如果在使用之前不进行加载的话,会产生很严重的结果

    2、这里需要注意一点的是

      

    public $Components = null; 
    
    /**
     * Array containing the names of components this controller uses. Component names
     * should not contain the "Component" portion of the classname.
     *
     * Example: `public $components = array('Session', 'RequestHandler', 'Acl');`
     *
     * @var array
     * @link http://book.cakephp.org/2.0/en/controllers/components.html
     */
        public $components = array('Session');

    看到源代码的这个核心方法的时候,居然使用了两个相同的变量、其实不同的,在CakePHP所有的约定没有说明一点就是首字母大写的就是一个对象,而小写开始的就是变量。

    3、component 内容 

    • Security
    • Sessions
    • Access control lists
    • Emails
    • Cookies
    • Authentication
    • Request handling
    • Pagination

    使用组件  

    $this->Components->load('OneTimer');


    动态使用组件
     public $components = array('Session', 'Cookie');
    开发一个组件

    request 对象为系统传递到controller去的数据,包含了表单中的所有数据
    例如获取很多数据
    $this->request->pass;
    $this->request['pass'];
    $this->request->params['pass'];
    
    // named parameters
    $this->request->named;
    $this->request['named'];
    $this->request->params['named'];

    获取get参数

    $this->request->query['page']; 参数名

    获取Url信息和客户端的很多信息

    获取data数据

    this->request->data['MyModel']['title'];

    判断请求类型

    $this->request->is('post');
    $this->request->isPost();
    $this->request->webroot contains the webroot directory.
    $this->request->base contains the base path.
    $this->request->here contains the full address to the current request
    $this->request->query contains the query string parameters.

    其他数据

    response对象

    Sending headers for redirects. 发送头部
    Sending content type headers. 发送数据类型
    Sending any header. 发送头部
    Sending the response body. 发送回应内容


  • 相关阅读:
    hyper-v启动虚拟机时提示“The application encountered an error while attempting to change the state of the machine ‘虚拟机名称'”如何处理?
    ubuntu下如何开机自动执行自定义脚本?
    centos下如何开放某个端口?
    linux都有哪些运行级别?
    linux内核在挂载ramdisk的过程中报错"RAMDISK: incomplete write (10739 != 32768)"如何处理?
    linux内核挂载根文件系统时报错”VFS: Cannot open root device "ram0" or unknown-block(0,0): error -6“如何处理?
    c代码审查软件
    项目管理术语表
    项目管理常用缩写
    MYSQL的读写分离主从延时问题
  • 原文地址:https://www.cnblogs.com/linksgo2011/p/2934907.html
Copyright © 2011-2022 走看看