简体   繁体   English

Codeigniter路线URL联系人页面

[英]Codeigniter route URL contact page

I'm new in Codeigniter I'm not sure how to use Codeigniter Routing. 我是Codeigniter的新手,我不确定如何使用Codeigniter路由。 I've created the Contact.php in the controller folder and contact.php in the views folder. 我已经在controller文件夹中创建了Contact.php ,在views文件夹中创建了contact.php

In routes.php I have put $route['Contact'] = 'controller/contact'; 在routes.php中,我将$route['Contact'] = 'controller/contact'; but when I enter the url http://mytest.dev/contact/ it shows 404 Page Not Found. 但是当我输入网址http://mytest.dev/contact/时,它显示404页面未找到。 The page you requested was not found. 未找到您所请求的页面。

I want when I enter " http://mytest.dev/contact " it will show the contact page 我想要输入“ http://mytest.dev/contact ”时显示联系页面

Thanks in advance. 提前致谢。

Controller 调节器

<?php defined('BASEPATH') OR exit('No direct script access allowed');

    class Contact extends CI_Controller {
        function __construct() {
            parent::__construct();
        }

        function index() {
            $this->load->view('contact')
        }
    }

In CI there is an index.php in the URL ( by default ). CI中,URL中有一个index.php (默认情况下)。 So, you can access your page with this url http://mytest.dev/index.php/contact 因此,您可以使用以下URL访问您的页面: http://mytest.dev/index.php/contact

For removing it from URL and have it like you want you need to add .htaccess file in your project directory 要从URL删除它并使其具有所需的名称,您需要在项目目录中添加.htaccess文件

Check this answer for it 检查这个答案

Also, you don't need to change your routes.php every time after creating a new page. 另外,创建新页面后,无需每次都更改您的routes.php Leave it like this 像这样离开

$route['default_controller'] = 'welcome'; // or contact
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

I see you are using $route['Contact'] = 'controller/contact'; 我看到您正在使用$route['Contact'] = 'controller/contact';

Tell us your controller's class name and which function/method did you use from the above you are referencing to contact() and that controller name doesn't make sense. 告诉我们您的控制器的类名称,以及您从以上引用的contact()使用了哪个函数/方法,而该控制器名称没有意义。 You route will normally be in lowercase too. 您的路线通常也会使用小写字母。

If you named your class Contact (which seems like it) then you need to put a .htaccess file in the folder where your index.php or base_url resides (or root directory) and then remove the value in application/config.php as $config['index_page'] = ''; 如果您将类命名为Contact (看起来像这样),则需要将.htaccess文件放入index.phpbase_url所在的文件夹(或根目录)中,然后将application/config.php中的值删除为$config['index_page'] = ''; so that you can access it from http://mytest.dev/contact 这样您就可以从http://mytest.dev/contact访问它

To make it clearer. 使其更清楚。 The format should be $route['AAA'] = 'BBB/CCC'; 格式应为$route['AAA'] = 'BBB/CCC';

AAA is the url path of your choice BBB is the name of your controller's class CCC is the function/method of the page you want to show AAA是您选择的URL路径BBB是控制器类的名称CCC是您要显示的页面的功能/方法

If you didn't add the htaccess, you must put /index.php/ before your preferred path. 如果未添加htaccess,则必须将/index.php/放在首选路径之前。

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

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