简体   繁体   English

如果文件夹和控制器使用相同的名称该怎么办?

[英]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.

相关问题 我应该为Twig模板使用与控制器中相同的变量名吗? - Should I use the same variable name for my Twig template as the one I have in my controller? 如何配置CodeIgniter以打开另一个文件夹中但只有域名的控制器 - how do I configure CodeIgniter to open the a controller that is in another folder but with only domain name 当我运行项目时,它显示控制器没有在 laravel 中退出,但它在控制器文件夹中,我在做什么? - when i run project it shows controller does not exit in laravel , but it there in controllers folder what i do? 如何在控制器中使用控制器? - How do I use a controller within a controller? 无论我做什么,我的代码都会产生相同的结果 - no matter what I do my code would result the same PHP扩展类后,我使用什么名称 - PHP After extending a class what name do I use 当文件(扩展名已删除)和文件夹名称相同时,如何正确链接? - How do I link correctly when a file(extensions removed) and a folder have the same name? 我如何访问位于Codeigniter 4中“ folder_name / controller_name”的控制器? - How can i access my controller located in “folder_name/controller_name” in codeigniter 4? 我如何从我的 Laravel Controller 中的 html 表格中获取 name='blur' 的值 - How Do i get value Of name='blur' From html Form in My Laravel Controller 我用什么作为 SMTP - What do I use as SMTP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM