Subscribe to RSS Feed

Subscribe to Comments Feed

Subscribe to Atom Feed

tech

技術的なことのメモ
  • blog
  • sitemap
  • 紹介

bakeで雛型を作る

by outsider タグ: cakephp, php
06 08 2009

DBにテーブルをあらかじめ作成しておく。
今回使うテーブルは「servers」。

  • bakeの実行
  • $ cd [cakeのインストール先]/cake/console
    $ ./cake bake
    Welcome to CakePHP v1.2.4.8284 Console
    ---------------------------------------------------------------
    App : app
    Path: /home/iwd-idc/httpd/cake/app
    ---------------------------------------------------------------
    Interactive Bake Shell
    ---------------------------------------------------------------
    [D]atabase Configuration
    [M]odel
    [V]iew
    [C]ontroller
    [P]roject
    [Q]uit
    What would you like to Bake? (D/M/V/C/P/Q)
    
  • Databaseの設定
  • Databaseの設定はここからもできる。

    ---------------------------------------------------------------
    Database Configuration:
    ---------------------------------------------------------------
    Name:
    [default] >
    Driver: (db2/firebird/mssql/mysql/mysqli/odbc/oracle/postgres/sqlite/sybase)
    [mysql] > postgres
    Persistent Connection? (y/n)
    [n] >
    Database Host:
    [localhost] >
    Port?
    [n] >
    User:
    [root] > test
    Password:
    > test
    Database Name:
    [cake] > test
    Table Prefix?
    [n] >
    Table encoding?
    [n] >
    Table schema?
    [n] > 
    
    ---------------------------------------------------------------
    The following database configuration will be created:
    ---------------------------------------------------------------
    Name:         default
    Driver:       postgres
    Persistent:   false
    Host:         localhost
    User:         test
    Pass:         *******
    Database:     test
    ---------------------------------------------------------------
    Look okay? (y/n)
    [y] >
    Do you wish to add another database configuration?
    [n] > 
    
    Creating file [cakeのインストール先]/app/config/database.php
    Wrote [cakeのインストール先]/app/config/database.php
    
  • Modelの作成
  • What would you like to Bake? (D/M/V/C/P/Q)
    > M
    ---------------------------------------------------------------
    Bake Model
    Path: [cakeのインストール先]/app/models/
    ---------------------------------------------------------------
    Use Database Config: (test/default)
    [default] >
    Possible Models based on your current database:
    1. Server
    Enter a number from the list above, type in the name of another model, or 'q' to exit
    [q] > 1
    
    Given your model named 'Server', Cake would expect a database table named servers
    Do you want to use this table? (y/n)
    [y] >
    Would you like to supply validation criteria for the fields in your model? (y/n)
    [y] > n   #とりあえずValidateは設定しない
    Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n)
    [y] > n    #とりあえずリレーションは設定しない
    
    ---------------------------------------------------------------
    The following Model will be created:
    ---------------------------------------------------------------
    Name:       Server
    Associations:
    ---------------------------------------------------------------
    Look okay? (y/n)
    [y] > 
    
    Baking model class for Server...
    
    Creating file [cakeのインストール先]/app/models/server.php
    Wrote [cakeのインストール先]/app/models/server.php
    
  • Controllerの作成
  • What would you like to Bake? (D/M/V/C/P/Q)
    > C
    ---------------------------------------------------------------
    Bake Controller
    Path: [cakeのインストール先]/app/controllers/
    ---------------------------------------------------------------
    Possible Controllers based on your current database:
    1. Servers
    Enter a number from the list above, type in the name of another controller, or 'q' to exit
    [q] > 1
    ---------------------------------------------------------------
    Baking ServersController
    ---------------------------------------------------------------
    Would you like to build your controller interactively? (y/n)
    [y] >
    Would you like to use scaffolding? (y/n)
    [n] >
    Would you like to include some basic class methods (index(), add(), view(), edit())? (y/n)
    [n] > y
    Would you like to create the methods for admin routing? (y/n)
    [n] > y
    Would you like this controller to use other helpers besides HtmlHelper and FormHelper? (y/n)
    [n] >
    Would you like this controller to use any components? (y/n)
    [n] >
    Would you like to use Sessions? (y/n)
    [y] > 
    
    ---------------------------------------------------------------
    The following controller will be created:
    ---------------------------------------------------------------
    Controller Name:  Servers
    ---------------------------------------------------------------
    Look okay? (y/n)
    [y] > 
    
    Creating file [cakeのインストール先]/app/controllers/servers_controller.php
    Wrote [cakeのインストール先]/app/controllers/servers_controller.php
    
    Baking unit test for Servers...
    
    Creating file [cakeのインストール先]/app/tests/cases/controllers/servers_controller.test.php
    Wrote [cakeのインストール先]/app/tests/cases/controllers/servers_controller.test.php
    
  • Viewの作成
  • What would you like to Bake? (D/M/V/C/P/Q)
    > V
    ---------------------------------------------------------------
    Bake View
    Path: [cakeのインストール先]/app/views/
    ---------------------------------------------------------------
    Possible Controllers based on your current database:
    1. Servers
    Enter a number from the list above, type in the name of another controller, or 'q' to exit
    [q] > 1
    Would you like to create some scaffolded views (index, add, view, edit) for this controller?
    NOTE: Before doing so, you'll need to create your controller and model classes (including associated models). (y/n)
    [n] > y
    Would you like to create the views for admin routing? (y/n)
    [y] > y
    
    Creating file [cakeのインストール先]/app/views/servers/index.ctp
    Wrote [cakeのインストール先]/app/views/servers/index.ctp
    
    Creating file [cakeのインストール先]/app/views/servers/view.ctp
    Wrote [cakeのインストール先]/app/views/servers/view.ctp
    
    Creating file [cakeのインストール先]/app/views/servers/add.ctp
    Wrote [cakeのインストール先]/app/views/servers/add.ctp
    
    Creating file [cakeのインストール先]/app/views/servers/edit.ctp
    Wrote [cakeのインストール先]/app/views/servers/edit.ctp
    
    Creating file [cakeのインストール先]/app/views/servers/admin_index.ctp
    Wrote [cakeのインストール先]/app/views/servers/admin_index.ctp
    
    Creating file [cakeのインストール先]/app/views/servers/admin_view.ctp
    Wrote [cakeのインストール先]/app/views/servers/admin_view.ctp
    
    Creating file [cakeのインストール先]/app/views/servers/admin_add.ctp
    Wrote [cakeのインストール先]/app/views/servers/admin_add.ctp
    
    Creating file [cakeのインストール先]/app/views/servers/admin_edit.ctp
    Wrote [cakeのインストール先]/app/views/servers/admin_edit.ctp
    ---------------------------------------------------------------
    
    View Scaffolding Complete.
    
  • 動作確認
  • http://[cakeをインストールしたサイト]/servers

    Related posts:

    1. paginatorのSmarty化
    2. cakephp最初のコントローラー
    3. cakephpにsimpletest

    0 comments
    add to hatena hatena.comment (0) add to del.icio.us (0) add to livedoor.clip (1) add to Yahoo!Bookmark (1) Total: 2

    Leave a Reply

    返信をキャンセル

    google adsense

    カテゴリー

    • CentOS
    • php
      • cakephp
    • Windows
    • wordpress

    タグ

    cakephp CentOS munin php Windows wordpress yum
    Design by: Bingo - The Web Design Experts