Re: How to implement CakePhp in an external site?
Hi!
In the case you described, how can I access a model 1 from model 2
when there's no association between them? loadModel is a controller
method, isn't it?
Thank you a lot
On Jan 14, 7:50 am, LunarDraco <mdc...@gmail.com> wrote:
> From your description you've given, I would say your placing your code
> in the wrong place or in the wrong level of the MVC. (Model, View,
> Controller) The order of this acronym also implies importance about
> where you should be putting your code. Most of your code should be in
> the Model, the business logic, calculation and manipulation of data.
> The view is next in the list as we need to format all the data we just
> finished manipulating. The Controller should have the least amount of
> code as its main purpose is to tie the user requested events to the
> business logic and control which model functions should be called, and
> to pass the already calculated data from the models to the view.
>
> Think of them in this manner Models return Data, Controllers return
> Views.
>
> Often new developers to the MVC development structure end up building
> apps where most of the code lives in the controllers and the models
> are bare and relying on the core functions inherited from the base
> model. They quickly find themselves in your position where you want to
> use some code from a function in Controller2 to manipulate some data
> from within Controller1 and find that it is very difficult to call on
> another controller.
>
> Models on the other hand are available to use from any other model in
> the structure. Code put in a model can be called by both other models
> as well as by the controllers.
>
> Do your best to make your Models Fat with your data manipulation and
> your Controllers Thin and you'll find the MVC framework is a great
> design.
>
> So your simple case might look more like this:
> class Model2
> {
> belongsto Model1
> function getComplexData(){
> $this->find(something);
> $this->Model1->customfunction();
> //combine and play with data returned from model1 and model2
> }
>
> }
>
> class Controller 1
> {
> function func1(){ //No data manipulation in the controller.
> $data = $this->Model2->getComplexData();
> $this->set(data); //pass data to view for display
> }
> }
>
> On Jan 13, 6:54 am, Axel <the...@gmail.com> wrote:
>
> > Hello,
>
> > I'm starting to use CakePHP and it looks very nice. However, its main
> > prupose seems to be management of relation with database and
> > subsidiaries of these actions (showing results, etc...)
>
> > In my case, I would like to create a site where I will have to do
> > calculations with the data, sorting, etc... and these are using many
> > method in different controllers, like :
>
> > Model 2 belongsto Model 1
>
> > class Controller 1
> > {
> > function func1(
>
> > //recover data from model 1
> > // recover data from model 2 via loadModel
>
> > //Use function func2 from Controller 2
> > // combine and play with data returned from func2 and from
> > Model1
> > (...)
> > )
>
> > }
>
> > It's the simplest case and it can vary a lot. The problem is that I
> > need requestAction to load func2 (is it ?). So, as it is very slow, I
> > was thinking of using my own external structure (which is already
> > built :D) and inside of this, doing some includes that recover the
> > data of model1 and model 2, play in my own stuff, pass it inside of
> > func2, play it ...etc.. etc...
> > 1) it is easier in order to play with the values
> > 2) no needs of request actions..etc
>
> > I don't know if how to do that, and if it's a good way to use it.
>
> > What do you think about it? Where can I put my fileS?
>
> > Thank you
>
> > PS : is this a help forum ? Hope i'm not in the wrong place.
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home