Let\'s say that I have a controller named
pages
and there is a method
slug_on_the_fly
public functi
You could use database driven routes.
Add the table blog_slugs to your MySQL database:
CREATE TABLE IF NOT EXISTS `blog_slugs` (
`id` bigint(20) NOT NULL auto_increment,
`slug` varchar(192) collate utf8_unicode_ci NOT NULL
PRIMARY KEY (`id`),
KEY `slug` (`slug`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;
Replace the code in application/config/routes.php with the one below:
$route[ 'default_controller' ] = 'main';
$route[ '404_override' ] = 'error404';
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->get( 'blog_slugs' );
$result = $query->result();
foreach( $result as $row )
{
$route[ $row->slug ] = 'pages/slug_on_the_fly/$1;
}
All you would have to do then is to create a record when you create a blog entry and you're done:
INSERT INTO `blog_slugs` (`slug`) VALUES ('name-of-the-article');