user3459150
user3459150

Reputation: 35

slug its not working in codeigniter

i want url slug like this

tkd/index.php/article/77/Kejurnas-2013

but when i click button like this

tkd/index.php/article/77/Kejurnas%202013

what wrong with my code. this is my view

<div class="post-buttons-wrap">
                          <div class="post-buttons">
                            <a href="<?php echo base_url('index.php/article/' . intval($dt->id) . '/' . e($dt->slug)) ; ?>" class="ui black label">
                                Read More
                              </a>
                          </div><!-- end .post-buttons -->
                      </div>

and this is my controller

public function index()
{

    $this->data['berita'] = $this->mberita->get_berita();
        $this->data['halaman'] = $this->mhalaman->get_profil();

        dump('Page!');
        // Fetch the page template
        $this->data['page'] = $this->page_m->get_by(array('slug' => (string) $this->uri->segment(1)), TRUE);
        count($this->data['page']) || show_404(current_url());

        // Fetch the page data
        $method = '_' . $this->data['page']->template;
        if (method_exists($this, $method)) {
            $this->$method();
        }
        else {
            log_message('error', 'Could not load template ' . $method .' in file ' . __FILE__ . ' at line ' . __LINE__);
            show_error('Could not load template ' . $method);
        }
    $this->data['contents'] = $this->data['page']->template;
    $this->load->view('template/wrapper_mahasiswa', $this->data);
}

please help me what to do. thank you.

Upvotes: 0

Views: 320

Answers (2)

Ricardmc
Ricardmc

Reputation: 27

You have to use the helper "URL" and use the functions "url_title()" and "convert_accented_characters()" if you need to convert some special characters.

http://ellislab.com/codeigniter/user-guide/helpers/url_helper.html for more info

Example: In your controller code, you will capture your form inputs. then you have to create the slug with a line like this:

$event['slug'] = url_title(convert_accented_characters($event['eventName']),'-',TRUE);

This line will return you a slug separated by "-", setting all the words to lowercase and deleting all special characters too.

Upvotes: 1

sunny
sunny

Reputation: 1166

try this- use rawurlencode while working with strings in url-

 <a href="<?php echo base_url('index.php/article/' . intval($dt->id) . rawurldecode('/') . e($dt->slug)) ; ?>" class="ui black label">
                                Read More
                              </a>

Upvotes: 0

Related Questions