0
votes

I'm developing my home page, this has a login button on the top right corner. I'd like to display a login page when the "login" text like so:

<li class="nav-item">
                <a class="nav-link header-text" href="<?php echo 
site_url('Login/login') ?>">Login</a>
</li>

So the controller is called "Login" and the view is "login".

My routing rules in the routes.php file are the following

$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';

My base url is: http://localhost:8080/ My site url is: http://localhost:8080/index.php

And my .htaccess file looks like this:

<IfModule authz_core_module>
    Require all denied
</IfModule>
<IfModule !authz_core_module>
    Deny from all
</IfModule>

The way this is currently setted up is not working for routing, i get a 404 not found message if i click the login and i get redirected to this url: http://localhost:8080/index.php/Login/login.html Can you please help me troubleshooting this problem? thanks!

EDIT: Here's the Login controller code:

<?php
class Login extends CI_Controller {

    public function view($page_name = 'login')
    {
        if ( ! file_exists(APPPATH.'views/pages/'.$page_name.'.php'))
        {
                // Whoops, we don't have a page for that!
                show_404();
        }

        $data['title'] = ucfirst($page_name); // Capitalize the first letter

        $this->load->view('templates/header', $data);
        $this->load->view('pages/'.$page_name, $data);
        $this->load->view('templates/footer', $data);
    }

}

2
I carefully read the codeigniter tutorial at this link: codeigniter.com/user_guide/tutorial/static_pages.html My actual configuration is the same one of the tutorial. So i tried loading this URL: localhost:8080/app/index.php/login And the login page is actually loaded but with a problem: without css... trying to troubleshoot this right nowmandiatutti
P.s. the header and footer files are loaded because i don't get any loading error... The css for the homepage is loaded. The header and footer are always the same and are located into views/templatesmandiatutti

2 Answers

0
votes

Try removing $route['(:any)'] = 'pages/view/$1'; and see what happens. It is grabbing every request and redirecting it to 'pages/view'.

I worry you misunderstand how CodeIgniter (CI) uses URLs. You said,

So the controller is called "Login" and the view is "login".

Which leads me to believe that URLs represent

example.com/class/view

when they actually represent this

example.com/class/function/id/

where 'id' is one or more values to be passed to the function.

Perhaps your comment was a misstatement, but if not I recommend rereading the CodeIgniter URLs section of the docs. You might also find the section URI Routing valuable as it clearly defines when you might want to use /config/Routes.php

The login URL is quite strange too. I'm curious to see what the controller code looks like.

0
votes

Ok, I did it! Basically I had a wrong idea on the standard routing rules I created following the tutorial. To solve the problem I had to: 1) change my base_url to: http://localhost:8080/app. I added the /app 2) The right way to route to a view in this case is: http://localhost:8080/app/index.php/name_of_the_class; 3) to load the css for every page I had to use the base_url syntax in the link tag like so: " type="text/css" media="all">

If you have any suggestion, best practice or something I can do better I'm here!