I am learning Codeigniter and I can't solve the problem I am having.
localhost/reservation/
, the system will display the login.php
andbook.php
.A good explanation is very appreciated.
View
<form class="" method="POST">
<div>
<button class="btn btn-primary" name="login">Login </button>
</div>
</form>
As you can see, I don't include username and password input fields to shorten the codes.
Controller
class Reservation extends CI_Controller {
public function _construct()
{
parent::__construct(;
$this->load->helper("url");
}
public function index()
{
if(...some condition...){
redirect('book');
}
$this->load->view('login');
}
public function book(){
$this->load->view('book');
}
}
I shorten the code, removed unnecessary ones(in my opinion) to make it shorter and direct to the point.
Routes
$route['book'] = 'reservation/book';
$route['default_controller'] = 'reservation';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
.htaccess
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
Your .htaccess
should be like this (removing index page):
Options +FollowSymlinks -Indexes
RewriteEngine on
DirectoryIndex index.php
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
put .htaccess
file to your app folder outside application folder
and set your config.php
like this :
$config['base_url'] = 'http://localhost/app_folder/';
$config['index_page'] = '';
Now access
http://localhost/app_folder/
will show you your login page