CodeIgniter Forums
URL parameters in CodeIgniter 4 Not Working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: URL parameters in CodeIgniter 4 Not Working (/showthread.php?tid=84182)



URL parameters in CodeIgniter 4 Not Working - elomayry - 10-19-2022

I tried to access an id from a URL

http://localhost:8080/CI4/public/details/1

Routes.php
Code:
$routes->get('details/(:any)', 'Car::details/$1')


Car.php (controller)

Code:
class Car extends BaseController
{

    public function details($id)
    {
        $carsModel = new carsModel();
        $query = $carsModel->findAll();

       

        $data = [
            'title_meta' => view('partials/title-meta', ['title' => 'Cars']),
            'page_title' => view('partials/page-title', ['title' => 'Vehicles', 'li_1' => 'Home', 'li_2' => 'Cars']),
            'carsList' => $query
        ];

        return view('details', $data);
    }

Partials head where css is referenced
Code:
    <!-- preloader css -->
<link rel="stylesheet" href="assets/css/preloader.min.css" type="text/css" />

<!-- Bootstrap Css -->
<link href="assets/css/bootstrap.min.css" id="bootstrap-style" rel="stylesheet" type="text/css" />
<!-- Icons Css -->
<link href="assets/css/icons.min.css" rel="stylesheet" type="text/css" />
<!-- App Css-->
<link href="assets/css/app.min.css" id="app-style" rel="stylesheet" type="text/css" />
i can get the ID on details page , but the CSS and page layout not loading and the url become like this

http://localhost:8080/CI4/public/details/assets/css/bootstrap.min.css
instead of
http://localhost:8080/CI4/public/assets/css/bootstrap.min.css


RE: URL parameters in CodeIgniter 4 Not Working - kenjis - 10-21-2022

Use base_url().
https://codeigniter4.github.io/CodeIgniter4/helpers/url_helper.html#base_url


RE: URL parameters in CodeIgniter 4 Not Working - InsiteFX - 10-23-2022

PHP Code:
<?= base_url('assets/css/bootstrap.min.css');?>