【问题标题】:Href Attribute Linked To Wrong Url in CodeIgniterHref 属性链接到 CodeIgniter 中的错误 URL
【发布时间】:2019-04-17 06:51:42
【问题描述】:

我正在开发 PHP MVC 框架 CodeIgniter,我的基本 url 设置如下:

$config['base_url'] = 'localhost/portal_advseed';

我通过在这一行更改 index.php 中的路径,在应用程序文件夹之外更改了我的视图文件夹:

$view_folder = 'theme';

我在主题文件夹中有一个 header.php 文件,其中有一些外部文件链接如下:

<link rel="apple-touch-icon" sizes="120x120" href="theme/app-assets/images/ico/apple-icon-120.png">

我有一个名为“Stock”的控制器,它有方法“view_stock”。在视图库存方法中,我正在加载标题视图文件,如下所示:

$this->load->view("header");

现在,当我在浏览器中运行 url http://localhost/portal_advseed/Stock/view_stock时,它会加载头文件,但不会加载外部文件。

我已经检查了查看源选项,href 属性显示如下:

<link rel="apple-touch-icon" sizes="120x120" href="theme/app-assets/images/ico/apple-icon-120.png">

当我点击 href 链接时,它会出现:

http://localhost/portal_advseed/Stock/theme/app-assets/images/ico/apple-icon-120.png

并且页面显示视图未找到错误很明显,它实际上应该转到链接:

http://localhost/portal_advseed/theme/app-assets/images/ico/apple-icon-120.png

那么为什么 href 链接到错误的 url?我在做什么错?

编辑:我也尝试添加 base_url 和 site_url 但它们也不起作用。而是在执行此 href 后链接到一个显示两次基本 url 的 url。

【问题讨论】:

    标签: php html codeigniter-3


    【解决方案1】:

    正如您所发现的,该链接是相对于当前页面的。您需要告诉链接它们在网站上的位置。你可以使用类似的东西:

    <link rel="apple-touch-icon" sizes="120x120" href="{$config['base_url']}theme/app-assets/images/ico/apple-icon-120.png">
    

    【讨论】:

      猜你喜欢
      • 2015-02-21
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 2014-10-21
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 2014-06-18
      相关资源
      最近更新 更多