Page 1 of 1

Trying to comprehend MVC

Posted: Tue Sep 22, 2009 4:44 pm
by thinsoldier
Trying to comprehend MVC here.

i've got a part of a site that does 3 things

show search form
show search results
show full record details

I imagine the urls like:
site.com/index.php/realty/search/
site.com/index.php/realty/results/4/ (4 = pagination page number)
site.com/index.php/realty/details/127/ (127 = record id)

I get the basic idea of setting up a _controller_ for that.
1 controller,
a model for pulling the data from mysql,
possibly a separate model/business logic if the search logic is complicated
and 3 methods/actions in the controller to show the 3 "pages",
and 3 templates

But what if one of those 3 actions actually does a few more things?

site.com/index.php/realty/details/127/print/ (show a print-friendly template)
site.com/index.php/realty/details/127/share/ (show a form where the visitor can e-mail a link to his friends)
site.com/index.php/realty/details/127/sharesent/ (show a confirmation page indicating that e-mail was sent)

Do I make another controller just for the 'details' part and somehow put that controller inside the first controller which is already inside of a front-controller?

Re: Trying to comprehend MVC

Posted: Tue Sep 22, 2009 5:29 pm
by Christopher
It is not clear to me which is the controller: realty or details ?

I tend to do the following (implying that realty is the controller and details, print, etc. are methods):

site.com/index.php/realty/details/127/
site.com/index.php/realty/print/127/
site.com/index.php/realty/share/127/
site.com/index.php/realty/sharesent/127/

But details could also be the controller (and realty the module).

Re: Trying to comprehend MVC

Posted: Tue Sep 22, 2009 8:56 pm
by josh
Actions should perform 1 task, if that action is doing 3 tasks, that action could probably be moved into it's own controller and that method broken up.

Putting the id before the action like /details/127/print is a cool idea, it wouldn't hurt anything and may even make the site easier to crawl in a logical order, or easier for humans to jump from action to action by hand editing the URLs.

I tend to do it the same as Christopher tho, because on the other hand the users may want to edit the ID and remain at the same action, rather then edit the action and remain at the same ID, it would just depend on the user's preference I would say.

Re: Trying to comprehend MVC

Posted: Wed Sep 23, 2009 9:50 am
by thinsoldier
I think the "module" thing is what's getting me.

So with "modules" then index.php/realty/details/127/
would be FrontController/module/controller/id/
allowing for
index.php/realty/details/view/127/
index.php/realty/details/print/127/
index.php/realty/details/share/127/

index.php/realty/search/simple/
index.php/realty/search/advanced/
index.php/realty/search/results/

index.php/user/manageAccount/viewDetails/
index.php/user/manageAccount/editDetails/
index.php/user/favourites/list/
index.php/user/favourites/add/
index.php/user/favourites/edit/
index.php/user/favourites/delete/
index.php/user/savedsearches/listRSS/
index.php/user/savedsearches/listWeeklyEmail/
index.php/user/newsletter/subscribe/
index.php/user/newsletter/unsubscribe/

index.php/newsletter/..? um... newsletter again? /unsubscribe/
index.php/newsletter/..? um... newsletter again? /subscribe/
index.php/newsletter/..? um... newsletter again? /archives/
index.php/newsletter/..? um... newsletter again? /cron_send_emails/
index.php/newsletter/..? um... newsletter again? /cron_cleanup/

Does it sound like I'm thinking in the right direction?
( :( if only one of these damned frameworks would run on my server. )

Re: Trying to comprehend MVC

Posted: Wed Sep 23, 2009 4:21 pm
by Christopher
thinsoldier wrote:Does it sound like I'm thinking in the right direction?
Yes.
thinsoldier wrote:( :( if only one of these damned frameworks would run on my server. )
Are you PHP4 ?

Re: Trying to comprehend MVC

Posted: Wed Sep 23, 2009 5:12 pm
by thinsoldier
no, but really really really close

what about this part: index.php/newsletter/..? um... newsletter again? /unsubscribe/
would I really have to put 'newsletter' in that spot?

I'm guessing real frameworks have a way to indicate some sort of assumed default controller based on the module name in special cases.

Re: Trying to comprehend MVC

Posted: Thu Sep 24, 2009 1:39 am
by Christopher
Yes, you can define a default module, controller and method.

Re: Trying to comprehend MVC

Posted: Wed Oct 07, 2009 9:26 am
by thinsoldier
Making it a point to try out skeleton before the start of next week and zend framework before the end of the month.

Have anything "beginner's starting point"-like I should read first on skeleton?

For the site I'll be trying to re-create I'm pretty sure for every user accessible *.php file will be a "module" in framework terms... I think... ok, I'm not so sure.

Re: Trying to comprehend MVC

Posted: Thu Oct 08, 2009 6:11 pm
by Christopher
thinsoldier wrote:Making it a point to try out skeleton before the start of next week and zend framework before the end of the month.

Have anything "beginner's starting point"-like I should read first on skeleton?
There are some docs. And the Blog example is pretty standard.
thinsoldier wrote:For the site I'll be trying to re-create I'm pretty sure for every user accessible *.php file will be a "module" in framework terms... I think... ok, I'm not so sure.
I think you have the wrong idea of 'module'. I think of each module as a mini-application. The Admin area if a website is the most common use fora module, so all of the URLs start with "example.com/admin/". A module give you an separate directory tree that has its own controllers/models/views directories.