简体   繁体   English

CodeIgniter-无法设置路由

[英]CodeIgniter - cannot set routing

I have a problem with CI. 我对CI有问题。 I have a model: 我有一个模型:

public function Game($id) {
    $id = (int)$id;

    $q = $this -> db -> get_where('games', array('id' => $id));
    return $q -> row_array();
}

Controller for it: 控制器:

public function index($gameID) {
    $data['game'] = $this->games_model->Game($gameID);
    $this -> load -> view('games/game', $data);
}

And a problem ;) I've set my routing as follows: 和一个问题;)我将路由设置如下:

$route['games/(:num)'] = 'games/game/$1';
$route['games'] = 'games/game/game';

But it doesn't work at all. 但这根本不起作用。 My controller dir is games/game.php (with function Game inside). 我的控制器目录是games/game.php (具有Game内部功能)。 My problem is - how can I pass $id for it? 我的问题是-如何通过$id I am very new to CI, but I couldn't find solution for this in docs. 我对CI非常陌生,但是我在文档中找不到解决方案。

You can use either remap or you will have to modify your routes path again. 您可以使用重新映射,否则将不得不再次修改路线。 Take a look at this question, that's been asked here. 看看这个问题,这里已经有人问过。

$route['games'] = 'games/game/index'; // Folder/Controller/Function
$route['games/(:num)'] = 'games/game/index/$1'; // Folder/Controller/Function/Method
$route['games/(:num)/(:any)'] = 'games/game/index/$1/$2'; 

If you want to use slug, url_title($title, 'underscore', TRUE) it help you 如果您想使用slug, url_title($ title,'underscore',TRUE),它将为您提供帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM