Jump to content
Robert1995

Codeigniter Models ( basic )

Recommended Posts

Posted (edited)

Mi-am facut niste modele in code igniter pentru SQL , cine stie poate va trebuie si voua :)


<?php
class SubPage extends CI_Model {

function __construct()
{
// Call the Model constructor
parent::__construct();
}

public function getAll(){
$sql="SELECT * FROM sub_page where hidden = 0 order by creation_date desc";
$r = $this->db->query($sql);
return $r->result_array();

}

public function getById($id){
$this->db->from('sub_page');
$this->db->where('id', $id);
$r = $this->db->get();
return $r->result_array();
}

public function getAllByPageId($page_id){
$this->db->from('sub_page');
$this->db->where('page_id', $page_id);
$this->db->where('hidden', 0);
$r = $this->db->get();
return $r->result_array();
}

public function getLastTen()
{
$sql="SELECT * FROM sub_page where hidden = 0 order by creation_date desc limit 10";
$r = $this->db->query($sql);
return $r->result_array();
}

public function enableById($id){
$data = array(
'hidden' => 0
);
$this->db->where('id', $id);
$this->db->update('sub_page', $data);
}

public function disableById($id){
$data = array(
'hidden' => 1
);
$this->db->where('id', $id);
$this->db->update('sub_page', $data);
}

}

Astept comentarii :)

P.S Mi-au trebuit 30 minute sa-mi dau seama de un lucru banal ce am uitat sa il fac , cine stie poate si voi aveti problema asta si va pot va ajuta :) in 'autoload' adaugati '$autoload['libraries'] = array('database');'

Edited by Robert1995
greseli gramaticale

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...