Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php CodeIgniter-路由问题(四部分)_Php_Codeigniter_Routing_Calendar_Routes - Fatal编程技术网

Php CodeIgniter-路由问题(四部分)

Php CodeIgniter-路由问题(四部分),php,codeigniter,routing,calendar,routes,Php,Codeigniter,Routing,Calendar,Routes,根据我认为的问题,我发现这实际上是一个路由问题。问题是,我无法真正找出问题所在,因为它看起来与我正在使用的另一条路线完全相同,运行良好,但这条路线有两个可变段,而不是一个(对于正在运行的路线) 我试图显示的文件位于: [主文件夹]/application/views/tasks/calendar/calendar.php 我可以用命令加载它: $route['tasks/calendar'] = 'tasks/calendar'; 但是,当我想将当前年份和月份作为最后两个部分时,它不起作用:

根据我认为的问题,我发现这实际上是一个路由问题。问题是,我无法真正找出问题所在,因为它看起来与我正在使用的另一条路线完全相同,运行良好,但这条路线有两个可变段,而不是一个(对于正在运行的路线)

我试图显示的文件位于:

[主文件夹]/application/views/tasks/calendar/calendar.php

我可以用命令加载它:

$route['tasks/calendar'] = 'tasks/calendar';
但是,当我想将当前年份和月份作为最后两个部分时,它不起作用:

$route['tasks/calendar/(:num)/(:num)']  = 'tasks/calendar/$1/$2';
据我所知,这应该意味着这样的链接应该有效:

(…)/index.php/tasks/calendar/2015/03

然而,事实并非如此。完整的routes.php如下所示:

$route['auth/(:any)']                   = 'auth/view/$1';
$route['auth']                          = 'auth';
$route['projects/delete/(:any)']        = 'projects/delete/$1';
$route['projects/create']               = 'projects/create';
$route['projects/(:any)']               = 'projects/view/$1';
$route['projects']                      = 'projects';
$route['(:any)']                        = 'pages/view/$1';
$route['default_controller']            = 'pages/view';
$route['category']                      = 'category';
$route['category/(:any)']               = 'category/view/$1';
$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';
public function calendar($year = null, $month = null) {
    // 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);

    // Set variables for $data array
    $data['year']  = $year;
    $data['month'] = $month;

    // Show page, including header and footer
    $this->load->view('templates/header', $data);
    $this->load->view('tasks/calendar', $data);
    $this->load->view('templates/footer');
}
<?php
echo "Selected year: ".$year." and month: ".$month;
echo $this->calendar->generate($year, $month);
我的控制器,tasks.php,如下所示:

$route['auth/(:any)']                   = 'auth/view/$1';
$route['auth']                          = 'auth';
$route['projects/delete/(:any)']        = 'projects/delete/$1';
$route['projects/create']               = 'projects/create';
$route['projects/(:any)']               = 'projects/view/$1';
$route['projects']                      = 'projects';
$route['(:any)']                        = 'pages/view/$1';
$route['default_controller']            = 'pages/view';
$route['category']                      = 'category';
$route['category/(:any)']               = 'category/view/$1';
$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';
public function calendar($year = null, $month = null) {
    // 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);

    // Set variables for $data array
    $data['year']  = $year;
    $data['month'] = $month;

    // Show page, including header and footer
    $this->load->view('templates/header', $data);
    $this->load->view('tasks/calendar', $data);
    $this->load->view('templates/footer');
}
<?php
echo "Selected year: ".$year." and month: ".$month;
echo $this->calendar->generate($year, $month);
非常简单的视图文件,calendar.php,如下所示:

$route['auth/(:any)']                   = 'auth/view/$1';
$route['auth']                          = 'auth';
$route['projects/delete/(:any)']        = 'projects/delete/$1';
$route['projects/create']               = 'projects/create';
$route['projects/(:any)']               = 'projects/view/$1';
$route['projects']                      = 'projects';
$route['(:any)']                        = 'pages/view/$1';
$route['default_controller']            = 'pages/view';
$route['category']                      = 'category';
$route['category/(:any)']               = 'category/view/$1';
$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';
public function calendar($year = null, $month = null) {
    // 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);

    // Set variables for $data array
    $data['year']  = $year;
    $data['month'] = $month;

    // Show page, including header and footer
    $this->load->view('templates/header', $data);
    $this->load->view('tasks/calendar', $data);
    $this->load->view('templates/footer');
}
<?php
echo "Selected year: ".$year." and month: ".$month;
echo $this->calendar->generate($year, $month);

问题在于您的路线顺序。这些路线:

$route['(:any)']                        = 'pages/view/$1';
$route['default_controller']            = 'pages/view'
应该位于路线列表的最底部,否则它们将显示在任务路线之前

参考资料:


注意:路由将按照定义的顺序运行。更高路线 将始终优先于较低的


问题是你的路线顺序。这些路线:

$route['(:any)']                        = 'pages/view/$1';
$route['default_controller']            = 'pages/view'
应该位于路线列表的最底部,否则它们将显示在任务路线之前

参考资料:


注意:路由将按照定义的顺序运行。更高路线 将始终优先于较低的


问题是你的路线顺序。这些路线:

$route['(:any)']                        = 'pages/view/$1';
$route['default_controller']            = 'pages/view'
应该位于路线列表的最底部,否则它们将显示在任务路线之前

