我正在本地開發Codeigniter中的統計信息站點。我有一個像本地主機/網站名稱/播放/ show_profile/PlayerNameCodeigniter:從url中放置變量的位置
我現在有一個網址如下:
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Player extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('player_model');
$player_name = $this->uri->segment(3);
}
public function index()
{
echo "index";
}
public function show_profile($player_name)
{
$data['player_stats'] = $this->player_model->get_stats($player_name);
$this->load->view('player/player_stats', $data);
}
}
?>
這工作,但我的問題是關於$ PLAYER_NAME變量。 __construct中有$player_name = $this->uri->segment(3);
,因此它可用於所有類方法。這是我應該這樣做的方式嗎?
這是安全嗎?
那麼'$ this-> uri-> segment(3)呢? – Motive 2012-02-23 19:04:31
我已更新我的帖子。你不需要它,如果你堅持你原來的方法原型 – Birdman 2012-02-23 19:06:11
哦,我沒有意識到,CI通過這些方法。很高興知道!謝謝您的幫助。 – Motive 2012-02-23 19:13:06