Welcome Guest, Not a member yet? Register   Sign In
Post your controller!
#5

[eluser]Boris Strahija[/eluser]
Here's a controller from one of my first projects in CI, and generally MVC. It's very far from perfect, but I think it's ok for a start Wink
It's just the start of the controlle because of the charachter limit.
Code:
<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');    
    /**
     * Galleries Controller
     *
     * @author         Boris Strahija <[email protected]>
     * @copyright     Copyright (c) 2009, Boris Strahija, Creo
     * @version     0.1
     * @since         2009-04-11
     */
    class Galleries extends Controller {
        
        var $section = "galleries"; //marking the navi
        
        var $user_level = 0;
        
        /**
         * The constructor
         *
         */
        function __construct()
        {
            // Call the Controller constructor
            parent::Controller();
            
            //restricted access
            $this->auth->restrict();
            
            //load required models and libraries
            $this->load->model('mdl_galleries');
            
            //profiler
            show_profiler($this->section);
            
            //get user level
            $this->user_level = $this->auth->get_user_level($this->session->userdata('user_id'));
            
        } //end __contruct()
        
        
        
        /**
         * Index method
         *
         */
        function index()
        {
            $this->overview();
            
        } //end index()
        
        
        
        /**
         * List of all galleries
         *
         */
        function overview()
        {
            if ($this->user_level < 10) redirect('backend/galleries/exibitions');
            
            //set data to pass
            $data = array();
            
            //sections
            $data['section']         = $this->section;
            $data['section2']         = 'overview';
            //page title
            $data['title']             = $this->lang->line('core_galleries').' / '.$this->lang->line('core_overview');
            //headline and extra button
            $data['h2']             = $this->lang->line('core_gallery_overview'); //the main headline
            $data['hbutton']         = '<span class="action">| '.anchor('backend/galleries/gallery', $this->lang->line('core_new_gallery'), array('class'=>'add')).'</span>';
            //content view
            $data['content_view']     = 'galleries/grid';
            
            //action URL's (form and delete)
            $form_url     = base_url() . 'backend/galleries/gallery/';
            $delete_url = base_url() . 'backend/galleries/gallery/delete/';
            
            //get all records
            $data['list']             = $this->mdl_galleries->get(array('category_id'=>'1'));
            
            //build grid
            if ($data['list']) :
                //if only one result is returned create array
                $data['list'] = to_array($data['list']);
                
                //configure the grid
                $grid_cfg = array(
                     'cols'     => array(
                         array($this->lang->line('label_name'),     'name',         NULL,     NULL,         $form_url.'{id}',     NULL)
                        ,array($this->lang->line('label_updated'),     'updated',         140,     NULL,         NULL,                 'unix_to_human')
                        ,array($this->lang->line('label_actions'),     '{actions}',     60,     'edit',     NULL,                 NULL)
                     )
                    ,'actions'     => array(
                         array($this->lang->line('label_edit'),     $form_url.'{id}',         'edit')
                        ,array($this->lang->line('label_delete'),     $delete_url.'{id}',     'delete')
                     )
                    ,'sort'     => array('0,0', '1,0')
                    ,'pager'     => TRUE
                    ,'class'     => 'wide'
                );
                
                //create grid object
                $grid = new grid($data['list'], $grid_cfg);
                
                //get grid code
                $data['grid'] = $grid->get(FALSE);
                
            endif;
            
            //load the view
            $this->load->view('backend/core', $data);
            
        } //end overview()
        
        
        
        /**
         * List of all exibitions
         *
         */
        function exibitions()
        {
            //set data to pass
            $data = array();
            
            //sections
            $data['section']         = 'exibitions';
            $data['section2']         = 'overview';
            //page title
            $data['title']             = 'Exibitions / '.$this->lang->line('core_overview');
            //headline and extra button
            $data['h2']             = 'Exibition overview'; //the main headline
            $data['hbutton']         = '<span class="action">| '.anchor('backend/galleries/exibition', 'New exibition', array('class'=>'add')).'</span>';
            //content view
            $data['content_view']     = 'galleries/grid';
            
            //action URL's (form and delete)
            $form_url     = base_url() . 'backend/galleries/gallery/';
            $delete_url = base_url() . 'backend/galleries/gallery/delete/';
            
            //get all records
            $data['list']             = $this->mdl_galleries->get(array('category_id'=>'8'));
            
            //build grid
            if ($data['list']) :
                //if only one result is returned create array
                $data['list'] = to_array($data['list']);


Messages In This Thread
Post your controller! - by El Forum - 08-30-2009, 12:19 AM
Post your controller! - by El Forum - 08-30-2009, 01:36 AM
Post your controller! - by El Forum - 08-30-2009, 07:19 AM
Post your controller! - by El Forum - 08-30-2009, 12:31 PM
Post your controller! - by El Forum - 08-30-2009, 12:44 PM
Post your controller! - by El Forum - 08-30-2009, 08:59 PM
Post your controller! - by El Forum - 08-30-2009, 10:07 PM
Post your controller! - by El Forum - 08-31-2009, 02:13 AM
Post your controller! - by El Forum - 08-31-2009, 03:13 AM
Post your controller! - by El Forum - 08-31-2009, 03:19 AM
Post your controller! - by El Forum - 08-31-2009, 04:43 AM
Post your controller! - by El Forum - 08-31-2009, 04:49 AM
Post your controller! - by El Forum - 09-01-2009, 01:05 AM
Post your controller! - by El Forum - 09-01-2009, 09:30 PM
Post your controller! - by El Forum - 09-02-2009, 02:42 AM
Post your controller! - by El Forum - 09-02-2009, 05:34 AM
Post your controller! - by El Forum - 09-02-2009, 09:02 AM
Post your controller! - by El Forum - 09-02-2009, 09:43 AM
Post your controller! - by El Forum - 09-02-2009, 10:13 AM
Post your controller! - by El Forum - 09-02-2009, 01:13 PM
Post your controller! - by El Forum - 09-03-2009, 06:40 AM
Post your controller! - by El Forum - 11-03-2009, 10:20 PM
Post your controller! - by El Forum - 11-03-2009, 11:02 PM
Post your controller! - by El Forum - 11-03-2009, 11:33 PM
Post your controller! - by El Forum - 11-04-2009, 12:09 AM
Post your controller! - by El Forum - 11-04-2009, 03:36 AM
Post your controller! - by El Forum - 11-04-2009, 07:14 AM



Theme © iAndrew 2016 - Forum software by © MyBB