Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:26:44+00:00 2026-06-04T06:26:44+00:00

Please see the following link structure http://stackoverflow.com/questions/10672712/voting-system-like-stackoverflow In the above link the 10672712 is

  • 0

Please see the following link structure

http://stackoverflow.com/questions/10672712/voting-system-like-stackoverflow

In the above link the 10672712 is the question id I guess, because if you check the following link you will get to the same location as above:

 http://stackoverflow.com/questions/10672712

Now if you use the above link then you will notice that in the browser’s address bar the link automatically adds the question title (as slug) after the question id and it appears just like the first link above.

I am trying to create an article based website using Codeigniter. To display a particular article I have a controller which looks like following:

function articles(){


    $id=$this->uri->segment(3);

    $this->load->model('mod_articles');
    $data['records']=$this->mod_articles->list_articles($id);
    $this->load->view('view_article',$data);
     }

My Model:

  function list_articles($id)

       $this->db->select('*');
        $this->db->from('cx_article');
        $this->db->join('cx_author', 'cx_author.author_id = cx_article.author_id');
        $this->db->where('article_id', $id); 
        $query = $this->db->get();

       if ($query->num_rows() > 0)
        { return $query->row_array();
        }
        else {return NULL;}

    }  

If you hit this-> localhost/my_base_url/my_controller/my_funtion/article_id then my article shows up. Now what I am trying to achieve is if someone hits localhost/my_base_url/my_controller/my_funtion/article_id I want to automatically add the article title as slug right after the article_id.(Just like the example I have given above)

Could you please tell me how to do that?

Thanks:)

P.S In my DB table I have a column called article_slug, in which I store my article title as slug(example: voting-system-like-stackoverflow ).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:26:46+00:00Added an answer on June 4, 2026 at 6:26 am

    controllers/my_controller.php

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class My_controller extends CI_Controller {
    
        function my_function($int_id = NULL, $str_slug = '') {
    
            $row = $this->db->get_where('cx_article', array('article_id' => $int_id))->row();
    
            if ($row and ! $str_slug) {
    
                $this->load->helper('url');
    
                $str_slug = url_title($row->title, 'dash', TRUE);
                redirect("my_controller/my_function/{$int_id}/{$str_slug}");
    
            }
    
            // Run the rest of the code here
    
        }
    
    }
    

    There is no point to have a slug column in your database since you don’t identify anything based on your slug, nor is it unique.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please see the the following http://valogiannis.com/recent/ .I have a webpage and when user click
Following up from my last question @ stackoverflow.com/questions/7049245/ I got a couple of answers
Please see following methods. public static ProductsCollection GetDummyData(int? customerId, int? supplierId) { try {
Please see following examples first, and which one is better? Could you compare some
Please see the following code: List list = Collections.synchronizedList(new ArrayList()); // ... synchronized (list)
How do we update a textbox on ticking checkboxes? Please see the following code,
Please see this fiddle I want the scrolling div stop following when left div
Can someone please help me figure out a way to achieve the following (see
Please see the code below <html xmlns=http://www.w3.org/1999/xhtml> <head> <title>Test</title> </head> <body> <div> ¿Hola cómo
Please see here for a related question . However, char goes to 0xffff (or

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.