Savant3 URI Plugin
June 14th, 2009 by Ray in PHP/MySQL, Solar | Tags: php, savant3, Solar | No CommentsI started working on a small project last weekend for a [H]ard|Forum member that would allow viewing maillog log info from a web site. I wanted to make an app that would have a small footprint and would be easy to manage (code base wise as well as UI). My first instinct was to use a MVC framework like Solar or Zend but those two have more features than what I needed for this project. Remember, I wanted a small footprint.
I decided to give Savant3 a shot. This at least allows me to separate my controller logic from my view logic. I only had one controller and one template so code overhead wasn’t an issue.
One of the things missing from this system was a way to easily handle URIs/URLs. Since Savant3 is a template engine, I wouldn’t necessarily expect a URI handler. However, I felt that having a plugin that handles URIs was worth the effort, even with a project of this size.
Since the plugin code is still a bit messy (missing inline docs, needs a little bit of refactoring, etc) I can only show you usage examples for now. I plan on cleaning up the code and releasing the plugin on this site shortly.
Here is how one might use this URI plugin in a Savant3 template:
// builds the URI based off of the current URL $uri = $this->uri()->fromCurrentUrl(); // allows setting query info $uri->query = 'order=name_asc'; // this adds to the query, it does not overwrite it $uri->query = 'page=2'; // returns only the query portion: '?order=name&page=2' $uri->get(); // this will update page to 'page=3' $uri->query = 'page=3'; // again we only return the query portion: '?order=name&page=3' $uri->get(); // we can also set a full query as well and we can provide keys without values $uri->query = 'order=name_desc&page=3&submitted' // currently there is not a way to remove a single piece of the query // we have to reset the whole query and rebuild it unset($uri->query); // passing 'true' to get() gives us the whole URI // for example: http://white-box.us/somedir/index.php $uri->get(true);
The rest of the functionality works much like Solar_Uri (currently w/the exception of path and query behavior), being able to set each piece of the URI before returning a newly built URI.
Leave a Reply