LoginSignup
4
0

More than 5 years have passed since last update.

CakePHP2 命名規則

Posted at

CakePHPの命名規則のメモ

条件

CakePHPver2.6.10

1.cakePHPディレクトリ名:cake
2.アプリケーション名:testapp
3.アクション名:action
4.テーブル名 :tables

http://localhost/cake/testapp/action/
http://localhost/[cakephpディレクトリ]/[アプリケーション名]/[アクション名]/

命名規則

CakePHP

ファイル、フォルダ名はキャメル記法を使用

Controller

  • ファイル名:[アプリケーション名]Controller.php → TestAppController.php
  • アクション記載:function [アクション名](){}function action(){}
app/Controller/TestAppController.php
<?php
App::uses('AppController', 'Controller');
class TestAppController extends AppController {
    function action(){//アクション名
    }
}

View

  • フォルダ名:[アプリケーション名] → TestApp
  • ファイル名:[アクション名].ctp → action.ctp
app/View/TestApp/action.ctp
//表示させるものを記載
<html>
  <head>
    <title>action Page</title>
  </head>
  <body>
    <h1>action Page</h1>
  </body>
</html>

Model

  • ファイル名:[テーブル名※1].php → Table.php
  • ファイル名:[テーブル名]Controller.php → TablesController.php
app/Model/Table.php
<?php
App::uses('AppModel', 'Model');
class Table extends AppModel { 
}
app/Controller/TablesController.php
<?php
App::uses('AppController', 'Controller');
class TablesController extends AppController {
    public $scaffold;//値確認用
}

テーブルにアクセスし中身を確認
http://localhost/cake/tables/

※1
テーブル名が複数系の場合は、単数系に
→ tables → Table.php
"_"の後の文字は大文字
→ sample_tables → SampleTable.php

参考

about COC
https://ja.wikipedia.org/wiki/%E8%A8%AD%E5%AE%9A%E3%82%88%E3%82%8A%E8%A6%8F%E7%B4%84

CakePHP2 プログラミング入門
http://libro.tuyano.com/index2?id=734001

4
0
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
4
0