参考资料:


注意:路由将按照定义的顺序运行。更高路线 将始终优先于较低的


问题是你的路线顺序。这些路线:

$route['(:any)']                        = 'pages/view/$1';
$route['default_controller']            = 'pages/view'
应该位于路线列表的最底部,否则它们将显示在任务路线之前

参考资料:


注意:路由将按照定义的顺序运行。更高路线 将始终优先于较低的


根据@Craig和@CodeGodie刚才所说的内容,您需要稍微重新排序您的路线定义

$route['tasks']                         = 'tasks/index';

// Initial route that will use $year=null, $month=null
$route['tasks/calendar']                = 'tasks/calendar';

// This route will use whatever $year, $month the user provides
$route['tasks/calendar/(:num)/(:num)']  = 'tasks/calendar/$1/$2';
您可能还希望将$year=null、$month=null设置为有效值

$today = getdate();

if(is_null($year) || is_null($month)){
    $year  = $today['year'];
    $month = $today['month']
}

根据@Craig和@CodeGodie刚才所说的内容,您需要稍微重新排序您的路线定义

$route['tasks']                         = 'tasks/index';

// Initial route that will use $year=null, $month=null
$route['tasks/calendar']                = 'tasks/calendar';

// This route will use whatever $year, $month the user provides
$route['tasks/calendar/(:num)/(:num)']  = 'tasks/calendar/$1/$2';
您可能还希望将$year=null、$month=null设置为有效值

$today = getdate();

if(is_null($year) || is_null($month)){
    $year  = $today['year'];
    $month = $today['month']
}

根据@Craig和@CodeGodie刚才所说的内容,您需要稍微重新排序您的路线定义

$route['tasks']                         = 'tasks/index';

// Initial route that will use $year=null, $month=null
$route['tasks/calendar']                = 'tasks/calendar';

// This route will use whatever $year, $month the user provides
$route['tasks/calendar/(:num)/(:num)']  = 'tasks/calendar/$1/$2';
您可能还希望将$year=null、$month=null设置为有效值

$today = getdate();

if(is_null($year) || is_null($month)){
    $year  = $today['year'];
    $month = $today['month']
}

根据@Craig和@CodeGodie刚才所说的内容,您需要稍微重新排序您的路线定义

$route['tasks']                         = 'tasks/index';

// Initial route that will use $year=null, $month=null
$route['tasks/calendar']                = 'tasks/calendar';

// This route will use whatever $year, $month the user provides
$route['tasks/calendar/(:num)/(:num)']  = 'tasks/calendar/$1/$2';
您可能还希望将$year=null、$month=null设置为有效值

$today = getdate();

if(is_null($year) || is_null($month)){
    $year  = $today['year'];
    $month = $today['month']
}


大多数路线都是1=1。你不能把它们设置成这样,想详细说明一下吗?我的所有其他路线都在工作,为什么会这样,如果它们没有功能的话?当然,它们工作,因为它们什么都不做。让我举例说明:
$route['auth']='auth'
表示将段中包含auth的任何URI重定向到auth类,即tld/auth重定向到.tld/auth。Idk首先你的问题是什么,但我不认为路由是原因。“路由将按照它们定义的顺序运行。较高的路由将始终优先于较低的路由。”尝试将“任务/日历/(:num)/(:num)”移到顶部。感谢Craig,如果我将其作为列表中的第一行,它实际上是有效的。然而,我不明白为什么,因为这已经是“任务”的第一条路线了。它仍然选择了任务的索引页?你的大多数路线都是1=1。你不能把它们设置成这样,想详细说明一下吗?我的所有其他路线都在工作,为什么会这样,如果它们没有功能的话?当然,它们工作,因为它们什么都不做。让我举例说明:
$route['auth']='auth'
表示将段中包含auth的任何URI重定向到auth类,即tld/auth重定向到.tld/auth。Idk首先你的问题是什么,但我不认为路由是原因。“路由将按照它们定义的顺序运行。较高的路由将始终优先于较低的路由。”尝试将“任务/日历/(:num)/(:num)”移到顶部。感谢Craig,如果我将其作为列表中的第一行,它实际上是有效的。然而,我不明白为什么,因为这已经是“任务”的第一条路线了。它仍然选择了任务的索引页?你的大多数路线都是1=1。你不能把它们设置成这样,想详细说明一下吗?我的所有其他路线都在工作,为什么会这样,如果它们没有功能的话?当然,它们工作,因为它们什么都不做。让我举例说明:
$route['auth']='auth'
表示将段中包含auth的任何URI重定向到auth类,即tld/auth重定向到.tld/auth。Idk首先你的问题是什么,但我不认为路由是原因。“路由将按照它们定义的顺序运行。较高的路由将始终优先于较低的路由。”尝试将“任务/日历/(:num)/(:num)”移到顶部。感谢Craig,如果我将其作为列表中的第一行,它实际上是有效的。然而,我不明白为什么,因为这已经是“任务”的第一条路线了。它仍然选择了任务的索引页?你的大多数路线都是1=1。你不能把它们设置成这样,想详细说明一下吗?我的所有其他路线都在工作,为什么会这样,如果它们没有功能的话?当然,它们工作,因为它们什么都不做。让我举例说明:
$route['auth']='auth'表示重定向segm中包含auth的任何URI