Question

Recently i am working with codeigniter. I need to create a permalink functionality just like as wordpress. Can anyone suggest me a way that, how i can implement this in codeigniter.

Was it helpful?

Solution

Can you give more details about what you want to do. In my understanding you want to create something like this?

http://example.com/2012/post-name/

1) You must have a mod_rewrite. 2) Use the controller or model but will advice to use Controller

Controller:

    public function something(string name, int year){
     //some code
   }

This will be translated to

http://www.example.com/something/name/year

Hope this helps or you can paste your code so I can explain further.

OTHER TIPS

So create the page: admin.php

Then in the controller:

public function about-us(){
 $this->view->load('about-us');
}

When you run the page is will be: http://domain.com/about-us. about-us is the function in the controller.

Are you asking how to remove the spaces and replace with a hyphen?

$slug = 'this is a bad slug';
$fixed_slug = str_replace(' ', '-', $slug);
# uncomment next line to see result
# echo $fixed_slug; 

If you want to make that a method, no worries:

public function fix_slug($slug){
    $fixed_slug = str_replace(' ', '-', $slug);
    return $fixed_slug;
}

You can obviously do more in that method, or abstract it to use with other text you want altered.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top