• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Codeigniter Slug

#1
Hello friends,
I am having problems with slug in codeigniter4,
I have a table called city which stores slug in slug columns

Controller code 

Code:
public function details($slug)
    {
     
        $data['entry'] = $this->EntryModel->getEntry($slug);
        $data['page_heading'] =  $this->EntryModel->getEntry($slug)->title;
        // print_r($data['entry']);
        // die;
        echo view('BasicApp\FrontPanel\Views\Content', $data);
    }

Slug is stored in database as 

india for india entry
india/delhi for delhi entry
india/delhi/abc for abc entry

The problem is when i access site using domain.com/india its working,if i access website as domain.com/india/delhi it still shows india only, 

My Route is 
Code:
$routes->get('/(:any)', 'FrontPanel::details/$1/', ['namespace' => 'BasicApp\FrontPanel\Controllers']);

Please help me where is the main issue ?
Reply

#2
Try this:
// The order is important

$routes->get('/(:any)/(:any)/(:any)', 'FrontPanel::details/$1/$2/$3', ['namespace' => 'BasicApp\FrontPanel\Controllers']);

$routes->get('/(:any)/(:any)', 'FrontPanel::details/$1/$2', ['namespace' => 'BasicApp\FrontPanel\Controllers']);

$routes->get('/(:any)/(:any)/(:any)', 'FrontPanel::details/$1/$2/$3', ['namespace' => 'BasicApp\FrontPanel\Controllers']);

$routes->get('/(:any)', 'FrontPanel::details/$1', ['namespace' => 'BasicApp\FrontPanel\Controllers']);
download and make your system directory strict
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.