Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Home extends CI_Controller {
- private $tpl;
- public function __construct(){
- parent::__construct();
- $this->load->model('addcats');
- }
- public function index(){
- $cats = $this->addcats->get();
- $tpl['cats'] = $cats;
- $tpl['content'] = 'home/index';
- $this->load->view('template', $tpl);
- }
- private function loadView($content) {
- $this->tpl['content'] = $content;
- $this->load->view('template', $this->tpl);
- }
- public function add(){
- $tpl['content'] = 'home/addcat';
- $this->load->view('template', $tpl);
- }
- public function cats($parent_id = 0){
- $this->db->where('parent_id', $parent_id);
- $data = $this->db->get('cats')->result_array();
- if(empty($data)){
- return;
- }
- echo '<ul>';
- foreach ($data as $key => $value) {
- echo '<li>'.$value['name'];
- $this->cats($value['id']);
- echo '</li>';
- }
- echo '</ul>';
- }
- public function create(){
- $post = $this->input->post();
- $this->addcats->parent_id = $post['parent_id'];
- $this->addcats->name = $post['name'];
- $this->addcats->sort = $post['sort'];
- $this->addcats->level = $post['level'];
- $this->addcats->create();
- $_SESSION['alert'] = 'თქვენი პოსტი წარმატებით დაემატა!';
- redirect('home/index');
- }
- public function delete($cat_id){
- $cats = $this->addcats->getUserById($cat_id);
- if(!$cats){
- redirect('home/index');
- }
- $cats->delete();
- redirect('home/index');
- }
- public function edit($cat_id) {
- $cats = $this->addcats->getUserById($cat_id);
- if(!$cats){
- redirect('home/index');
- }
- $tpl['cat_id'] = $cat_id;
- $tpl['addcats'] = $cats;
- $tpl['content'] = 'home/edit';
- $this->load->view('template', $tpl);
- }
- public function update($cat_id){
- $cat = $this->addcats->getUserById($cat_id);
- if(!$cat){
- redirect('home/index');
- }
- $post = $this->input->post();
- $cat->parent_id = $post['parent_id'];
- $cat->name = $post['name'];
- $cat->sort = $post['sort'];
- $cat->level = $post['level'];
- $cat->update();
- redirect('home/index');
- }
- }
- /* End of file home.php */
- /* Location: ./application/controllers/home.php */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement