Anonymous
Создайте фронтенд-форум с помощью Codeigniter [закрыто]
Сообщение
Anonymous » 26 дек 2025, 00:40
У меня 3 стола
Код: Выделить всё
|forum_id|name_forum|
| 1 |forum 1 |
|thread_id|name_thread|forum_id|
| 1 |Thread 1 | 1 |
|post_id|name_post|text|thread_id|
| 1 | post 1 |tttt| 1 |
я создаю страницу 1 для отображения имени_форума
страницу 2 для отображения группы name_thread по forum_id (МОГУ ЛИ Я ВСТАВИТЬ NAME_THREAD GROUP BY FORUM_ID?)
страницу 3 для отображения name_post и текстовой группы по thread_id (МОГУ ЛИ Я ВСТАВИТЬ NAME_POST GROUP_BY) THREAD_ID )
Я создаю с помощью codeigniter. я могу показать всю эту проблему, но не могу вставить тему и опубликовать.
Код: Выделить всё
class Forum extends CI_Controller{
private $limit = 10;
function __construct() {
parent::__construct();
//load library helper
$this->load->library(array('table','form_validation'));
$this->load->helper(array('form','url'));
$this->load->model('home_forum_model','',TRUE);
$this->load->helper('date');
$this->is_logged_in();
}
function index($offset=0,$order_column='forum_id',$order_type='ASC')
{
if(empty($offset)) $offset=0;
if(empty($order_column)) $order_column='forum_id';
if(empty($order_type)) $order_type='asc';
//Untuk cek validasi kolom
//tanggal
$data['datestring'] ="Tanggal: %d %M %Y ";
$data['time']=time();
$data['zona']= timezones('UP7');
//load data siswa
$forums = $this->home_forum_model->get_paged_list($this->limit,$offset,$order_column,$order_type)->result();
//pagination
$this->load->library('pagination');
$config['base_url']= site_url('home/forum/index/');
$config['prev_link']='<Prev';
$config['next_link']='Next>';
$config['first_link']='<<First';
$config['last_link']='Last>>';
$config['total_rows']= $this->home_forum_model->count_all_forum();
$config['per_page'] = $this->limit;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
//table data
$this->load->library('table');
$this->table->set_empty(' ');
$tmpl = array ( 'table_open' => '' );
$this->table->set_template($tmpl);
//$new_order = ($order_type == 'asc'?'desc':'asc');
$this->table->set_heading(
'Nama Forum');
//$i=0+$offset;
foreach($forums as $forum)
{
$this->table->add_row(
anchor('home/forum/view_thread/'.$forum->forum_id,$forum->nama_forum,array('class'=>'view_thread') )
);
$this->table->add_row($forum->deskripsi);
}
$data['table']=$this->table->generate();
$data['content']='home/tampil_forum';
$this->load->view('template_home/template',$data);
}
function view_thread($id)
{
//tanggal
$data['datestring'] ="Tanggal: %d %M %Y ";
$data['time']=time();
$data['zona']= timezones('UP7');
$data['title']='Detail Forum';
$data['action']=site_url('home/forum/view_thread/');
$data['link_back']=anchor('home/forum/index/','Lihat Daftar Forum',array('class'=>'back'));
//ambil detail agenda
$data['threads']=$this->home_forum_model->get_thread_by_id($id)->result();
//load agenda
$data['content']='home/tampil_thread';
$this->load->view('template_home/template',$data);
}
Это модель
Класс Home_forum_model расширяет CI_Model{
Private $primary_key = 'forum_id';
Private $table_name = 'forum';
Код: Выделить всё
function __construct() {
parent::__construct();
}
function get_paged_list($limit=10,$offset=0,$order_column='',$order_type='asc')
{
if(empty($order_column) || empty($order_type))
{
$this->db->order_by('forum_id','asc');
}else{
$this->db->order_by($order_column,$order_type);
return $this->db->get('forum',$limit,$offset);
}
}
function get_forum()
{
return $this->db->get('forum');
}
function count_all_forum(){
return $this->db->count_all($this->table_name);
}
function count_all_thread(){
return $this->db->count_all('thread');
}
function count_all_post(){
return $this->db->count_all('post');
}
function get_post_by_id($id)
{
$this->db->select('post.*,post.nama_post as judulpost,post.text as isipost');
$this->db->from('post');
$this->db->join('thread','post.thread_id=thread.thread_id');
$this->db->where('post.thread_id',$id);
$this->db->order_by('post.post_id','asc');
return $this->db->get();
}
function get_thread_by_id($id)
{
$this->db->select('thread.*,thread.title as title,forum.nama_forum as forum');
$this->db->from('thread');
$this->db->join('forum','thread.forum_id = forum.forum_id');
$this->db->where('thread.forum_id',$id);
$this->db->order_by('thread.thread_id','desc');
return $this->db->get();
}
Подробнее здесь:
https://stackoverflow.com/questions/125 ... odeigniter
1766698811
Anonymous
У меня 3 стола [code]|forum_id|name_forum| | 1 |forum 1 | |thread_id|name_thread|forum_id| | 1 |Thread 1 | 1 | |post_id|name_post|text|thread_id| | 1 | post 1 |tttt| 1 | [/code] [list] [*]я создаю страницу 1 для отображения имени_форума [*]страницу 2 для отображения группы name_thread по forum_id (МОГУ ЛИ Я ВСТАВИТЬ NAME_THREAD GROUP BY FORUM_ID?) [*]страницу 3 для отображения name_post и текстовой группы по thread_id (МОГУ ЛИ Я ВСТАВИТЬ NAME_POST GROUP_BY) THREAD_ID ) [/list] Я создаю с помощью codeigniter. я могу показать всю эту проблему, но не могу вставить тему и опубликовать. [code]class Forum extends CI_Controller{ private $limit = 10; function __construct() { parent::__construct(); //load library helper $this->load->library(array('table','form_validation')); $this->load->helper(array('form','url')); $this->load->model('home_forum_model','',TRUE); $this->load->helper('date'); $this->is_logged_in(); } function index($offset=0,$order_column='forum_id',$order_type='ASC') { if(empty($offset)) $offset=0; if(empty($order_column)) $order_column='forum_id'; if(empty($order_type)) $order_type='asc'; //Untuk cek validasi kolom //tanggal $data['datestring'] ="Tanggal: %d %M %Y "; $data['time']=time(); $data['zona']= timezones('UP7'); //load data siswa $forums = $this->home_forum_model->get_paged_list($this->limit,$offset,$order_column,$order_type)->result(); //pagination $this->load->library('pagination'); $config['base_url']= site_url('home/forum/index/'); $config['prev_link']='<Prev'; $config['next_link']='Next>'; $config['first_link']='<<First'; $config['last_link']='Last>>'; $config['total_rows']= $this->home_forum_model->count_all_forum(); $config['per_page'] = $this->limit; $config['uri_segment'] = 4; $this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links(); //table data $this->load->library('table'); $this->table->set_empty(' '); $tmpl = array ( 'table_open' => '' ); $this->table->set_template($tmpl); //$new_order = ($order_type == 'asc'?'desc':'asc'); $this->table->set_heading( 'Nama Forum'); //$i=0+$offset; foreach($forums as $forum) { $this->table->add_row( anchor('home/forum/view_thread/'.$forum->forum_id,$forum->nama_forum,array('class'=>'view_thread') ) ); $this->table->add_row($forum->deskripsi); } $data['table']=$this->table->generate(); $data['content']='home/tampil_forum'; $this->load->view('template_home/template',$data); } function view_thread($id) { //tanggal $data['datestring'] ="Tanggal: %d %M %Y "; $data['time']=time(); $data['zona']= timezones('UP7'); $data['title']='Detail Forum'; $data['action']=site_url('home/forum/view_thread/'); $data['link_back']=anchor('home/forum/index/','Lihat Daftar Forum',array('class'=>'back')); //ambil detail agenda $data['threads']=$this->home_forum_model->get_thread_by_id($id)->result(); //load agenda $data['content']='home/tampil_thread'; $this->load->view('template_home/template',$data); } [/code] Это модель Класс Home_forum_model расширяет CI_Model{ Private $primary_key = 'forum_id'; Private $table_name = 'forum'; [code]function __construct() { parent::__construct(); } function get_paged_list($limit=10,$offset=0,$order_column='',$order_type='asc') { if(empty($order_column) || empty($order_type)) { $this->db->order_by('forum_id','asc'); }else{ $this->db->order_by($order_column,$order_type); return $this->db->get('forum',$limit,$offset); } } function get_forum() { return $this->db->get('forum'); } function count_all_forum(){ return $this->db->count_all($this->table_name); } function count_all_thread(){ return $this->db->count_all('thread'); } function count_all_post(){ return $this->db->count_all('post'); } function get_post_by_id($id) { $this->db->select('post.*,post.nama_post as judulpost,post.text as isipost'); $this->db->from('post'); $this->db->join('thread','post.thread_id=thread.thread_id'); $this->db->where('post.thread_id',$id); $this->db->order_by('post.post_id','asc'); return $this->db->get(); } function get_thread_by_id($id) { $this->db->select('thread.*,thread.title as title,forum.nama_forum as forum'); $this->db->from('thread'); $this->db->join('forum','thread.forum_id = forum.forum_id'); $this->db->where('thread.forum_id',$id); $this->db->order_by('thread.thread_id','desc'); return $this->db->get(); } [/code] Подробнее здесь: [url]https://stackoverflow.com/questions/12523928/build-frontend-forum-with-codeigniter[/url]