filter a string to remove disallowed characters to compose an URL in CodeIgniter – Education Career Blog

I’m trying to make URL-friendly links for the blog on my portfolio.
So I would like to obtain links something like site/journal/post/{title}

Obviously Journal is my controller, but let’s say my title would be ‘ goes live!’ I would like to have a valid url like site/journal/post/mysitecom-goes-live where all disallowed characters are removed.

How would I transform ‘ goes live!’ to ‘site/journal/post/mysitecom-goes-live’ in CodeIgniter based on the characters in $config’permitted_uri_chars’


use the url helper


$blog_slug = url_title(' Goes live!');

echo $blog_slug //mysitecom-site-goes-live 
// might differ slightly, but it'll do what you want.

to generate url-friendly links.

Store this value in a field in your blog table (url_title/url_slug) whatever.

make a function:

class Journal extends controller
   //make your index/constructor etc

   function view($post)
     // etc - your model returns the correct post,
     // then process that data and pass it to your view

your blog_model has a method get_post that uses CI’s

$this->db->where('url_title', $post);

hope that makes sense.

then when you access the page:

the function will pick up “mysite-goes-live” and pass it to the view() function, which in turn looks up the appropriate blog entry in the database.

Leave a Comment