v3.1.1 的 CakePHP 路由不适用于 v3.1.2,可能是错误的约定?

CakePHP routes of v3.1.1 don't work with v3.1.2, maybe wrong conventions?

我将我的 cakePHP 应用程序从 v3.1.1 更新到 v3.1.2,在此段落中,我的所有路由和文件命名都失效了。

v3.1.1:

db_table = hotels_profiles (1to1 its correctly call it in this way if i have 'hotels' table?)

ModelTable = HotelsProfilesTable

Entity = HotelsProfile

Controller = HotelsProfilesController (for call model $this->Hotelsprofiles)

url = /hotelsprofiles/action

现在 v3.1.2 我需要重命名:

Controller to Hotelsprofiles, or change my url to hotels_profiles.

In controller for call model i need to rename

$this->Hotelsprofiles to $this->HotelsProfiles.

为什么?发生什么事了?我把蛋糕约定写错了?

请你告诉我,如果我想向酒店添加配置文件,我需要在哪种模式下以正确的方式命名文件table?

升级不是问题的原因

url = /hotelsprofiles/action

默认情况下,url 将查找文件:

src/Controller/HotelsprofilesController.php

根据问题正确命名文件:

src/Controller/HotelsProfilesController.php
                     ^

url 仍可在不区分大小写的文件系统(windows、osx)上运行 - 但在区分大小写的文件系统(linux).

所以问题的原因不是升级,而是将 windows(版本 3.1.1)与 not-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));
                                                          ^
...

您可能不需要 baked 代码 - 但使用 bake 只需查看或使用 baked 代码即可回答您的许多问题。注意问题的不同之处:

  • $this->HotelsProfiles
  • 生成的 urls 将默认采用 /hotels-profiles/view/1 的形式 - 尽管确切的形式取决于默认路由 class 即 configured in the routes file.