cakephp视图用php文件,cakephp使用笔记

1、cakephp,一个controller里面可以使用多个model,用$uses来声明

public $uses = array("Question", "Answer");

model的命名遵循驼峰式,不像view是用下划线隔开

2、model默认返回数组,使用下面的代码来转换成对象

public $actsAs = array('Bean');

需要有对应的bean对象才能进行转换。

复制类的时候一定要记得改类名,zend studio不会像eclipse那样提示类名错误

3、php拼接html

foreach($message as $key => $value){

echo '

'.$value['name'].''.(isset($value['city'])?$value['city']:"").'

'.$value['amount'].(isset($value['active'])?'('.$value['active'].')':"").'

'.$value['msg'].'

';

}

?>

4、通过在文件中打印内容,远程调试代码

ob_start();

echo '

';

print_r($content);

$txt = ob_get_contents();

ob_end_clean();

$fp = fopen('/home/she/weixin.txt', 'a+');

fwrite($fp, $txt);

fclose($fp);

5、controller 引用model的问题

WechatsController 默认可以直接使用Model Wechat,但是如果controller里面使用了下面的引入语句

public $uses = array('Game', 'User', 'Contest');

其中没有包含Wechat, 那wechat就不能直接使用了

Wechat没有在根目录下的Model里,如果引用的话要加上外面的目录

$this->loadModel('External.Wechat');

6、cakephp 查询

$conditions = array();

$conditions['or'] = array(

array('BuddyRelationship.user_id'=>$userId, 'BuddyRelationship.buddy_user_id'=>$buddyUserId),

array('BuddyRelationship.user_id'=>$buddyUserId, 'BuddyRelationship.buddy_user_id'=>$userId)

);

$conditions['and'] = array('BuddyRelationship.status'=>self::Accepted, 'BuddyRelationship.deleted'=>self::Undeleted);

$buddyCount = $this->find('count', compact('conditions'));

$creditModel = ClassRegistry::init("Credit");

$conditions['and'] = array('Credit.amount <>'=>0);

$conditions['and'] = array("User.id" => $uid);

$credit = $creditModel->find('first', array('conditions'=>$conditions));

7、后台赋值和前台取值

post取值:$this->data['openId'];

get取值:$openId = $this->request->query['openId'];

后台复制:$this->set("openId",$openId);

前台取值:"/>

8、指定某些方法无需权限验证

public function beforeFilter(){

parent::beforeFilter();

$this->Auth->allow('sheet', 'allagainst');

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值