1

在 CakePHP 中为通用控制器、模型和视图开发多个应用程序的最佳方法是什么?有人想开发这种类型的应用程序吗?

4

2 回答 2

1

这就是插件的用途——您可以创建一组控制器、模型、视图(以及更多),将它们打包在一起,然后将它们部署到所有应用程序中。有关详细信息,请参阅CakePHP 食谱

使用这种方法会为您的 url 添加一个额外的插件部分,这可以通过提供路由规则来修复。

于 2012-09-26T10:12:05.840 回答
-1

有两种方法可以做到这一点。

  1. 将常用的控制器、模型和视图打包为插件
  2. 将您的通用代码放在一组单独的目录中,并App::build()在 bootstrap.php 中使用以包含这些目录:
 App::build(array(
      'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
      'models' =>  array('/full/path/to/models/', '/next/full/path/to/models/'),
      'views' => array('/full/path/to/views/', '/next/full/path/to/views/'),
      'controllers' => array('/full/path/to/controllers/', '/next/full/path/to/controllers/'),
      'datasources' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
      'behaviors' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
      'components' => array('/full/path/to/components/', '/next/full/path/to/components/'),
      'helpers' => array('/full/path/to/helpers/', '/next/full/path/to/helpers/'),
      'vendors' => array('/full/path/to/vendors/', '/next/full/path/to/vendors/'),
      'shells' => array('/full/path/to/shells/', '/next/full/path/to/shells/'),
      'locales' => array('/full/path/to/locale/', '/next/full/path/to/locale/')
  ));
于 2012-09-26T10:22:36.757 回答