CakePHP中文手冊 翻譯 Cake命名規則

2021-09-05 15:34:38 字數 2657 閱讀 6764

沒錯,規則。根據thefreedictionary:

1.一般約定或者對特定的實踐或態度的認可:根據規則,北方一直在地圖的最上方。

2.在乙個組裡,乙個廣泛遵守的實踐或和過程,特別能促進社會互動;一種習慣:握手的規則。

3.一種廣泛被使用或被接受的裝置或者技術,例如在**,文學或者繪畫裡:旁白的戲劇規則。

cake

的規則會變魔法,稱之為自動魔法。

cake

讓你的生產率提高到乙個令你害怕的水平,但又不失靈活性。

cake

的規則確實非常簡單,而且直觀。他們是從最佳實踐裡提煉出來的,而這些最佳實踐是

web開發人員在

web開發領域裡多年使用的實踐。

類,那麼在cake裡,它的檔案應該命名為my_nifty_class.php。因此如果你找到乙個小片段,你會自動知道:

1.如果它是乙個命名為kissesandhugscontroller的controller,那麼它的檔名必須為kisses_and_hugs_controller.php(注意檔名中的_controller)。

2.如果它是乙個名為optionvalue的model,那麼它的檔名必須為option_value.php.

3.如果它是乙個名為myhandycomponent的元件,那麼它的檔名必須為my_handy.php(在檔名裡不需要_component)

4.如果它是乙個名為besthelperever的helper,那麼它的檔名必須為best_heler_ever.php.

1.model的類名是單數

2.model類名中,單個單詞的model為大寫,多個單詞的model是大寫的駱駝峰。

例項: person, monkey, glassdoor, lineitem, reallyniftything

3.多對多的join表應該命名為: 按字母排列的第乙個表的複數_按字母排列的第二個表的複數.例如: tags_users

4.model檔名使用乙個小寫的帶有下劃線的語法。

例項: person.php, monkey.php, glass_door.php, line_item.php, really_nifty_thing.php

5.與model相關聯的表也使用小寫的帶有下劃線的語法,但是他們是複數的。

例項: people, monkeys, glass_doors, line_items, really_nifty_things

cakephp的命名規則意味著流線型的**建立,並且讓**更加具有可讀性。如果你想他遵循你的方式,你可以覆寫它。

1.model名:在你的model定義裡設定$name變數.

2.與model相關的資料庫名:在你的model定義裡設定$usetable變數.

1.controller名為複數

2.對於單個詞的controller,類名為大寫,多個詞的為大寫的駱駝峰。而且controller類名以'controller'結尾。

例項: peoplecontroller, monkeyscontroller, glassdoorscontroller, lineitemscontroller, reallyniftythingscontroller

3.例項

: people_controller.php, monkeys_controller.php, glass_doors_controller.php, line_items_controller.php, really_nifty_things_controller.php

4.對於保護成員的可見性,controller動作名應該預加乙個'-'.

5.對於私有成員的可見性,controller動作名應該預加乙個'--'.

1.view在他們顯示的動作後命名。

2.在動作名後命名view,小寫。

例項: peoplecontroller::worldpeace()

期望乙個在

的view

。monkeyscontroller::banana()

期望乙個在

的view。

你可以在動作的結尾,呼叫$this->render('沒有.thtml的view檔名')來強制乙個動作render乙個指定的view,

1.中類myhelperhelper 擴充套件了helper

使用var $helpers = array('html','myhelper')將它包含在controller裡;在view裡,你可以使用$myhelper->methods()l來訪問。

1.裡,類mycomponentcomponent擴充套件了物件。

使用$components = array('mycomponent')將它包含在controller裡。在controller裡,使用$this->mycomponent->method()來訪問

vendor不遵循任何規則,原因非常明顯:他們是第三方的**,cake沒有對它們的控制權力。

last updated:2006-12-05

CakePHP中文手冊 翻譯

0.宣告1.前言2.介紹cakephp 3.基本概念 4.安裝cakephp 5.配置 6.scaffolding 7.model 8.controller 9.view 10.component 元件 11.helper 12.cake的全域性變數和函式 13.資料驗證 14.外掛程式 15.訪問...

CakePHP中文手冊 翻譯

0.宣告1.前言2.介紹cakephp 3.基本概念 4.安裝cakephp 5.配置 6.scaffolding 7.model 8.controller 9.view 10.component 元件 11.helper 12.cake的全域性變數和函式 13.資料驗證 14.外掛程式 15.訪問...

CakePHP中文手冊 翻譯 外掛程式

cakephp 允許你建立乙個controller,model以及view的組合,並且可以將他們發布為乙個已打包的應用程式外掛程式,以至在cakephp應用程式中,其他可以使用它。在你的乙個應用程式中,有乙個優秀的使用者管理模組,簡單的blog或web service模組嗎?將它打包為乙個cakep...