[wp-hackers] Options for Controller - Views

Mike Schinkel mikeschinkel at newclarity.net
Fri Nov 20 15:29:52 UTC 2009

On Nov 20, 2009, at 9:32 AM, Otto wrote:
> 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.

Yes it is a nasty, dirty, ugly hack.  In order to get something as simple as an arbitrary URL to route requires use of the follow hooks (directly from my plugin):

		add_action('generate_rewrite_rules', array(__CLASS__,'add_rewrite_rules'));
		add_filter('query_vars', array(__CLASS__,'add_queryvars' ));

It is total crap that you have to use so many hooks to get the path "/products/{product}" to work and that your hooks have to much with fragile SQL.

> I don't see that at all. It's a very clear and well-defined structure,

...for someone who has developed years of expertise with it. *Not* for 99.9% of WordPress users.

> 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.


> ...and in that case I'd ask why bother with

> starting with WordPress in the first place?

Because WordPress is in use by millions of people. 
Because there are more plugins for WordPress than for anything else.
Because there are more off-the-shelf themes for WordPress than for anything else.
Because WordPress has a better end user admin interface than anything else. 
Because WordPress is in active in development.
Need I go on?

> I've used the Zend MVC
> framework before, and it's quite good.

Good. For programmers. 

But not a good solution for people whose needs match 80% of what WordPress offers but also needs to control URLs for 20% of their site.

> 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.

Speaking for myself and not Jacob, what was difficult was that in order to support the following structure I had to use TWELVE (12) HOOKS and the resultant code was very fragile!!!


Is *should* be as easy as me adding in a (simplified) URI Template and mapping it to a file or function (that's what my plugin allows, but it was far too difficult, and fragile, to make it work.) 

> 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.

For the record, I'm not advocating MVC, I'm advocating making URL mapping easy.  Easy like Django or Rails.

> 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.

But WordPress' rewrite system is far to complicated for any but the advanced WordPress developer to tackle, and too fragile to be a robust solution. 

-Mike Schinkel
WordPress Custom Plugins

More information about the wp-hackers mailing list