一、cakephp,一个controller里面能够使用多个model,用$uses来声明php
public $uses = array("Question", "Answer");html
model的命名遵循驼峰式,不像view是用下划线隔开数组
二、model默认返回数组,使用下面的代码来转换成对象eclipse
public $actsAs = array('Bean');post
须要有对应的bean对象才能进行转换。ui
复制类的时候必定要记得改类名,zend studio不会像eclipse那样提示类名错误this
三、php拼接htmlspa
<?php foreach($message as $key => $value){ echo '<li> <p class="p1">'.$value['name'].'<a href="#">'.(isset($value['city'])?$value['city']:"").'</a></p> <p>'.$value['amount'].(isset($value['active'])?'('.$value['active'].')':"").'</p> <p>'.$value['msg'].'</p> </li>'; } ?>
四、经过在文件中打印内容,远程调试代码调试
ob_start(); echo '<pre>'; print_r($content); $txt = ob_get_contents(); ob_end_clean(); $fp = fopen('/home/she/weixin.txt', 'a+'); fwrite($fp, $txt); fclose($fp);
五、controller 引用model的问题code
WechatsController 默承认以直接使用Model Wechat,可是若是controller里面使用了下面的引入语句 public $uses = array('Game', 'User', 'Contest'); 其中没有包含Wechat, 那wechat就不能直接使用了 Wechat没有在根目录下的Model里,若是引用的话要加上外面的目录 $this->loadModel('External.Wechat');
六、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));
七、后台赋值和前台取值
post取值:$this->data['openId']; get取值:$openId = $this->request->query['openId']; 后台复制:$this->set("openId",$openId); 前台取值:<input type="hidden" name="openId" value="<?php echo $openId; ?>"/>
八、指定某些方法无需权限验证
public function beforeFilter(){ parent::beforeFilter(); $this->Auth->allow('sheet', 'allagainst'); }