私はCodeigniterでローカルに統計サイトを開発しています。Codeigniter: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変数に関するされています。私は、次のローカルホスト/サイト名/プレーヤー/ show_profile /プレイヤー名
私が現在持っているようなURLを持っています。 __constructには$player_name = $this->uri->segment(3);
がありますので、すべてのクラスメソッドで使用できます。これは私がそれをやるべきである方法ですか?
これは安全ですか?
「$ this-> uri-> segment(3);」というのはどうでしょうか? – Motive
私の投稿を更新しました。元のメソッドのプロトタイプである – Birdman
に固執すれば、それは必要ありません。ああ、私はCIがそれらをメソッドに渡したことに気付きませんでした。知っておいてよかった!助けてくれてありがとう。 – Motive