나는 아주 명백한 것을 놓치고 있을지 모르지만, 나는 아직도 길을 잃어 버렸다. 실제 데이터베이스 상호 작용이 잡을 것 같습니다. 즉, 테이블은 설치시 만들어 지지만 정보를 보내면 입력 한 내용에 관계없이 유효성 검사가 실행되므로 실제로 작동하지 않는 것 같습니다. 필드 요구 사항을 해제하면 데이터베이스가 정보를 완전히받지 못합니다. 컨트롤러에서PyroCMS/Codeigniter 데이터베이스 문제
는 :
수준의 관리자는 모듈의 목적이있는 details.php 파일
public function install()
{
$this->dbforge->drop_table('shows');
$shows = "
CREATE TABLE ".$this->db->dbprefix('shows')." (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` varchar(100) NOT NULL,
`location` varchar(300) NOT NULL,
`support` text,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
if($this->db->query($shows))
{
return TRUE;
}
}
에서 Admin_Controller {
private $show_validation_rules = array(
array(
'field' => 'date',
'label' => 'Date',
'rules' => 'trim|max_length[100]|required'
),
array(
'field' => 'location',
'label' => 'Location',
'rules' => 'trim|max_length[300]'
),
array(
'field' => 'support',
'label' => 'Support',
'rules' => 'trim|required'
)
);
public function __construct()
{
parent::__construct();
$this->load->model('shows_m');
$this->load->library('form_validation');
$this->lang->load('shows');
$this->load->helper('html');
$this->template->set_partial('shortcuts', 'admin/partials/shortcuts');
}
public function index()
{
$view_data = array();
$view_data['shows'] = $this->shows_m->get_all();
$this->template->build('admin/index', $view_data);
}
public function create()
{
$shows = $this->shows_m->get_all();
$this->form_validation->set_rules($this->show_validation_rules);
if ($this->form_validation->run())
{
if ($this->shows_m->insert_show($this->input->post()))
{
$this->session->set_flashdata('success', lang('shows.create_success'));
redirect('admin/shows/index');
} else {
$this->session->set_flashdata('error', lang('shows.create_error'));
redirect('admin/shows/create');
}
}
foreach($this->show_validation_rules as $rule)
{
$shows[$rule['field']] = $this->input->post($rule['field']);
}
$view_data = array(
'shows' => $shows
);
$this->template->build('admin/create', $view_data);
}
public function edit($id)
{
$this->form_validation->set_rules($this->show_validation_rules);
$show = $this->shows_m->get($id);
if (empty($show))
{
$this->session->set_flashdata('error', lang('shows.exists_error'));
redirect('admin/shows');
}
if ($this->form_validation->run())
{
if ($this->shows_m->update_entry($id, $this->input->post()) === TRUE)
{
if (isset($this->input->post()['delete']))
{
$this->session->set_flashdata('success', lang('shows.delete_success'));
redirect('admin/shows/');
}
else
{
$this->session->set_flashdata('success', lang('shows.update_success'));
redirect('admin/shows/edit/' . $id);
}
} else {
if (isset($this->input->post()['delete']))
{
$this->session->set_flashdata('error', lang('shows.delete_error'));
redirect('admin/shows/edit/' . $id);
}
else
{
$this->session->set_flashdata('error', lang('shows.update_error'));
redirect('admin/shows/edit/' . $id);
}
}
}
foreach($this->show_validation_rules as $rule)
{
if ($this->input->post($rule['field']))
{
$show[$rule['field']] = $this->input->post($rule['field']);
}
}
$view_data = array(
'shows' => $show
);
$this->template->build('admin/edit', $view_data);
}
public function delete($id = NULL)
{
$id_array = array();
if ($this->input->post())
{
$id_array = $this->input->post()['action_to'];
}
else
{
if ($id !== NULL)
{
$id_array[0] = $id;
}
}
if (empty($id_array))
{
$this->session->set_flashdata('error', lang('shows.id_error'));
redirect('admin/shows');
}
foreach ($id_array as $id)
{
$show = $this->shows_m->get($id);
if (!empty($show))
{
if ($this->shows_m->delete($id) == FALSE)
{
$this->session->set_flashdata('error', lang('shows.delete_error'));
redirect('admin/shows');
}
}
}
$this->session->set_flashdata('success', lang('shows.delete_success'));
redirect('admin/shows');
}
}
를 확장 즉, 공연 날짜, 위치 및 y 지원 밴드 및 기타 정보를 모듈에 의해 생성 된 태그를 사이트의 해당 페이지에 삽입하여.
나는 그것이 아주 간단해야하고 내가 명백한 것을 놓치고 있다고 생각하는 경향이 있지만 누가 압니다. 나는, 나에게 소리 지르는 것을 자유롭게 느낀다, 나는 그것을 바르게 평가할 것이다.
편집 :
클래스 Shows_m이 MY_Model를 확장하는 모델
코드는 {
public function get_all($limit = NULL)
{
$this->db->order_by("id", "desc");
if (isset($limit)){ $this->db->limit($limit); }
$results = $this->db->get('shows');
$result = $results->result_array();
return $result;
}
public function get($id)
{
$results = $this->db->get_where('shows', array('id' => $id));
$result = $results->row_array();
return $result;
}
public function insert_show($input)
{
$to_insert = array(
'date' => $input['date'],
'location' => $input['location'],
'support' => $input['support']
);
if ($this->db->insert('shows',$to_insert))
{
return TRUE;
} else {
return FALSE;
}
}
public function update_entry($id, $input)
{
$new_data = array(
'date' => $input['date'],
'location' => $input['location'],
'support' => $input['support']
);
if (isset ($input['delete']))
{
if($this->delete($id))
{
return TRUE;
} else {
return FALSE;
}
} else {
$this->db->where('id', $id);
if ($this->db->update('shows', $new_data))
{
return TRUE;
} else {
return FALSE;
}
}
}
public function delete($id)
{
if ($this->db->delete('shows', array('id' => $id)))
{
return TRUE;
} else {
return FALSE;
}
}
}
나머지 코드를 복사/붙여 넣기 할 수 있습니까? CI 포럼에있는 것처럼? 또한 문제가있는 페이지에서 생성 된 HTML을 확인하는 데 도움이 될 수 있습니다. – stormdrain
$ _POST를 $ this-> input-> post()로 변경하기 위해 게시물을 편집하면 실제로 죽음의 흰색 화면이 나타납니다. CodeIgniter에서 오류보고가 가능한 문제를 나타내지 않습니다. 또한 관리자 컨트롤러 및 해당 모델에 대한 전체 코드가 추가되었습니다. – Cory