개인 프로젝트를 위해 codeIgniter 2.2.0을 테스트하고 있습니다. 일부 자습서를 읽었지만 CRUD에 갇혀 있습니다. 요소를 삭제하고 싶을 때 리디렉션이 올바르게 작동하지만 요소를 억제하지 않습니다.
내 컨트롤러의 발췌 내용은 다음과 같습니다.
class Admin extends CI_Controller{
function __construct(){
parent::__construct();
}
function index(){
$data['heading'] = 'Panneau d\'administration';
$data['title'] = 'Général';
$data['content'] = 'admin_panel';
$this->load->view('admin/adminTemplate',$data);
}
function marques(){
$data['heading'] = 'Panneau d\'administration | Marques';
$data['title'] = 'Les marques';
$data['content'] = 'admin_marques';
$data['row'] = $this->admin_model->readMarque();
$this->load->view('admin/adminTemplate',$data);
}
/******************************************
================CRUD=======================
*******************************************/
/******************************************
CRUD Marques
*******************************************/
function updateMarque(){
if($this->uri->segment(3)){
$data['row'] = $this->admin_model->getMarque($this->uri->segment(3));
$data['heading'] = $data['row']->marque_lib;
$this->admin_model->update($this->uri->segment(3));
$this->load->view('admin_update', $data);
}
else{
redirect('admin');
}
}
function deleteMarque(){
//récupération de l'id dans ladresse
if($this->uri->segment(4)){
$this->admin_model->deleteMarque($this->uri->segment(4));
redirect('admin');
}
else{
redirect('index.php/admin');
}
}
function createMarque(){}
다음은 내 모델의 발췌입니다.
class Admin_model extends CI_Model{
function __construct(){
parent::__construct();
}
/******************************************
CRUD Marques
*******************************************/
function create_marque(){
}
function readMarque(){
$req = $this->db->get('marques');
if ($req->num_rows>0) {
foreach ($req->result() as $row) {
$data[] = $row;
}
return $data;
}
}
function updateMarque($id, $data){
$this->db->where('marque_id', (int)$id);
$this->db->delete('marques', $data);
}
function getMarque($id){
$this->db->where('marque_id', (int)$id);
$marque = $this->db->get('marques');
if($marque->num_rows>0){
$row = $marque->row();
return $row;
}
}
function deleteMarque($id){
$this->db->where('marque_id', $id);
$this->db->delete('marques');
}
그리고 내 견해는 다음과 같습니다.
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>Libellé</th>
<th>Chemin de l'image</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php
if ($row != null) :
foreach ($row as $infoMarque): ?>
<tr>
<td><?php echo $infoMarque->marque_id ; ?></td>
<td><?php echo $infoMarque->marque_lib ; ?></td>
<td><?php echo $infoMarque->marque_img_path ; ?></td>
<td>
<button type="button" class="btn btn-default btn-default">
<span class="glyphicon glyphicon-pencil"></span>
<a href="<?php echo site_url('index.php/admin/marques/updateMarque/'.$infoMarque->marque_id) ; ?>">Editer</a>
</button>
<button type="button" class="btn btn-default btn-default">
<span class="glyphicon glyphicon-remove"></span>
<a href="<?php echo site_url('index.php/admin/marques/deleteMarque/'.$infoMarque->marque_id) ; ?>">Supprimer</a>
</button>
</td>
</tr>
<?php endforeach; endif;?>
</tbody>
</table>
왜 이것이 작동하지 않는지 모르겠습니다. 컨트롤러 자체가 아닌 하위 페이지와 하위 페이지에 대한 작업이 있기 때문에 아마도 그럴 것이라고 생각했지만 ...
내 하찮은 영어 실력에 죄송하다는 말씀을 드리고 싶습니다
어떤 아이디어와 조언이라도 좋을 것입니다.
감사
늦은 답변 죄송합니다. 나는 이미 문제를 알아 냈다. 요소를 억제하는 링크에서 내 경로는
site_url('index.php/admin/marques/updateMarque/'.$infoMarque->marque_id)
그것은해야한다 :
site_url('index.php/admin/updateMarque/'.$infoMarque->marque_id)
action updateMarque ()가 marques의 '하위 함수'가 아니기 때문입니다.
아마 모든 사람들이 이미 이것을 알고 있을지도 모르지만 base_url () 함수를 사용하는 것이 더 낫다는 것을 발견했습니다. 링크에서 'index.php'를 억제 할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다