new CI-based WebApp released…

#11
[eluser]mr.green[/eluser]
Pages Controller Src

Code:
<?

class Pages extends Controller
{    

    var $data = array();
    var $table = 'pages';
    var $back_url = '/admin/pages/pagelisting/';
    var $pagedata = array();
    var $id;


    function __construct()
    {
        parent::Controller();        

        check_permissions();

        $this->lang->load('application');    
        $this->id = (int) $id = $this->uri->segment(4, 0);        
        $this->load->model('base', 'BaseModel');
        $this->data['page_title'] = $this->lang->line('pages_crud');
        $this->data['current'] = '4';    

        $this->data['breadcrumb'] = array(
            'admin' => $this->config->item('admin_main_page'),
            'admin/pages/orderslist' => 'Текстовые блоки'
        );
    }
    

    function pageslisting()
    {      
        $this->back->captureUrl();

        // PAGINATION
        $pagination_config = array(
            'base_url' => '/admin/pages/pageslisting/page/',
            'total_rows' => $this->db->count_all($this->table),
            'uri_segment' => 5,
            'num_links' => 20,
            'per_page' => $this->config->item('crud_per_page'),
        );    

        $this->pagination->initialize($pagination_config);        

        $this->pagedata['pages'] = $this->BaseModel->GetLimitedData(

            $this->table,
            $offset = (int) $this->uri->segment(5, 0),
            $per_page = $this->config->item('crud_per_page'),
            $extra_where = '',
            $orderby = array('id', 'desc')
        );

        $this->data['page'] = $this->load->view('admin/datagrid/pages_list', $this->pagedata, true);
        $this->load->view('admin/layouts/main', $this->data);
    }


    function edit()
    {
        $this->back_url = $this->db_session->userdata['script_names'][0];

        // GET DATA FROM DATABASE
        if ($this->id)
        {
            $this->db->select('*');
            $query = $this->db->getwhere($this->table, array('id' => $this->id));

            if (!$this->pagedata['form'] = $query->row())
            {
                $this->db_session->set_flashdata('flashError', $this->lang->line('page_not_exists'), 1);
                redirect($this->back_url);
            }
        }

        $this->data['page_title'] .= $this->id
            ? ' / редактирование'
            : ' / добавление';

        // BREADCRUMB
        $this->pagedata['form']->title
            ? array_push_associative($this->data['breadcrumb'], array($this->pagedata['form']->title))
            : array_push_associative($this->data['breadcrumb'], array('Добавление страницы'));        

        // VALIDATION INIT
        $rules['title'] = 'required|trim';
        $fields['title'] = 'Название';

        $rules['text'] = 'required|trim';
        $fields['text'] = 'Текст';    

        $rules['alias'] = 'required|trim|alpha';
        $fields['alias'] = 'Алиас';    

        $this->validation->set_rules($rules);
        $this->validation->set_fields($fields);        
        // ***

        if ($this->validation->run())
        {
            $data['title'] = $this->input->post('title');
            $data['text'] = $this->input->post('text');
            $data['alias'] = $this->input->post('alias');

            if ($this->id) $this->db->update($this->table, $data, "id={$this->id}");
            else $this->db->insert($this->table, $data);                

            $this->db_session->set_flashdata('flashMessage', $this->config->item('success_message'), 1);
            redirect($this->back_url);
        }
        else
        {
            $this->data['page'] = $this->load->view('admin/forms/pages', $this->pagedata, true);
            $this->load->view('admin/layouts/main', $this->data);
        }
    }


    function delete()
    {
            $this->BaseModel->DeleteRow($this->table, $this->id);
            $this->db_session->set_flashdata('flashMessage', $this->lang->line('page_deleted'), 1);
            redirect($this->back_url);
    }
}
?>


Messages In This Thread
new CI-based WebApp released… - by El Forum - 07-01-2007, 03:43 AM
new CI-based WebApp released… - by El Forum - 07-02-2007, 12:45 AM
new CI-based WebApp released… - by El Forum - 07-02-2007, 04:49 AM
new CI-based WebApp released… - by El Forum - 07-02-2007, 09:27 AM
new CI-based WebApp released… - by El Forum - 07-02-2007, 10:45 AM
new CI-based WebApp released… - by El Forum - 07-02-2007, 12:19 PM
new CI-based WebApp released… - by El Forum - 07-02-2007, 01:33 PM
new CI-based WebApp released… - by El Forum - 07-02-2007, 08:46 PM
new CI-based WebApp released… - by El Forum - 07-02-2007, 11:02 PM
new CI-based WebApp released… - by El Forum - 07-02-2007, 11:03 PM
new CI-based WebApp released… - by El Forum - 07-03-2007, 04:02 AM
new CI-based WebApp released… - by El Forum - 07-03-2007, 04:07 AM
new CI-based WebApp released… - by El Forum - 07-03-2007, 04:23 AM
new CI-based WebApp released… - by El Forum - 07-03-2007, 04:25 AM
new CI-based WebApp released… - by El Forum - 07-03-2007, 09:37 AM
new CI-based WebApp released… - by El Forum - 07-06-2007, 02:12 PM
new CI-based WebApp released… - by El Forum - 04-26-2010, 05:47 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.