Bonjour,

J'ai un souci avec l'update sous CodeIgniter:

Je refais mon site, sous Codeigniter.

Je passe par Tinymce pour créer mes tutoriels.

Je souhaiterai les éditer.

Voila ce que j'ai fait :

Controller :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Tutoriel extends CI_Controller {
 
  public function __construct()
  {
    parent::__construct();
    $this->load->database();
    $this->load->helper(array('url','security', 'form'));
    $this->load->library('form_validation');
    $this->load->model('tutoriel_model');
    $this->load->model('tutoriel_status');
    $this->load->model('tutoriel_categorie');
 
 
  }
 
  public function nouveau_tutoriel() {
 
    $this->form_validation->set_rules('titre', "Titre", 'trim|required');
    if($this->form_validation->run())
    {
      $data['title'] = "Nouveau tutoriel";
 
      $this->tutoriel_model->contenu = $this->input->post('contenu');
      $this->tutoriel_model->status = $this->input->post('status');
      $this->tutoriel_model->titre = $this->input->post('titre');
 
      $this->tutoriel_model->ajouter_tutoriel($this->input->post('titre'), $this->input->post('contenu'), $this->input->post('status'), $this->input->post('categorie'));
 
      $this->load->view('common/header', $data);
      $this->load->view('dashboard/ecrire', $data);
    }
 
    else {
      $data['title'] = "Nouveau tutoriel";
      $this->load->view('dashboard/header_admin', $data);
      $this->load->view('dashboard/ecrire', $data);
    }
  }
 
 
 
  public function edit($id= NULL )
  {
    $id = $this->uri->segment(3);
 $this->tutoriel_model->load_all_tutoriel_by_id($id, TRUE);
 
   $this->tutoriel_model->edit($id);
    $data['title'] = "Édition du tutoriel";
 
    $this->load->view('common/header', $data);
    $this->load->view('dashboard/ecrire', $data);
 
  }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Tutoriel_model extends CI_Model {
  private $table = 'tutoriel';
 
  function ajouter_tutoriel($titre, $contenu, $status, $categorie)
  {
    return $this->db->set(array('titre' => $titre,
 
      'contenu' =>$contenu,
      'status' => $status,
      'categorie' => $categorie))
    ->set('date', 'NOW()', false)
    ->insert($this->table);
  }
 
  public function count()
  {
    return $this->db->count_all($this->table);
  }
 
  public function load_tutoriel($id)
  {
    $this->db->select('*');
    $this->db->from('tutoriel');
    $this->db->where('status', "P");
    $this->db->where('id', $id);
 
 
    $this->load_tutoriel = $this->db->get()->result();
 
    return $this->load_tutoriel;
 
 
  }
 
  public function load_all_tutoriel_by_id($id)
 
  {
 
    $this->db->select('*');
    $this->db->from('tutoriel');
    $this->db->where('id', $id);
 
 
    $this->load_all_tutoriel_by_id = $this->db->get()->result();
 
    return $this->load_all_tutoriel_by_id;
  }
 
  public function load_all_tutoriel()
  {
    $this->db->select('*');
    $this->db->from('tutoriel');
 
 
    $this->load_all_tutoriel = $this->db->get()->result();
 
    return $this->load_all_tutoriel;
  }
 
 
  public function edit($id)
  {
    $data = array(
    'titre' => $titre,
    'contenu' => $contenu,
    'status' => $status,
    'categorie' => $categorie);
 
    $this->db->where('id', $id);
    $this->db->update('tutoriel', $data);
  }
 
}
La vue :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
  <script src="<?php echo base_url()?>assets/js/tinymce/tinymce.min.js"></script>
  <script type='text/javascript' src="<?php echo base_url()?>/assets/js/tinymce/init.js"></script>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <?= ($title); ?>
        <hr />
      </div>
      <div class="row">
        <div class="col-md-12">
          <?= form_open('tutoriel/nouveau_tutoriel', ['class' => 'form-horizontal']); ?>
          <div class="form-group">
            <?= form_label("Titre:", "titre", ['class' => "col-md-2 control-label"]) ?>
            <div class="col-md-10 <?= empty(form_error('titre')) ? "" : "has-error" ?>">
              <?= form_input(['name' => "titre", 'id' => "titre", 'class' => 'form-control'], set_value('titre')) ?>
              <span class="help-block"><?= form_error('titre'); ?></span>
            </div>
          </div>
          <div class="form-group">
            <?= form_label("Contenu&nbsp;:", "contenu", ['class' => "col-md-2 control-label"]) ?>
            <div class="col-md-10 <?= empty(form_error('contenu')) ? "" : "has-error" ?>">
              <?= form_textarea(['name' => "contenu", 'id' => "contenu", 'class' => 'form-control'], html_entity_decode(set_value('contenu'))) ?>
              <span class="help-block"><?= form_error('contenu'); ?></span>
            </div>
          </div>
          <div class="form-group">
            <?= form_label("Statut&nbsp;:", "status", ['class' => "col-md-2 control-label"]) ?>
            <div class="col-md-10 <?= empty(form_error('status')) ? "" : "has-error" ?>">
              <?= form_dropdown("status", $this->tutoriel_status->text, set_value('status'), ['id' => "content", 'class' => 'form-control']) ?>
              <span class="help-block"><?= form_error('status'); ?></span>
            </div>
          </div>
 
          <div class="form-group">
            <?= form_label('Categories:', "categorie", ['class' => "col-md-2 control-label"])?>
            <div class="col-md-10 <?= empty(form_error('categorie')) ? "" : "has-error" ?>">
             <?= form_dropdown("categorie", $this->tutoriel_categorie->text, set_value('categorie'), ['id' => "content", 'class' => 'form-control']) ?>
             <span class="help-block"><?= form_error('categorie'); ?></span>
           </div>
         </div>
 
 
         <div class="form-group">
          <div class="col-md-offset-2 col-md-10">
            <?= form_submit("send", "Envoyer", ['class' => "btn btn-default"]); ?>
          </div>
        </div>
        <?= form_close() ?>
      </div>
    </div>
  </div>
</div>
</body>
</html>

J'attends vos retours avec impatience ...

Merci d'avance