[wp-hackers] Options for Controller - Views

Otto otto at ottodestruct.com
Fri Nov 20 15:20:11 UTC 2009


On Fri, Nov 20, 2009 at 9:08 AM, Jacob Santos <wordpress at santosj.name> wrote:
> Yes, it is completely possible to use the template redirect hook as the
> controller, but in this instance the reason is that you would have to have
> the majority of your controller logic in there or abstract it out into
> separate functions to keep the function from becoming massive. So if I did
> the extra work and allowed for the Rewrite to call the function directly, I
> don't have to worry about all of the logic myself or I could have a mile
> long function for all of the points of the project.
>
> I will take for instance one project where I replaced two sections and
> provided for two other sections. Yeah, I didn't use the add_rewrite_rule and
> I may add it in there just to see how well it works and if it removes the
> need for the title hack.

Okay, but I guess this is where we're differing here. WP_Rewrite
doesn't call *anything* directly. That's not its function at all. It
doesn't decide what gets displayed, it's not a controller and it's not
meant to be.

> Alas, I believe I went too far in to why I need it and lost the point. The
> point is that WP_Rewrite should not be doing the mod_rewrite and the
> controller, I think the programmer that architect the code thought, "What
> better rewriter is there other than mod_rewrite? The answer, none. Lets use
> it and force the person to create other files for their extensions."

WP_Rewrite isn't supposed to be a controller in that sense. It's just
a URL parser. That's it. All WP_Rewrite does is convert the URL into
query_vars.

Other parts use those query vars to determine what to do and where to
go. In particular, WP_Query uses the query_vars to determine what
content to pull out of the DB, and then it sets flags accordingly. The
template-loader then uses those flags to determine what template
(view) to pass control off to. Everything is nice and separated.

> What I plan on doing is splitting the WP_Rewrite out into the mod_rewrite
> reader / writer and the Router.

The "router" in WordPress is the template-loader file. Not WP_Rewrite.

You're trying to fit a square peg in a round hole here. Yes, you can
shave the sides of the peg and make an octagon to fit through the
hole, but it won't roll as well as a cylinder would. ;)

-Otto


More information about the wp-hackers mailing list