1

I want to show single blog news by slug but I do not know

Blog Controller :

        public function show_news($slug)
        {
          $page_data['page_title']  = 'News';
          $page_data['news_item'] = $this->blog_model->get_news($slug);

          $this->template->load('frontend/blog_news',$page_data);

        }

Blog Model :

	 function get_news($slug)
    {
      $slugs = urldecode($slug);
       $query = $this->db->get_where('blogposts', array('slug' => $slugs));
if($query->num_rows() > 0 ){
	if($this->db->get_Where('blogposts', array('slug'=>$slugs))->row()->status == '1'){
		return $query->row_array();
		   }
		}
    }

my route :

$route['blog/(:any)/news/(:any)'] = "blog/show_news/$1/$2";

2
  • your question in incomplete, explain more Commented Jan 28, 2017 at 9:31
  • @MahdiMajidzadeh in view data not show anything , where is my wrong? Commented Jan 28, 2017 at 9:51

2 Answers 2

2

you have only one parameter($slug) with show_news function so obviously the route "blog/show_news/$1/$2"; will be incorrect.Manage your route like this..

$route['blog/news/(:any)'] = "blog/show_news/$1";

It redirects every blog/show_news/slug to blog/news/slug

Sign up to request clarification or add additional context in comments.

Comments

0

In your controller, you have only 1 parameter. This is not ok with your route configuration. It should be $route['blog/news/(:any)'] = "blog/show_news/$1"; as already said.

But, your question title is

Codeigniter - routes multiple parameters

If you mean that you want to pass another parameter, than, with your current route, you can access the $2 variable by adding a second parameter to the method of your controller like this.

public function show_news($slug, $secondParameter){

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.