简体   繁体   中英

Codeigniter Routing?

I am having a problem with my routing in Codeigniter Project. Actually I have created the admin folder under the controller,view and model to access the admin section.And my routes.php file is as below:

$route['default_controller'] = "admin/login";
$route['admin/(:any)'] = "admin/admin/$1";
$route['404_override'] = '';

When I click on the submit button of the login page it redirects to the same page of login. The action where it should actually go its not redirecting there.

check the form tag. may be it have an action in it. and your button type maybe submit please remove and check again

If you want to use another CI instance in your project then keep it in your project folder as given below :

 /project
    /application
    /admin
    /system

In your admin folder you should have another CI project from where you'll create your admin panel.

 /project/admin
       /application
       /system

You can set your configuration and routing and whatever you want from any of your project as you desire.

Hope that helps.

In routes.php file :

$route['default_controller'] = "your default controller";
$route['404_override'] = '';

In htaccess

#Options +FollowSymlinks
#RewriteEngine on
#
#RewriteCond $1 !^(index\.php|assets|uploads|tt|resources|robots\.txt|favicon\.ico)
#RewriteRule ^(.*)$ /index.php/$1 [L]


RewriteEngine on
RewriteCond $1 !^(index\.php|cronDailyProof\.php|cronWeeklyProof\.php|cronMonthlyProof\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
DirectoryIndex index.php

The above two changes solved my problem.

in route.php

$route['default_controller'] = "home";
$route['404_override'] = 'errors';
$route['admin'] = 'admin/login';

and in htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
rewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L]

these changes solved this problem for me

If u have to follow for default_controller home controller working then home controller working and not page available then pagenotfound controller work. on my default page to move on login page onclicking login button. then follw like this

<?php
                    $attributes = array("class" => "form-horizontal", "id" => "loginform", "name" => "loginform");
                    echo form_open("login/index", $attributes);
                ?>
//login button like this and its working
<button type="submit" name="btn_login" id="btn_login" class="btn btn-default" value="Login"><?php echo lang('Login'); ?></button>
<?php echo form_close(); ?>

My Route.php file

$route['default_controller'] = 'home';
$route['404_override'] = 'pagenotfound';
$route['translate_uri_dashes'] = FALSE;

My .htaccess file

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|admin|js|css|images|assets|uploads|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM