[wp-hackers] Options for Controller - Views
otto at ottodestruct.com
Fri Nov 20 14:32:54 UTC 2009
On Thu, Nov 19, 2009 at 9:06 PM, Jacob Santos <wordpress at santosj.name> wrote:
> Using template_redirect is a dirty hack...
How is template_redirect a dirty hack? The template-loader is the
entire "view" portion of WordPress, and IMO it works just fine. You
can select your "view" based on any criteria you prefer. yes, it's one
big set of else-if's, but the template_redirect lets you add your own
set of criteria and to bypass the existing templates (views) entirely.
I think you're too wedded to some pre-existing other concept of MVC
that you have instead of working within the existing framework.
> and I can get by not using
> add_rewrite_rule function completely with a few other hacks. The point of
> MVC is to easily extend the base with a defined flow path. Right now it is
> like a maze with many paths leading to dead ends.
I don't see that at all. It's a very clear and well-defined structure,
albeit a potentially poorly named one.
> In fact, I could do without the whole "blog" portion and use the Plugin API
> and other parts, like the administration to create something completely
> different using WordPress as the base.
The administration piece of WordPress is the real dirty hack here. Not
to disparage anybody, but it's a total mess. Dozens of points of
entry, cross-including all over the place... it's extremely difficult
to work with. The front-end portion is trivially easy to extend by
> As it stands now, it would require a
> great deal of hacking and I could never really remove the portions of
> WordPress that makes WordPress, well WordPress. If that is the case, then
> I'm better off starting from a framework that actually implements MVC
> properly and without all of the WTF?s that exist within WordPress.
Well, yes, basically you are. You're talking about wanting to make
WordPress into not WordPress, and in that case I'd ask why bother with
starting with WordPress in the first place? I've used the Zend MVC
framework before, and it's quite good. If you want specific portions
of WordPress, then quite a lot of it has been abstracted out into
classes. Things like the Plugin API and such are actually somewhat
trivial to recreate, because lets face it, all that really does is to
keep a dynamic list of files somewhere and then includes them, one at
a time. Creating an interface to do that is not difficult. The clever
bit there is scanning the plugins for the header information.
> Also, it has to be easy, so if someone wants to extend what I created, they
> can do so without having to kick their own ass trying to figure it out. Do
> you know how long it takes to learn Zend Framework, Code Igniter, etc? An
> hour and it is pretty straight forward with all of the examples and that is
> also with working development. I spent 4 hours trying to use WP_Rewrite and
> after feeling like an idiot and cursing the name of the person who created
> such a monstrosity, I gave up and used the template_redirect route. To find
> that I have to use it anyway isn't all that appealing.
I'm confused as to what exactly you were trying to do with WP_Rewrite
that you found so difficult. Calling add_rewrite_rule to, well, add a
rewrite rule seems fairly straightforward to me. WP_Rewrite is just an
internal implementation that is basically equivalent to the .htaccess
rewrites method. It doesn't claim to be much of anything more. It
doesn't connect URLs to "views", it changes URLs from one form to
another. That's all it ever claims to do. If you want to connect query
variables to views, then template_redirect is the right way to do it.
That's not a hack, that's by design. The whole thing is based on query
variables, WP_Rewrite just lets you create those variables based on
other characteristics of the URL.
> I think the last time I tried this I attempted to work WP_Query in the
> project as well as it was far too much rewriting. The goal should be to get
> closer to an simpler MVC implementation.
I disagree. The goal should be to abstract the pieces into separate
components, yes, but not to go full MVC with all the limitations that
encompasses. MVC can be nice for some things, but it is ultimately
frustrating and limiting when applied to Web Applications.
To pick an example, Zend MVC is relatively easy to work with, but it
ultimately limits you on how you can construct your URLs. It's
inflexible in several respects because of the assumptions it makes
about how you want your URLs to look. WordPress' rewrite system is
highly flexible, since you can make your URLs look any way you can
express with regexp, then change them into query_vars, and direct to
your templates based on those vars.
More information about the wp-hackers