加入收藏 | 设为首页 | 会员中心 | 我要投稿 甘南站长网 (https://www.0941zz.com/)- 科技、行业物联网、开发、云计算、云管理!
当前位置: 首页 > 编程开发 > PHP > 正文

cakephp常见知识点汇总

发布时间:2020-12-31 00:32:28 所属栏目:PHP 来源:互联网
导读:这篇文章主要介绍了cakephp常见知识点,汇总整理了cakephp的模板、数据库、日志、表单等相关操作技巧,需要的朋友可以参考下

本文实例总结了cakephp常见知识点。分享给大家供大家参考,具体如下:

1. 调用其他控制器的模板,重定向

方法一:

在此调用/views/tasks/tasks下的hello.ctp模板

viewPath = 'tasks'; $this -> render('hello');

方法二(带参):

$this->redirect(array('controller'=>'users','action'=>'welcome',urlencode($this->data['姓名'].'haha')));

2. 查询

直接使用sql:

PostContent->query("select * from user"); find(): $clue = $this->clue->find('all',array( 'fields' =>array( 'id','title','content' ),'order' => 'id ASC','conditions' => array('id' => '1'),) );

find的参数,第一个可以是all、first、count,第二个参数为一数组,数组的key可以是:conditions、fields、order、limit、offset、joins。

添加:

clue->create(); $this->clue->save($this->data);

修改:

clue->create(); $this->clue->save($this->data);

删除:

clue->delete($id)

3. 不需要公共样式时

layout = false;

不用渲染任何view

autoRender = false;

4. 定义公共的方法/类

方法一:

可以在/app/Controller/AppController.php中定义公共的方法

调用

test();

方法二:

在/app/controllers/components中创建UtillComponent.php

调用:

Utill->juanstr($digit1);

5. 定义提示信息

Session->setFlash(__('The user has been saved'));

<p class="wrong"><?php echo $this->Session->flash();?>

或者

Session->write('Message.auth',array('message'=>__('The user has been saved.',true),'element'=>'','params'=>array()));

<p class="wrong"><?php echo $this->Session->flash('auth');?>

6. session设置

可参考:

check(string $name);

检查Session中是否已有$name为键值的数据项.

del(string $name); delete(string $name);

删除$name 指定的 Session 变量。

valid当Session有效时返回true,最好在read()操作前用它来确定你要访问的会话是否确实有效.

read(string $name);

返回 $name 变量值。

renew

通过创建新的seesion ID,删除原有的ID,将原有Session中信息更新到新的Session中。

write(string $name,mixed $value);

将变量 $name,$value写入会话.

error

返回最近由 Cake Session Component 产生的错误,常用于调试。

7. 表单

Form->create('Subject',array( 'type' => 'post','inputDefaults'=>array( 'div'=>false,'label'=>false ),'url'=>array( 'controller'=>'subjects','action'=>'edit' ),'onsubmit'=>'return validateCallback(this,dialogAjaxDone);' //提交前验证 ) ); echo $this->Form->input('id',array('type'=>'hidden')); echo $this->Form->input('uid',array('type'=>'hidden')); ?>
    Form->input('type',array('type'=>'select','class'=>'ipt','options' => array(0=>'文章',1=>'专题',2=>'图组')));?>
  • Form->input('pushtype','options' => $pushtype,//所有选项 'multiple'=>'checkbox','selected' => $pushtypes,//选中的项 )); ?>
    推荐文章
      热点阅读