【问题标题】:Is there a way to get the current object and method with CodeIgniter?有没有办法使用 CodeIgniter 获取当前对象和方法?
【发布时间】:2013-06-05 04:41:20
【问题描述】:

我正在寻找一个通过 URI 告诉我当前对象和方法的函数。通常,我会使用$this->uri->uri_string(),但是,我不想传递任何“动态”段。例如,'products/shoes/123' 的 URI 将是 'products/view_product'

我希望能够做到这一点,这样我就可以创建一个包含页面标题的配置文件......因为我使用模型来输出我的页面标题。它是从构造中的MY_Controller.php 调用的。例如:$this->template->overall_header($title = "View Product")...

但在构造中,它将是:

$this->template->overall_header($title = $this->config->item($object_method_string));

有人有解决办法吗?感谢您的宝贵时间。

【问题讨论】:

  • 这里的object是什么意思...方法中传入的参数?????

标签: codeigniter object methods


【解决方案1】:

对于当前方法 $method= $this->router->fetch_method();

我希望你在谈论这个

【讨论】:

    【解决方案2】:

    要扩展 Nishant 的 答案,您可以访问路由器类中的属性。

    所以对于当前对象;

    $this->router->class
    

    对于当前方法;

    $this->router->method
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多