简体   繁体   English

Codeigniter路由?

[英]Codeigniter Routing?

I am having a problem with my routing in Codeigniter Project. 我在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: 实际上我已经在控制器,视图和模型下创建了admin文件夹,以访问admin部分。而我的route.php文件如下所示:

$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 : 如果要在项目中使用另一个CI实例,则将其保存在项目文件夹中,如下所示:

 /project
    /application
    /admin
    /system

In your admin folder you should have another CI project from where you'll create your admin panel. 在您的admin文件夹中,您应该有另一个CI项目,您将从此处创建管理面板。

 /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 : 在routes.php文件中:

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

In htaccess 在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.php中

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

and in htaccess 并在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. 如果您必须遵循default_controller家庭控制器的工作,则家庭控制器工作,而页面不可用,则pagenotfound控制器工作。 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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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