2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cake Recipe

Last updated at Posted at 2016-04-10

開発用のリファレンス兼アウトプット学習のために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

参考文献

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?