Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - mohrt

Pages: [1]
Coding - Application Development / 1.2.3 released
« on: May 03, 2013, 10:34:32 am »
TinyMVC 1.2.3 is released, just a small bug fix.

Coding - Application Development / TinyMVC 1.2.1 is released
« on: September 01, 2011, 03:17:15 pm »
See the download page.

Coding - Application Development / auto-magic controllers
« on: July 12, 2010, 05:16:49 pm »
I'm using Smarty as my view layer. Just playing around, I adjusted my default controller so it will try to load a template straight from the URL, so for example:

This will try to load a template named foobar.tpl. Likewise:

Will load foo/bar/baz.tpl. If the path ends in slash:

This will attempt to load foo/bar/baz/index.tpl

What purpose does this serve? It makes things SUPER easy for static content. Want a documentation page? Create documentation.tpl file, then just put /documentation in the URL, and it just works. Couple that with Smarty 3 and template inheritance, and things get pretty interesting! Of course if a controller file exists, that will get picked up by TinyMVC and go the normal controller processing route. This is basically for static content that does not require any prior variable assignments.

Here is the default controller I am using. This could easily be edited to work with straight up TinyMVC view files instead of Smarty templates, but you get the idea.

Code: [Select]

 * default.php
 * default application controller
 * @package TinyMVC
 * @author Monte Ohrt

class Default_Controller extends TinyMVC_Controller

// be sure the uri library is autoloaded

__call($method,$args) {
// create a template path from the path info
// if template exists, display it
$tpl_path $_SERVER['PATH_INFO'];
if(substr($tpl_path,-4) !== '.tpl') {
$tpl_path .= 'index.tpl';
$tpl_path .= '.tpl';
if($this->smarty->templateExists($tpl_path)) {
} else {



Coding - Application Development / TinyMVC 1.1 is released
« on: June 04, 2010, 04:23:56 pm »
1.1 is released. The docs are not quite up to date, but they should still work for the most part. I still need to add new features into the docs. Let me know if there are any discrepancies with the current docs.

Coding - Application Development / Big SVN update
« on: October 30, 2009, 02:23:13 pm »
quite a few things have changed internally in the SVN.

* The main bootstrap process now uses a class to perform the initialization, and house the entire MVC.
* the default c-based spl_autoload() is now used for speed. This means many internal file names/structure have been changed. Be sure to get a full svn update
* you can now control which controller/method (action) is used in the config instead of the url with $config['root_controller'] and $config['root_action']
* unknown actions now use $config['default_action'] as default, or 'index' if not given

* You can now access several things through the tmvc instance:

$tmvc = tmvc::instance();
$tmvc->controller // the controller object
$tmvc->action // the controller method being used
$tmvc->url_segments // the array built from path_info
$tmvc->config // the loaded config array

Please post any issues you may find!

[edit] also, exceptions are used for much error handling now, instead of trigger_error()

TinyMVC Framework Development / timer added to SVN
« on: August 20, 2008, 10:57:38 am »
You can now time your applications with the SVN version.

Here is how it works:

In your myapp/configs/application.php, add this:

Code: [Select]
$config['timer'] = true;
The timer is now enabled.

In your view file, put {TMVC_TIMER} somewhere, and it will get replaced by the total execution time of your application.

To do your own timings:

Code: [Select]
// set initial time

// compute stuff here...

// set ending time

// get the time difference
$mytime = tmvc::timer('marker1','marker2');

I'm open to comments and suggestions!

TinyMVC Framework Development / URI routing added to SVN
« on: August 15, 2008, 04:39:28 pm »
I just added simple URI routing to the SVN repository (four simple lines of code :)

Here is how it works:

Checkout SVN and update your code. (specifically, sysfiles/TinyMVC.php)
In your myapp/configs/application.php file, add:

Code: [Select]
/* URL routing, use preg_replace() compatible syntax */
$config['routing']['search'] =  array();
$config['routing']['replace'] = array();

Now TinyMVC respects these settings, and will do an internal replacement on the PATH_INFO (everything past the index.php). Use preg_replace() compatible format.

For example, if you want this:


to map to:


you would create a route as such:

Code: [Select]
$config['routing']['search'] =  array('!list!');
$config['routing']['replace'] = array('listing');

Be sure to include delimiters in the search query.

You have to be careful with this, it does a simple preg_replace, so anywhere in your PATH_INFO, list will be replaced with listing. It may be wise to check for the slash prefix too:

Code: [Select]
$config['routing']['search'] =  array('!/list!');
$config['routing']['replace'] = array('/listing');

All rules for preg_replace apply, so if you want:


to map to:


You could do this:

Code: [Select]
$config['routing']['search'] =  array('!^/groups/(\d+)!');
$config['routing']['replace'] = array('/groups/view/id/${1}');

And of course, multiple replaces apply in the order they are given:

Code: [Select]
$config['routing']['search'] =  array(
$config['routing']['replace'] = array(

note: I thought about some nifty simplified syntax but to be honest, I saw no sense in crippling the power/speed of preg_replace(), and you should already know the syntax :)

Let me know how it goes! I will likely be putting out a new distribution soon.

TinyMVC Framework Development / SVN commit, new stuff!
« on: May 24, 2008, 01:03:44 am »
Hi all,

I've committed a lot of stuff to SVN lately, mostly some new model functionality to the db layer, several code cleanups and a new helper script with a couple of useful functions in it. I don't have any documentation updated yet, but the new model functions work like so:

Code: [Select]
$this->db->orwhere('(foo=? or bar=?)',array($foo,$bar));
while($row = $this->db->next())
  $results[] = $row;

This allows you to piece together an SQL query programmatically and injection stuff is taken care of where ? are used. (PDO is used under the hood.)

And two new functions in the helper script:

Code: [Select]

The first one dumps out a php variable in a nice easy-to-read format. The second redirects the browser and exits. Besure you load the "helpers" script, or autoload it.

Feel free to browse around and make comments here.

TinyMVC Framework Development / New SVN repository
« on: January 14, 2008, 10:11:02 am »
TinyMVC has a new repository home, updated from CVS to SVN. Please use the new location:
Code: [Select]
svn checkout tinymvc-php-read-only

Pages: [1]