Controllers?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

My own FC is just under 100 lines. How'd they get to 100's? I would have thought it a simple enough pattern to implement - unless they're throwing in all but the kitchen sink...;)
User avatar
dbevfat
Forum Contributor
Posts: 126
Joined: Tue Jun 28, 2005 2:47 pm
Location: Ljubljana, Slovenia

Re: Controllers?

Post by dbevfat »

Ree wrote:I think the FC should be universal enough to accept ALL request data. I guess you could pass the whole $_REQUEST to the front controller. Then from the $_REQUEST 'data soup' it would determine which action should be taken and then some page controller would do its job. Could it be something like that? Or maybe I'm wrong here? I guess you could also pass some Request object instead of $_REQUEST.

Yes, it's usually a good thing to abstract things to some level. If you use an object to encapsulate the request, you immediately achieve at least two things:
- decoupling the application from the environment; you can initialize the Request object from $_GET, $_POST or $_REQUEST or maybe even from command line arguments. You just have to use a different Request object that implements the same interface.
- you get a point in the application where you can apply filters; cleaning the added slashes on systems with magic_quotes=On is a good example.

Maugrim: I think this is partially already an answer to what you said. They weren't aiming for a single project (or a single user) front controller, they tried to make it flexible yet simple. And since you can't have a very flexible system that's not complex, you have to agree to some level of complexity. I think they did a good job.

I'd actually like to hear an outsider opinion on their FC, so if any of you is willing to take a look at it, you're welcome to share comments.

@Roja
You're right, it is more a 'baseline framework for pure OOP development' then a Front Controller. And I understand why it seems funny to you, it actually does to me, too. When I think about it, it was really not a good pointer for a simple FC, even though it could be extracted from their skeleton code ...

I wonder if the original poster of that thread ever got to read it? Did he even bother to read it after 3 posts? :D
Btw, don't you like DokuWiki, or why did you frown when I mentioned it?

Regards
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Re: Controllers?

Post by Roja »

dbevfat wrote:I'd actually like to hear an outsider opinion on their FC, so if any of you is willing to take a look at it, you're welcome to share comments.
I'm really not sure why McGruff didn't dig in ("havent looked at it in detail").. he was a contributor to the discussion there, and the class had tests included. Granted, they don't seem to test every aspect of the code, but I would have thought he would have contributed that as feedback to improve it.

If he did, I suspect he'd see why we're discussing the size issue (yet again). For him to out-of-hand pass on it, especially commenting on me being "naive" (when I've read through the code in question) seems odd for him. Perhaps he'll be more interested in commenting in depth once he's read it. I really don't see how anyone can see it as anything but far beyond a simple FC. To not do so does it a disservice, imho.

You'll notice that my comments didn't actually call the code bloated, just aimed at the wrong problem. I think many of the classes are actually fairly dead-on, if they are a little too 'boilerplate' - but such a thing is exactly what they were aiming for.
dbevfat wrote:@Roja
You're right, it is more a 'baseline framework for pure OOP development' then a Front Controller. And I understand why it seems funny to you, it actually does to me, too. When I think about it, it was really not a good pointer for a simple FC, even though it could be extracted from their skeleton code ...

I wonder if the original poster of that thread ever got to read it? Did he even bother to read it after 3 posts? :D
Btw, don't you like DokuWiki, or why did you frown when I mentioned it?
Unfortunately, it often occurs that a good question doesn't get much followup from the poster. The user in question never posted again, so I'd say its likely that he didn't read the "answer". I could make a snide comment about him not wanting to wade through 16 pages to GET to the answer, but it happens here on a daily basis too - without the 16 pages of high-level discussion. ;)

I'm the very first person to say I'm biased against Sitepoint's forums. I've commented about it in my blog, and I have been consistent in my comments about them. Nevertheless, some things are universal, and ask-and-forget seems to be one of them. Really don't understand it myself. <shrug>.

As to DokuWiki, its a wiki comment in general. I actually find wiki's to be tremendously overhyped. The 'wins' and successes of things like Wikipedia are truly the exception to the rule, and the general rule (again, my opinion only) is that you trade *all* design and style in exchange for a minor amount of additional feedback/contribution. Going a step further, its an extremely rare combination of needs and benefits that results in wiki's being exactly the right choice. For something as static and well-defined as patterns, I'd argue strongly that the design and style (readability, accessibility, etc) are far more important.

Like so many things, I'll wait and see. I've been wrong before - I thought gmail and AJAX was uber-hype, until I used it extensively, and now I see exactly why its changing the world of web programming.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Re: Controllers?

Post by McGruff »

Ree wrote:I guess you could pass the whole $_REQUEST to the front controller. Then from the $_REQUEST 'data soup' it would determine which action should be taken and then some page controller would do its job. Could it be something like that?
Yes - almost. Strictly speaking a FrontController doesn't hand over to a PageController, although it could be something very like a PageController. They're both input controllers, ie at the top of the tree.

Typically, the FC is watching one of the GET vars, and can use the value to dynamically invoke a class or lookup a config file (the former being preferred).

I'd certainly use a Request object. "Hide presentation layer specific details from the domain" is a standard refactoring.

More FC info here: http://www.phpwact.org/pattern/front_controller
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

Typically, the FC is watching one of the GET vars, and can use the value to dynamically invoke a class or lookup a config file (the former being preferred).
Does that mean each request by the user must have a GET variable?

It seems quite nice in theory, but a simple example would really be helpful to me. Say, a very simple scenario of database record management (let's call that Product management). The actions (requests) a user could perform could be these:

- Insert a new product (fill in a form)
- Update an existing product
- Delete existing products (all selected products are deleted)

How would you implement controllers (starting with FC) to handle these requests?
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

If you drop by here we might be able to create an example using TDD.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

Implementing a basic FC is very simple, but for example if you consider that a FC must use also additionally patterns to allow future upgrades and changes, then i suppose that you will make more then 100 lines.

For example an OOP concept tells you that is better to make a factory instead of derivating (i hope that this is the proper word, or extending) and implementing this may take additional lines (not many, but will increase the overall number of FC module lines).
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

You do realise this thread is 9 months old dont you?
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

I think that is not important when this thread has been started, is important what information provides, no matter when this information has been added. You should know better this idea since you are an admin. I also think that you post an useless replay and is hard for me to understand why you post must be viewed by all readers of this area. :twisted:
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

fastfingertips wrote:I think that is not important when this thread has been started, is important what information provides, no matter when this information has been added. You should know better this idea since you are an admin. I also think that you post an useless replay and is hard for me to understand why you post must be viewed by all readers of this area. :twisted:
The reply was only posted because we have rules against necrothreading.
Locked