1
votes

I have been doing ASP.NET MVC at university this year and only touched on some of the basic principles but absolutely loved it. Having been a PHP fan for over 6 years I planned to use something like CakePHP to continue using the MVC pattern in my work.

However I have a few questions as their are MASSIVE differences between the two frameworks:

1.) How would someone do something similar to LINQ where when ever you do your actionresult you can simple build a query and then return it to the view?

2.) Do repositories exists in Cake? I love these in ASP.NET and the ability to create custom methods for your database logic and then call them anywhere.

3.) Confusion with the model. In ASP.NET I could have a single model deal with lots of tables and then call any table or combination of tables with ease. In Cake it seems you have a model per table???

2

2 Answers

2
votes

CakePHP comes with its own persistence API, whereas in ASP.NET MVC you can (and have to) use something else of your choosing.

1) There isn't an equivalent to LINQ in CakePHP, but you can still construct queries pretty easily.

2) CakePHP's models can have functions attached, and they also have something called Behaviors which are neat.

3) CakePHP's persistence system associates one model with a persistent entity (such as a table). I'm not sure I can give a better answer with out a more specific example.

I did a lot of PHP work before I moved on to .NET. While I still like ASP.NET MVC or RoR better (mostly because they are better frameworks and languages, IMHO, than PHP), the few projects I did in CakePHP were very pleasant.

0
votes

I am not familiar with ASP.NET, but I can answer some of these questions.

  1. LINQ... I am not familiar with. If you could give a simple example, I could explain if there is a similar method in Cake.
  2. The Repositories you refer to can be Behaviors as mentioned by @HackedByChinese. However, you may have better results by adding functions to the app_model.php file. All models in the app can access any function in the app_model.php file which can be added to your app directory.
  3. Yes. CakePHP is designed with code separation in mind. The idea behind a single table per model allows you build a very FAT model and still keep it manageable. You build all of the relationships, validation, and other model specific code into each model. Then when something goes wrong with Users for example, you know you need to look in the Users model. This can be overridden, you can put all of the model access into a single model file if you want, but it makes the code sloppy. If you are going to do that, why use Cake? Just put all of your model code in Model.php, all of your controller code in Controller.php and all of your view code in View.php and call it good. I think you would agree that is not the structure for very readable nor extensible code.