Welcome Guest, Not a member yet? Register   Sign In
JS and CSS URL change
#1

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...s/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 
Reply
#2

(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...s/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'?>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB