開発用のリファレンス兼アウトプット学習のためにCakePHPのコードをメモ。
Model
path : app/Model/*.php
命名規則
code
class Model extends AppModel {
}
View
- Path app/View/folder/*.ctp
- Layout
命名規則
code
Controller
- Path : app/Controller/ModelsController.php
命名規則
code
class ModelsController extends AppController {
public ;
public function method ($param) { // url is '/method/param'
$this->autoRender = false // If not need to render
$this->Model->find();
if ($this->request->is('post')) {} // 'get', 'ajax'
$this->set('variable', $variable);
$this->set(['key'=>hash]);
$this->render(*templateFileName*); // Not include file extra
$this->redirect();
}
todo: CRUDシーケンス
public function add() {}
public function edit() {}
public function delete() {
$this->Model->delete($id);
}
}
Routing
code
Helper
code
Behavior
code
Component
code
DB
Migration
Cache
Path : app/tmp/cache/*
DB関連でハマったらファイルrm app/tmp/cache/*
Log
Path : app/tmp/logs/debug.log or error.log
logging : $this->log('log', *output*);
Hook
- beforeFilter
- beforeRender
- afterFilter
How to ajax
server code
class ModelsController extends AppController {
functiono method() {
$this->autoRender = false;
return response;
}
}
client code
$.ajax({
url:/*Controller*/method,
type:'POST',
data: {key:value,...},
dataType:'json',
})
.done(function(response){})
.fail(function(){});
Workflow
- UI
- DB
- Model
- View
- Controller
- Coding
- Test
- Pull Requset
- Review