I work as a PHP developer for a small company, the previous developer used cakephp for a couple of sites and I despise having to work on them. I don’t know whether this is down to any combination of: My lack of knowledge of cakephp, the way the previous developer used cakephp or cakephp itself…
However some of the ways things are done (Which seem to stem from the framework, not the previous developer…) seem to be done in really limiting ways.
My main irk is the way it handles models… Setting up the models, defining the relationships I have no problem with, and makes perfect sense… however…
what it calls a “Model” is actually a data mapper of sorts…
For example:
$product = $this->Product->findAll( null, null, 'category_id ASC' )
Is $this->Product a “Model”? I’d argue not… it seems to be a datamapper to me. It isn’t related to a single product in the system, but it’s what CakePhp refers to as a model. Which brings me to my next issue:
The data objects are simple associatve arrays
Once the product has been loaded from the DB it loads it into a simple array… not an object. Which means there’s no way to define a function on a model? Seriously? this is basic functionality for any model isn’t it? I should be able to call $order->getTotal(); which adds subtotal, delivery and the tax for the user’s country? This also has the problem of not being able to use typed parameters (or any kind of type checking) anywhere that data objects are passed around.
Calls to Model->expects()
This is something which I can’t find any proper documentation for but it looks like this:
$this->Product->expects ( array ( 'Image', 'Tag' ) );
What it does it set up the relations which are populated when the product is fetched. These calls are littered throughout controllers. why does the controller have any knowledge of the inner workings of the model?. What this also does, is make the view used by the controller unusable anywhere else unless the models being passed to it are set up the same way elsewhere. Why doesn’t the view require a model, then the model deal with its own relations (Even a simple ActiveRecord approach would be better). I can see why they’re needed… which is to work around the limitations of using arrays as data objects, but this just goes to show why that’s a bad idea in the first place.
I really don’t like the way it does views either, but that’s not nearly as annoying as the way it handles models.
I don’t understand how such a popular MVC framework can get the basics so wrong.
Sorry this is more of a rant than a question and I fully admit it may my understanding that’s wrong and welcome people pointing me in the right direction if that’s the case.