CodeIgniter Forums
JS and CSS URL change - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: JS and CSS URL change (/showthread.php?tid=79950)



JS and CSS URL change - eddoh - 08-21-2021

Hello,

I have a problem with a methohe from a controller. Indeed, when I call it the js and css loading path changes and they fail to load.

correct path : http://localhost:8081/assets/images/logo.svg
wrong path after method call : http://localhost:8081/update_user/assets/images/logo.svg
Below my code 

PHP Code:
$routes->get('/users''Admin/Users::index');
$routes->get('/add_user''Admin/Users::add_user');
$routes->get('update_user/(:num)''Admin/Users::update_user/'); 

PHP Code:
public function update_user($id)
    {
 if(
$this->request->getMethod() == 'get'){ 
 if (
session()->get('login') != "") {

                $userModel = new UserModel();
                $user $userModel->find($id);

                $profilModel = new ProfilModel();
                $profilsItems $profilModel->findAll();

                $data = [
                    'title_meta' => view('partials/title-meta', ['title' => 'Utilisateurs']),
                    'page_title' => view('partials/page-title', ['title' => 'UpdateUser''pagetitle' => 'GestionUtilisateurs''link' => 'users']),
                    'user' => $user
                    'profils' => $profilsItems
                
];
    
                
return view('admin/edit_user_2'$data);
            } else {
                return redirect()->to('/login');
            }
 }

        if($this->request->getMethod() == 'post'){
            // ---- store details in database
 
$model = new UserModel();

 
$updateData = [
 
'nom' => $this->request->getVar('nom'),
 
'prenom' => $this->request->getVar('prenom'),
 
'email' => $this->request->getVar('email'),
 
'mobile' => $this->request->getVar('mobile'),
                'tel' => $this->request->getVar('tel'),
                'id_profil' => $this->request->getVar('id_profil')
 ];

            $model->where('id'$id)
 ->
set($updateData)
 ->
update();

 return 
redirect()->to('/users');
        }
    }






Thanks for your help 



RE: JS and CSS URL change - nfaiz - 08-22-2021

(08-21-2021, 03:37 AM)eddoh Wrote: Hello,

I have a problem with a methohe from a controller. Indeed, when I call it the js and css loading path changes and they fail to load.

correct path : http://localhost:8081/assets/images/logo.svg
wrong path after method call : http://localhost:8081/update_user/assets/images/logo.svg
Below my code 

PHP Code:
$routes->get('/users''Admin/Users::index');
$routes->get('/add_user''Admin/Users::add_user');
$routes->get('update_user/(:num)''Admin/Users::update_user/'); 

PHP Code:
public function update_user($id)
    {
 if(
$this->request->getMethod() == 'get'){ 
 if (
session()->get('login') != "") {

                $userModel = new UserModel();
                $user $userModel->find($id);

                $profilModel = new ProfilModel();
                $profilsItems $profilModel->findAll();

                $data = [
                    'title_meta' => view('partials/title-meta', ['title' => 'Utilisateurs']),
                    'page_title' => view('partials/page-title', ['title' => 'UpdateUser''pagetitle' => 'GestionUtilisateurs''link' => 'users']),
                    'user' => $user
                    'profils' => $profilsItems
                
];
    
                
return view('admin/edit_user_2'$data);
            } else {
                return redirect()->to('/login');
            }
 }

        if($this->request->getMethod() == 'post'){
            // ---- store details in database
 
$model = new UserModel();

 
$updateData = [
 
'nom' => $this->request->getVar('nom'),
 
'prenom' => $this->request->getVar('prenom'),
 
'email' => $this->request->getVar('email'),
 
'mobile' => $this->request->getVar('mobile'),
                'tel' => $this->request->getVar('tel'),
                'id_profil' => $this->request->getVar('id_profil')
 ];

            $model->where('id'$id)
 ->
set($updateData)
 ->
update();

 return 
redirect()->to('/users');
        }
    }






Thanks for your help 

Try
PHP Code:
<?= base_url('assets/images/logo.svg'?>