Tuesday, November 12, 2013

Re: Some talk about complex Applications with CakePHP

Thank you for your answer.
I know the problem is on my code, that's why I came here to ask that.
I use cake for almost 2 years now, and everywhere I look on the internet, I see people writing bunch of codes on controllers. I never really seen an application really active record oriented with Cake (Maybe It's my mistake, I didn't tried to find them too, just never seen one).

What I gave you was just a really simple example, of course, it's not a real code, and not as big as it would be on a real context.
I know it should be on my model, however, as I said, if that code was on my model, I wouldn't be able for example to use the paginate with it. Then I would need to write a little bit of that wouldn't be structured the same way of the rest of the application (which for me is worse than growing the controllers)


Thank you again.. appreciate your time helping me

On Monday, November 11, 2013 8:35:23 AM UTC, Florian Krämer wrote:
The issue is your code not the framework. ;) No matter what framework you're going to use, if you put all your code into controllers this won't work out very well in Zend or Symphony as well. Also Cake does not force you to do anything in a completely strict way, everything can be changed but you won't make your live more easy by not following the conventions. Cake definitely doesn't force you to put code into controllers, that's plain wrong. 

I guess you don't do unit testing, which is not good. Unit testing is a must have, specially for big projects. I guess that because of your heavy controllers, in fact controllers should by tiny and models fat. Models have plenty of advantages, they can be shared between different controllers and shell scripts while a controller method can't be shared that way. Also testing models is easier than testing controllers. As rchavik already pointed out lookup costume find methods in the book. If properly build it should be also possible for you to create submodules, plugins for parts of your applications that can be shared. Check the https://github.com/cakedc/comments comments plugin for example. It encapsulates all the comment code in a plugin and can be implemented within ~1-2 hours in any application.

Your code piece here that you put in the controller should be in fact a model method. You can always pass args from the request object to a model method. Even if the method can't be shared with another application for some reason, it should go into the model.

If you want objects returned in 2.0 there is a plugin for that as well, just google it.

If you want you can do a training session with us http://www.cakedc.com/training, besides basic Cake lessons we can also have a class about design patterns and best practice as well.

On Sunday, November 10, 2013 3:51:26 PM UTC+1, Ighor Martins wrote:

This will be an application, with a custom software design. And CakePHP almost force us to follow it's strict design. At the same time, this platform won't require that enough for me to move to something like Zend. 

So, I have knowledge about Cake, but I don't really know the best practices to develop big applications with Cake. Only normal websites.
Sometimes I even feel like cake almost force us grow our controllers code instead of models, and that's what's making me sad.
To give you an example:
I normally do things like this on controllers:
$this->MyModel->find('all', array(
  'contain' => array(
     'SecondLevelThing' => array(
       'ThirdLevelThing' => array(
          'conditions' => 'thirdLevelThingConditions'
       ),
       'conditions' => 'secondLevelThingConditions' 
     )
  )
));

I know CakePHP 3 will be there in a while to solve some of these issues, and it will finally return objects instead of arrays :)
but for now, how is the best design pattern to follow with CakePHP when developing big applications without fighting against the framewok?

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: