저는 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