[英]What do i do if my folder and controller use the same name?
I have a vendor folder created by composer on my codeigniter project and i also have a vendor controller, so when i load localhost/my_project/vendor
it will open the composer folder instead but when i use localhost/my_project/index.php/vendor
it loads the controller please any possible way of solving this issue. 我在我的codeigniter项目上有一个由composer创建的供应商文件夹,并且我也有一个供应商控制器,因此当我加载
localhost/my_project/vendor
,它将打开composer文件夹,但是当我使用localhost/my_project/index.php/vendor
时请加载控制器以解决此问题的任何可能方式。 When i use localhost/my_project/admin
it works perfectly incase you thinking i didn't use the default .htaccess file. 当我使用
localhost/my_project/admin
,如果您认为我没有使用默认的.htaccess文件,它可以完美地工作。
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Vendor extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('paypal');
$this->load->library('twoCheckout_Lib');
$this->load->library('vouguepay');
/*cache control*/
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
//$this->crud_model->ip_data();
$vendor_system = $this->db->get_where('general_settings', array('type' => 'vendor_system'))->row()->value;
if ($vendor_system !== 'ok') {
redirect(base_url(), 'refresh');
}
}
/* index of the vendor. Default: Dashboard; On No Login Session: Back to login page. */
public function index()
{
if ($this->session->userdata('vendor_login') == 'yes') {
$page_data['page_name'] = "dashboard";
$this->load->view('back/index', $page_data);
} else {
$page_data['control'] = "vendor";
$this->load->view('back/login', $page_data);
}
}
You should to set right settings for your web server. 您应该为您的Web服务器设置正确的设置。 You may setup rewrite rules as in example below.
您可以按照以下示例设置重写规则。 if you are using apache:
如果您使用的是Apache:
<LocationMatch "^/vendor">
RewriteRule . index.php [L]
</LocationMatch>
if you are using nginx: 如果您使用的是nginx:
location /vendor {
rewrite (.*) /index.php last;
}
Codeigniter uses the same Apache mod_rewrite snippet as so many applications: Codeigniter使用与许多应用程序相同的Apache mod_rewrite代码段:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Those both conditions first check if there is a file ( -f
) or directory ( -d
) with the requested name. 这两个条件都首先检查是否存在具有所请求名称的文件(
-f
)或目录( -d
)。 And only if no such file or directory exists, the RewriteRule will take effect. 并且仅当不存在此类文件或目录时,RewriteRule才会生效。 Since you already have a directory "vendor" you have to set an exception for that directories name before the other rewrite:
由于您已经有一个目录“ vendor”,因此必须在其他重写之前为该目录名称设置一个例外:
RewriteCond %{REQUEST_FILENAME} ^vendor/.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.