帮助蛋糕控制器

发布于 2024-09-01 07:33:02 字数 109 浏览 4 评论 0原文

我们有一位外包工程师致力于快速删除数据库中列出的项目的功能。他说代码很难,因为缺少“控制器”。是否有像蛋糕中那样的每个功能都有一个预加载的控制器,或者他期望有一个控制器来实现我们还没有的功能,这很奇怪吗?

We had an outsourced engineer work on a quick feature DELETING items listed in our database. He says that the code is difficult because the "controller" is missing. Is there a pre-loaded controller for every function like that in cake, or is it weird that he is expecting a controller to be there for a feature we didn't have yet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

李不 2024-09-08 07:33:02

有一个通用的 AppController,但实际上它更像是一个抽象类(您通常从中派生其他控制器)。

他期待一个控制器并不奇怪——毕竟,你将无法调用模型中的方法(这就是我猜测你正在执行删除的方式),除非你有一个控制点打电话给他们。在这种情况下,控制点是控制器。

所以你可以创建一个控制器。下面是一个可以开始的模板:

class SomeController extends AppController {
 function delete() {
  $this->Some->delete();
 }
}

然后访问 /somes/delete (记住,URL 通常是 /controller/action)。

现在,他可能正在谈论 Cake Bake CLI 应用程序。这将获取您的数据库表,并引导您完成应用程序的初始基本设置。一般来说,它为 CRUD 操作创建一个基本框架。

无论哪种方式,您都需要创建一个控制器(手动或通过 Bake)。

There is a generic AppController, but that's more of an abstract class in practice (you generally derive your other controllers from that).

It's not that weird at all that he's expecting a controller -- after all, you won't be able to call methods in the models (which is how I'm guessing you're doing delete) unless you have a point of control to call them from. In this case, the point of control is the controller.

So you can just create a controller. Here's a template to start from:

class SomeController extends AppController {
 function delete() {
  $this->Some->delete();
 }
}

Then access /somes/delete (remember, URLs are generally /controller/action).

Now, he could be talking about the Cake Bake CLI app. That will take your DB tables, and walk you through an initial basic setup for your app. Generally it creates a basic skeleton for CRUD actions.

Either way, you need to create a controller (manually, or via Bake).

夏有森光若流苏 2024-09-08 07:33:02

当您使用蛋糕烘焙功能时,它会为您创建所有控制器。当您不使用它时,您需要手动创建它们。一开始就制作所有控制器是没有意义的,只有当你真正要编写它们时才制作它们会很好。

When you use the Cake bake function, it'll create all the controllers for you. When you don't use it, you'll need to create them manually. It makes no sense to make all the controllers at the begin, just make them when you really gonna write them would be good.

还在原地等你 2024-09-08 07:33:02

如果您在访问页面时 CakePHP 中没有控制器 (http://www.youraddress.com/Newfeature )您收到缺少控制器错误:

错误:找不到 NewfeatureController。

错误:在文件 app\controllers\newfeature_controller.php 中创建下面的类 NewfeatureController

如果没有控制器,您将无法从数据库中获取或删除数据 - 了解模型-视图-控制器。您不需要仅在 CakePHP 中的静态页面使用控制器。

If you do not have a controller in CakePHP when you visit a page (http://www.youraddress.com/Newfeature) you receive a missing controller error:

Error: NewfeatureController could not be found.

Error: Create the class NewfeatureController below in file: app\controllers\newfeature_controller.php

You cannot get or delete data from the database without controllers - Understanding Model-View-Controller. You do not need the controller only for static pages in CakePHP.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文