CodeIgniter - $ this-> uri-> segment()返回空 [英] CodeIgniter - $this->uri->segment() returns empty

查看:220
本文介绍了CodeIgniter - $ this-> uri-> segment()返回空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要 CodeIgniter日历库工作,为此,我需要使用 $ this-> uri-> segment(),至少根据文档。日历的网址如下所示:

I am trying to get the CodeIgniter calender library to work, and for that I need to use $this->uri->segment(), according to the documentation at least. The url for the calender looks like this:


http://www.example.com/index.php/tasks/calendar/2015/03

这就是说,根据我的理解, $ this-> uri->段(3 )是年, $ this-> uri-> segment(4)这个月。但是,这两个都不返回任何东西,这里是我的日历页面的代码:

Which means, as far as I can understand, that $this->uri->segment(3) would be the year, and $this->uri->segment(4) the month. However, both of these returns nothing at all, here is the code for my calender page:

echo "Selected year: ".$this->uri->segment(3)." and month: ".$this->uri->segment(4);
echo $this->calendar->generate($this->uri->segment(3), $this->uri->segment(4));

第一行仅用于调试目的,并确认没有命令返回任何输出。日历库在控制器中加载以下代码:

The first line is merely used for debugging purposes, and confirms that none of the commands returns any output. The calender library is loaded in the controller, with the following code:

public function calendar() {
    // Calender configuration (must be done prior to loading the library
    $conf = array(
            'start_day' => 'monday',
            'show_next_prev' => true,
            'next_prev_url' => base_url() . 'index.php/tasks/calendar'
    );

    // Load libraries and helpers
    $this->load->library('calendar',$conf);

    // Show page, including header and footer
    $this->load->view('templates/header', $data);
    $this->load->view('tasks/calendar', $data);
    $this->load->view('templates/footer');
}

任何人都可以告诉我我在哪里失败?

Can anyone tell me where I am failing? I read the documentation over and over again, and checked my code, but I can't see what I do different than their example?

UPDATE

我想我已经排除了问题与 $ this-> uri-> gt; section()函数有关。可能在控制器加载不正确的页面时,如果在... / tasks / calendar /(...)之后将其他部分添加到URL中。我仍然没有找到解决方案,但我想让你知道,如果其他人读这个有同样的问题。

I think I have ruled out that the problem is related to the $this->uri->section() function. Is likely to do with the controller loading an incorrect page, when additional sections is added to the URL after .../tasks/calendar/(...). I still haven't found a solution, but I wanted to let you know, in case others who read this had the same issue.

UPDATE 2

UPDATE 2

我认为这可能是一个路由问题,routes.php看起来像这样,与任务相关:

I think it might be a routing issue, the routes.php looks like this, for anything related to tasks:

$route['tasks/create']                  = 'tasks/create';
$route['tasks/calendar/(:num)/(:num)']  = 'tasks/calendar/$1/$2';
$route['tasks/calendar']                = 'tasks/calendar';
$route['tasks']                         = 'tasks';
$route['tasks/(:any)']                  = 'tasks/view/$1';


推荐答案

为了工作,你必须加载Codeigniter url helper,因为你使用 base_url()。你可以通过运行这个 $ this-> load-> helper('url'); 或者通过进入你的autoload.php, code>帮助器

for this to work you have to load the Codeigniter url helper since youre using base_url(). You can do this by running this $this->load->helper('url'); or by going to your autoload.php and placing it there in helper

这篇关于CodeIgniter - $ this-> uri-> segment()返回空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