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 - Fatal编程技术网

Php CodeIgniter-路由和分页

Php CodeIgniter-路由和分页,php,codeigniter,Php,Codeigniter,这是我第一次尝试在CI中分页,我遇到了一个小问题,很可能是路由造成的 我的规则如下: $route['User/(:num)/(:any)'] = 'User/index/$1'; $route['user/(:num)/(:any)'] = 'User/index/$1'; 这些被翻译成类似http://site.com/index.php/user/1/tomek 现在,我的分页控制器: $config['base_url'] = site_url('user').'/'.$user.'/

这是我第一次尝试在CI中分页,我遇到了一个小问题,很可能是路由造成的

我的规则如下:

$route['User/(:num)/(:any)'] = 'User/index/$1';
$route['user/(:num)/(:any)'] = 'User/index/$1';
这些被翻译成类似
http://site.com/index.php/user/1/tomek

现在,我的分页控制器:

$config['base_url'] = site_url('user').'/'.$user.'/'.$data['user'][0]['nick'].'/';
$config['total_rows'] = $this->rating_model->countOwned($user);
$config['per_page'] = 2;
$config['enable_query_strings'] = true;
$this->pagination->initialize($config);
...
$data['owns'] = $this->rating_model->getOwned($data['user'][0]['id'],$config['total_rows'],$config['per_page']);
在我的模型中,我使用了简单的
限制

public function getOwned($user,$limit,$start) {
    $this->db->limit($limit,$start);
    ...
链接和所有的工作都很好,但它们不工作。我得到了一个类似
http://site.com/index.php/user/1/tomek/2
,但物品仍然完好无损。我的错在哪里

编辑>完成控制器代码:

public function index($user = null) {
        $session_data = $this->session->userdata('user_data');
        $this->db->cache_off();

        if($session_data) :

            $this->load->helper(array('form', 'url'));
            $this->load->library('pagination');
            $this->load->model('user_model');
            $this->load->model('rating_model');
            $this->load->model('games_model');

            if($user) {
                $user = $user;
            } else {
                $user = $session_data['id'];
            }

            //vars
                $data['user'] = $this->user_model->getUser($user);
                $data['title'] = $data['user'][0]['nick'].' · Profil użytkownika';
                $data['age'] = $this->user_model->getAge($data['user'][0]['birth']);
                $data['sex'] = $this->user_model->getSex($data['user'][0]['sex']);

                $config['base_url'] = site_url('user').'/'.$user.'/'.$data['user'][0]['nick'].'/';
                $config['total_rows'] = $this->rating_model->countOwned($user);
                $config['per_page'] = 4;
                $config['enable_query_strings'] = true;
                $this->pagination->initialize($config);

                $data['pages'] = $this->pagination->create_links();

                $data['rates'] = $this->rating_model->countRates($user);
                $data['rates2'] = $this->rating_model->countGrades($user);

                $data['developers'] = $this->games_model->getDevelopers();
                $data['genres'] = $this->games_model->getGenres();
                $data['platforms'] = $this->games_model->getPlatforms();

                $data['nowPlaying'] = $this->rating_model->getNowPlaying($data['user'][0]['id']);

                $data['owns'] = $this->rating_model->getOwned($data['user'][0]['id'],$config['total_rows'],$config['per_page']);

                //load
                $this->template->load('template','theme/yourAccount/main', $data);

        else :

                $this->load->view('unlogged');

        endif;
    }
以下url“http://site.com/index.php/user/1/tomek/2“需要: $route['User/(:num)/(:any)/(:num)]='User/index/$1/$2/$3'


您可能可以将索引排除在路由之外。因为这是它调用的标准函数。

问题实际上在
uri\u段中。我必须指出,url的哪一部分是页码。像这样:
$config['uri_segment']=5和我加载我的页面时:

$data['owns'] = $this->rating_model->getOwned($data['user'][0]['id'],4,$this->uri->segment(5));

效果很好。谢谢大家的帮助

希望这会有所帮助。分页中的两个重要因素是uri段和查询的限制偏移量。如果您尝试完成$config(不需要用于格式化的那些),比如$cofig['uri_segment'],它也可能对您有所帮助

尝试检查这个链接,检查结构和算法,可能会有所帮助。

第四个uri段应该传递给模型中的
$start
。这是真的吗?如果是,你是怎么做到的?我不会通过第四部分。我该怎么做?我正在学习CI的教程()。我添加了此路径,但没有帮助。它是否达到了您的索引功能?您是否放置了模具()并进行了测试?