Welcome Guest, Not a member yet? Register   Sign In
Configure URL for sake of SEO
#3

Hello there,

You must use your Routes file under Config. Please look for it. And let me give you an example :

1) $route['user-area'] = 'site/user_area';

the left of the  "="  is the url which the visitor will visit/see, the right part is your component. My component name is "site" here.

  Example :
 
PHP Code:
public function user_area(){
  $this->load->view('admin/user_area'); 


This example above points to your view file which is under your "admin" folder. But the url is not ('admin/user_area'). I mean, you want the visitor to see only "user-area". And this is arranged in the routes file.

2)$route['user-area/:num()'] = 'site/user_area/$1';
  
What is :num()  ? It means any number following user-area/. Because this page is for my "users personal page" depending on their ID. And ID is a number.

3) $route['user-area/:any()'] = 'site/user_area/$1'; 

 any means anything : text or number..

Plus, when you need to see a specific page of any product or user you will follow the url. So that you can get its/his slug.

Watch here: www. mysite.com/about-me    the slug is : about me. So, how to take it?
$the_slug = $this->uri->segment(1);

So then, when you go to Models to retrieve any data you will use this parameter:


Example for getting slug for Component and Model

Controller: 
 
PHP Code:
public function about (){
$the_slug = $this->uri->segment(1);
$this->load->model('Backend_Model);
$data['
informations'] = $this->Backend_Model->about_pages($the_slug); 
  
$this->load->view('
about-me', $data);  // in your about_me file you will use "informations" to  show the datas.



Model : 

 
PHP Code:
public function about_pages($the_slug) {
    $query $this->db->select('*')
     ->from('pages')
     ->where('page_slug'$the_slug)
    ->get()
    ->row();  

  
return $query;



Good Luck.
Reply


Messages In This Thread
Configure URL for sake of SEO - by cybersalih - 09-06-2019, 06:44 AM
RE: Configure URL for sake of SEO - by PaulD - 09-06-2019, 07:09 AM
RE: Configure URL for sake of SEO - by demyr - 09-06-2019, 11:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB