• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Update data in DB

#1
I go through Tinymce to create pages.
I would like to edit them.
That's what I did:


I can not view the data to change it

Controller

PHP Code:
<?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($idNULL )
  {
    $id $this->uri->segment(3);
 $this->tutoriel_model->load_all_tutoriel_by_id($idTRUE);
  
   $this
->tutoriel_model->edit($id);
    $data['title'] = "Édition du tutoriel";
  
    $this
->load->view('common/header'$data);
    $this->load->view('dashboard/ecrire'$data);
  
  
}



Model :

PHP Code:
<?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);
  }
  



Vue : 

PHP Code:
<!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->textset_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->textset_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> 

Thanks for your help
Reply

#2
I can see your function edit()
But not that this function is ever called.
In you controller when the form is valid you need to call the edit function to save the data.

You also always call $this->tutoriel_model->ajouter_tutoriel() that will create a new record every time.
it will not update any existing data.
On the package it said needs Windows 7 or better. So I installed Linux.
Reply

#3
Great, I just noticed ...: /
Another question :
How do I make a redirect after sending the form?

Thanks you so much
Reply

#4
redirect('/start/');
or
redirect('/start/?container=' . $container);

just replace the url and parameter to fit your case.
On the package it said needs Windows 7 or better. So I installed Linux.
Reply

#5
Thank you very much.

Where do I write it?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.