我将cakePHP应用程序从v3.1.1更新到v3.1.2,在这段文章中我的所有路由和文件命名都已破坏。
v3.1.1 :
db_table = hotels_profiles(1to1正确调用它,如果 我有'酒店'表?)
ModelTable = HotelsProfilesTable
实体= HotelsProfile
Controller = HotelsProfilesController(适用于呼叫模式$ this-> Hotelsprofiles)
url = / hotelsprofiles / action
现在使用 v3.1.2 我需要重命名:
控制器到Hotelsprofiles,或将我的网址更改为hotels_profiles。
在呼叫模型的控制器中,我需要重命名
$ this-> Hotelsprofiles to $ this-> HotelsProfiles。
为什么呢?发生了什么?我以错误的方式写蛋糕约会?
请告诉我,如果我想在酒店表格中添加个人资料,我需要以哪种方式正确命名文件?
答案 0 :(得分:4)
url = / hotelsprofiles / action
默认情况下,此网址会查找文件:
src/Controller/HotelsprofilesController.php
根据问题正确命名文件:
src/Controller/HotelsProfilesController.php
^
该url仍将在不区分大小写的文件系统(windows,osx)上运行 - 但在区分大小写的文件系统(linux)上会失败。
因此问题的原因不是升级,而是将Windows(版本3.1.1)与非Windows(3.1.2 - 但版本无关)进行比较。
文档中详细介绍了conventions,但新手更容易使用bake来确保文件和样板代码符合CakePHP的期望:
-> bin/cake bake all HotelsProfiles
Welcome to CakePHP v3.1.2 Console
---------------------------------------------------------------
App : src
Path: /var/www/cakephp.dev/src/
PHP : 5.5.15-1~dotdeb.1
---------------------------------------------------------------
Bake All
---------------------------------------------------------------
One moment while associations are detected.
Baking table class for HotelsProfiles...
Creating file /var/www/cakephp.dev/src/Model/Table/HotelsProfilesTable.php
Wrote `/var/www/cakephp.dev/src/Model/Table/HotelsProfilesTable.php`
Baking entity class for HotelsProfile...
Creating file /var/www/cakephp.dev/src/Model/Entity/HotelsProfile.php
Wrote `/var/www/cakephp.dev/src/Model/Entity/HotelsProfile.php`
Baking test fixture for HotelsProfiles...
Creating file /var/www/cakephp.dev/tests/Fixture/HotelsProfilesFixture.php
Wrote `/var/www/cakephp.dev/tests/Fixture/HotelsProfilesFixture.php`
Bake is detecting possible fixtures...
Baking test case for App\Model\Table\HotelsProfilesTable ...
Creating file /var/www/cakephp.dev/tests/TestCase/Model/Table/HotelsProfilesTableTest.php
Wrote `/var/www/cakephp.dev/tests/TestCase/Model/Table/HotelsProfilesTableTest.php`
Baking controller class for HotelsProfiles...
Creating file /var/www/cakephp.dev/src/Controller/HotelsProfilesController.php
Wrote `/var/www/cakephp.dev/src/Controller/HotelsProfilesController.php`
Bake is detecting possible fixtures...
Baking test case for App\Controller\HotelsProfilesController ...
Creating file /var/www/cakephp.dev/tests/TestCase/Controller/HotelsProfilesControllerTest.php
Wrote `/var/www/cakephp.dev/tests/TestCase/Controller/HotelsProfilesControllerTest.php`
Baking `index` view file...
Creating file /var/www/cakephp.dev/src/Template/HotelsProfiles/index.ctp
Wrote `/var/www/cakephp.dev/src/Template/HotelsProfiles/index.ctp`
Baking `view` view file...
Creating file /var/www/cakephp.dev/src/Template/HotelsProfiles/view.ctp
Wrote `/var/www/cakephp.dev/src/Template/HotelsProfiles/view.ctp`
Baking `add` view file...
Creating file /var/www/cakephp.dev/src/Template/HotelsProfiles/add.ctp
Wrote `/var/www/cakephp.dev/src/Template/HotelsProfiles/add.ctp`
Baking `edit` view file...
Creating file /var/www/cakephp.dev/src/Template/HotelsProfiles/edit.ctp
Wrote `/var/www/cakephp.dev/src/Template/HotelsProfiles/edit.ctp`
Bake All complete.
通过这种方式,您可以使用约定,而不仅仅是文件名约定:
...
$this->set('hotelsProfiles', $this->paginate($this->HotelsProfiles));
^
...
您可能不需要烘焙代码 - 但使用烘焙只需查看或使用烘焙代码即可回答您的许多问题。请注意问题的不同之处:
$this->HotelsProfiles
/hotels-profiles/view/1
- 但确切的格式取决于默认路由类configured in the routes file。