【问题标题】:change the url scheme更改 url 方案
【发布时间】:2012-07-06 14:25:56
【问题描述】:

我正在使用 hmvc 创建一个注册页面:- 现在我在网址中输入:- http://localhost/CI/index.php/user/registration

user 是模块名

控制器:-registration.php

<?php
class Registration extends MX_Controller{
    function index() {
        $this->load->view('homepage');
    }

    function register(){
        $this->load->view('registrationPage');
    }
}
?>

查看:-homepage.php

<html>
<body>
    <a href="registration/register">register</a>
</body>
</html>

问题是在我的网址中我必须输入http://localhost/CI/index.php/user/registration/register 才能进入注册页面。

我想要http://localhost/CI/index.php/user/register,我们该怎么做。? 设置 base_url 不起作用,设置路由 ia 也不起作用。 这是否可以转到任何页面而不在 url 中提供模块名称..?

【问题讨论】:

  • 只需将您的 anchor tag 更改为 注册 :-)
  • no buddy.. :( 找不到它的说页面.....
  • 你能告诉我当你得到page not found时url显示的是什么
  • 显示http://localhost/CI/index.php/register
  • 对不起,我误解了你的问题。现在我的建议是您可以在 PHP 的 .htaccess 文件中进行 URL 重定向。

标签: php codeigniter codeigniter-url


【解决方案1】:

编辑你routes.php配置文件夹下的文件

$route['user/register'] = 'user/registration/register';

【讨论】:

  • 我已经完成了那件事,但是当我单击 homepage.php 中的注册链接时它不起作用\
  • 如果你的注册链接是这样的&lt;a href="registration/register"&gt;register&lt;/a&gt; 更改$route['registration/register'] = 'user/registration/register';
  • 你绝对应该使用这个。要添加,您应该使用&lt;?= base_url('user/register') ?&gt;
【解决方案2】:

您可以在.htaccess 文件中使用url rewriteurl rewriting without htaccess how to do url-rewriting in PHP

在 CodeIgniter 中,.htaccess 存在于 system/application/config/config.php

获取更多信息here,因为我不知道 CodeIgniter

【讨论】:

  • 我无法保存 .htaccess 文件。它显示错误:- you must type a filename :(
【解决方案3】:

您应该通过在您的主机文件中添加一个条目来为您的网站创建一个正确的 URL。例如:

127.0.0.1 http://mysitename

127.0.0.1 http://localhost.mysitename

Google 如何在 apache 中设置虚拟主机。您应该能够找到很多关于此的文章。现在编辑您的 apache 配置以启用虚拟主机。启用此功能后,您将为您的站点创建一个虚拟主机条目。虚拟主机告诉 apache 将您选择的 URL 映射到项目文件的特定目录路径。 (这样实际的目录路径就不是 URL 的一部分。)

接下来您应该编辑您的 .htaccess 以便始终通过 index.php 前端控制器路由请求。完成此操作后,您将不必使用“/index.php/”作为每个 URL 的一部分。阅读 Code Igniter 用户指南中称为 Code Igniter URLs 的部分。它具有示例 .htaccess 配置。此外,它还解释了 Code Igniter URL 的工作原理。

为了让 CI 与虚拟主机一起工作,您必须在 CI 配置文件中设置基本 URL 以匹配 v-host URL。

完成所有这些后,您需要重新启动 apache。

现在您可以根据您想要的 URL 结构来命名您的控制器和方法。在这种情况下,一个名为 user.php 的控制器带有一个名为 register 的方法。

【讨论】:

  • 嗯谢谢你的回复......但我在codeigniter中使用hmvc,用户是我的模块名称控制器名称是注册和功能是注册..我在url中得到的是: - ../index.php/module_name/controller_name/controller_function。我只想../index.php/controller_name/controller_function 不包括模块名称..有没有办法做到这一点..?
  • 你能告诉我篝火是用来做什么的吗?
【解决方案4】:

在您的项目中必须使用 HMVC 吗?否则,请选择简单的 Codeigniter 方式,因为这是您在这种情况下所期望的。

【讨论】:

  • hmmm...hmvc 将分离每个模块.. 它可以用简单的 codeigniter 完成,但我无法创建不同的模块..所以我使用 HMVC]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-31
  • 1970-01-01
  • 2010-10-15
  • 2012-08-30
  • 2017-12-05
  • 2021-05-06
相关资源
最近更新 更多