【发布时间】:2013-07-01 03:34:57
【问题描述】:
我是 MVC 和 Codeigniter 的新手,但我有一些工作虽然不是我想要的,但我想知道是否有人可以帮助我?
我的网站(联赛、球员)在 codeigniter 子目录中有 2 个页面,目前我访问它们的 URL 是“http://www.mydomain.co.uk/codeigniter/index.php/golf”和“http://www.mydomain.co.uk/codeigniter/index.php/players”
1) 如何从 URL 中删除 index.php?我试过 $config['index_page'] = '';在 config/config.php 并设置 .htaccess 文件,但没有运气。
2) 我只想将我在 routes.php 中的默认控制器指向高尔夫控制器,并让控制器处理请求的任何页面。
3)我是否正确设置了它,或者如果没有,那么正确的方法是什么?一个控制器好吗?
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ codeigniter/index.php/$1 [L]
config/routes.php
$route['default_controller'] = 'golf';
$route['players'] = 'golf/players'; <-Don't really want this entry!
config/autoload.php
$autoload['libraries'] = array('database');
$autoload['helper'] = array('url');
controllers/golf.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Golf extends CI_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->load->model('league_model');
$data['league'] = $this->league_model->get_League();
$data['title'] = 'League Table';
$this->load->view('templates/header', $data);
$this->load->view('templates/menu');
$this->load->view('league', $data);
$this->load->view('templates/footer');
}
public function players() { //Runs because of entry in config/routes.php
$route['players'] = 'golf/players';
$data['title'] = 'Players';
$this->load->view('templates/header', $data);
$this->load->view('templates/menu');
$this->load->view('players', $data);
$this->load->view('templates/footer');
}
}
?>
models/league_model.php
<?php
class League_model extends CI_Model {
public function __construct() {
}
public function get_League() {
$this->db->from("player");
$this->db->order_by("name", "asc");
$query = $this->db->get();
return $query->result_array();
}
}
?>
views/league.php
<p><?php echo $title; ?></p>
<?php foreach ($league as $item): ?>
<p><?php echo $item['name']." : ".$item['handicap']." : ".$item['bbnetbirdie']." : ".$item['bb4p'] ?></p>
<?php endforeach ?>
views/players.php
<p>This is players</p>
【问题讨论】:
标签: codeigniter codeigniter-routing