views:

38

answers:

3

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.

A: 

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.

GuidoH
+1  A: 

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).

Travis Leleu
we werent "doing" delete at all in this new environment with cake- thats why i thought it was odd he was expecting the controller
adam
A: 

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.

bancer