【问题标题】:CodeIgniter - Turn off controller function call?CodeIgniter - 关闭控制器函数调用?
【发布时间】:2012-10-10 08:35:47
【问题描述】:

我只是想加载控制器而不是基于 URI 调用函数,这样我就可以根据以下段生成页面。 如何更改默认行为以执行此操作? 例如。

example.com/class/function/ID >>> example.com/class/ID/ID

我以为我需要做的就是在 config.php 中添加:

$route['find/(:any)/(:any)'] = "find/$1/$2";

但这给了我一个 404。


example.com/find/item/location

class Find extends CI_Controller {

private $s1;
private $s2;

function __construct()
{
    parent::__construct();
}

function index()
{
    $this->s1 = $this->uri->segment(2);
    $this->s2 = $this->uri->segment(3);
    $this->makePage();
}

function makePage()
{
    echo 'Page about ' . $this->s1 . 'in ' . $this->s2;
    //Get Data ($s1 & $s2)
    //Load View 
}
}

【问题讨论】:

    标签: php codeigniter codeigniter-routing


    【解决方案1】:

    想通了,需要添加另一个函数来调用(findit);

    $route['find/(:any)/(:any)'] = "find/findit/$1/$2";
    

    function findit()
    {
        $this->makePage();
    }
    

    我发现这篇文章很有帮助:CodeIgniter: Directing to functions with a URL segment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-22
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 2011-06-29
      相关资源
      最近更新 更多