【问题标题】:CodeIgniter controller to view to another controller urlCodeIgniter 控制器查看另一个控制器 url
【发布时间】:2014-04-13 08:28:51
【问题描述】:

比如说,我从 controller1 加载了一个视图

网址应该是index.php/controller1/<function where view is ran>

然后从那个视图我有一个链接。

<a href='controller2/view'>View</a>

点击该链接后,网址现在如下所示。

index.php/controller1/controller2/view

有没有办法清除以前的url_segment,或者有更好的方法链接到另一个控制器的功能。

【问题讨论】:

  • 我使用&lt;?=base_url();?&gt;index.php/controller/view(显然在autoload.php中使用url助手)。

标签: php codeigniter hyperlink


【解决方案1】:

做。

<?=base_url(); ?>/controller2/view

在你的href里面。

【讨论】:

  • CI 是否有一些配置来启用 =$value?> 而不是 当我将代码传递给我的朋友时,他们通常会被打印为值。
  • 那是php5的新特性..看第5点@php.net/manual/en/migration54.new-features.php
  • 漂亮的版本(不可能有双重//)是base_url('controller2/view')
【解决方案2】:

你可以把链接写成

<a href='<?=base_url(); ?>controller2/view'>View</a>

记住你已经在config/config.php文件中设置了base_url

$config['base_url'] = 'http://yourSite';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-23
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 2016-01-01
    • 2012-12-19
    • 2019-12-09
    相关资源
    最近更新 更多