Model(3/5) - 소스 중복제거
* Controller 파일의 중복소스 제거
1. __construct()
- controller/topic.php (아래 소스의 빨간색 글씨로 되어 있는 부분이 중복되고 있다.)
function index() { $this->load->database(); $this->load->model('topic_model'); //topic_model.php 파일을 불러오겠다. $data=$this->topic_model->gets(); //topic_model.php 의 gets라는 method를 사용하여 $data에 넣겠다. $this->load->view('main',array('topics'=>$data)); } function get($id) { $this->load->database(); $this->load->model('topic_model'); $topic=$this->topic_model->get($id); $this->load->view('get',array('topic'=>$topic)); //기존 $id에서 $topic 값을 가져오는 것으로 수정. } |
- 중복제거
function __construct() { parent::__construct(); $this->load->database(); $this->load->model('topic_model'); } function index() { $data=$this->topic_model->gets(); //topic_model.php 의 gets라는 method를 사용하여 $data에 넣겠다. $this->load->view('main',array('topics'=>$data)); } function get($id) { $topic=$this->topic_model->get($id); $this->load->view('get',array('topic'=>$topic)); //기존 $id에서 $topic 값을 가져오는 것으로 수정. } |
2. function
- controller/topic.php (아래 소스의 빨간색 글씨로 되어 있는 부분이 중복되고 있다.)
function __construct() { parent::__construct(); $this->load->database(); $this->load->model('topic_model'); } function index() { $this->load->view('head'); $data=$this->topic_model->gets(); $this->load->view('topic_list',array('topics'=>$topics)); $this->load->view('main'); $this->load->view('footer'); } function get($id) { $this->load->view('head'); $data=$this->topic_model->gets(); $this->load->view('topic_list',array('topics'=>$topics)); $topic=$this->topic_model->get($id); $this->load->view('get',array('topic'=>$topic)); $this->load->view('footer'); } |
- 중복제거
function __construct() { parent::__construct(); $this->load->database(); $this->load->model('topic_model'); } function index() { $this->head(); $this->load->view('main'); $this->load->view('footer'); } function get($id) { $this->head(); $topic=$this->topic_model->get($id); $this->load->view('get',array('topic'=>$topic)); $this->load->view('footer'); } function head(){ $this->load->view('head'); $data=$this->topic_model->gets(); $this->load->view('topic_list',array('topics'=>$topics)); } |