• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Path problem I have while using route groups

#1
Hello, first of all I apologize for my bad English.
I am having a problem with the routes and if there will be no problem, I would like to explain by giving examples. I will give the example from a completely clean and fresh install. So there is no additional development etc.

There is a line in the "welcome_message.php" page that calls a style file from the "public" folder.
This line is:
Code:
<link rel = "stylesheet" href = "assets/css/style.css">



If I call the route as follows, the style.css file loads without problems and looks like this (example.com/assets/css/style.css)

PHP Code:
$routes-> get('welcome''Home::index'); 



But if I call the route as a group that I mentioned below, the style.css file is not loaded and the path looks like this (example.com/blog/assets/css/style.css)

PHP Code:
$routes->group('blog', function ($routes) {
    $routes->add('welcome''Home::index');
}); 


I follow such a way to avoid using base_url when calling entities. If I add "base_url ()" to the beginning of the line I call this css file, there is no problem and it calls the file in both ways without any problem, but I wanted to get your feedback because it was interesting to me. Is this a normal process? So is this what it should be or I'm making my mistake somewhere. And I wonder if there is a way to solve this without adding base_url ?

Thank you very much for your help in advance.
Reply

#2
You should not confuse the filesystem path in public/ with the request path. When you do a request to example.com/blog/ and generate a page - the request goes through public/index.php and thanks to the .htaccess rewrite instructions it works.

However - the page you generate will look like it is served from public/blog/ and will thus look for the assets directory there.

If you are serving your public/ directory from a apache virtualhost you should be able to refer to the asset path as <link rel = "stylesheet" href = "/assets/css/style.css"> (note the "/assets" path).
If not, I'd try adding the BASE tag to your pages - https://developer.mozilla.org/en-US/docs...ement/base and point that to "/".
As a third option you can inject base_url() in all your templates.
Reply

#3
PHP Code:
$routes->group('blog', function ($routes) {
    $routes->add('welcome''Home::index');
});

// change to
$routes->group('', function ($routes) {
    $routes->get('welcome''Home::index');
}); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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