Welcome Guest, Not a member yet? Register   Sign In
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


Messages In This Thread
Update data in DB - by tonny16 - 07-05-2017, 11:36 PM
RE: Update data in DB - by rtenny - 07-06-2017, 04:23 AM
RE: Update data in DB - by tonny16 - 07-06-2017, 07:57 AM
RE: Update data in DB - by rtenny - 07-06-2017, 09:03 AM
RE: Update data in DB - by tonny16 - 07-06-2017, 10:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB