Welcome Guest, Not a member yet? Register   Sign In
CI and Phil Strugeons REST API
#8

[eluser]moos3[/eluser]
Here is my controller. But if I'm understanding you correctly so /api/paste/pastes/ will automagically go to pastes_get()?

heres the pastes controller
Code:
<?php
class Main extends Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->model('languages');
    }
    
    function _form_prep($lang='php', $title = '', $paste='', $reply=false)
    {
        $this->load->model('languages');
        $this->load->helper("form");
        
        $data['languages'] = $this->languages->get_languages();        
        $data['scripts'] = array('jquery.js', 'jquery.timers.js');
        
        if(!$this->input->post('submit'))
        {
            if($this->db_session->flashdata('settings_changed'))
            {
                $data['status_message'] = 'Settings successfully changed';
            }
            
            $data['name_set'] = $this->db_session->userdata('name');
            $data['expire_set'] = $this->db_session->userdata('expire');
            $data['acopy_set'] = $this->db_session->userdata('acopy');
            $data['private_set'] = $this->db_session->userdata('private');            
            $data['snipurl_set'] = $this->db_session->userdata('snipurl');
            $data['remember_set'] = $this->db_session->userdata('remember');
            $data['paste_set'] = $paste;
            $data['title_set'] = $title;
            $data['reply'] = $reply;

            if($lang != 'php' or ($lang == 'php' and $this->db_session->userdata('lang') == false))
            {
                $data['lang_set'] = $lang;
            }
            elseif($this->db_session->userdata('lang'))
            {
                $data['lang_set'] = $this->db_session->userdata('lang');
            }
        }
        else
        {
            $data['name_set'] = $this->input->post('name');
            $data['expire_set'] = $this->input->post('expire');
            $data['acopy_set'] = $this->input->post('acopy');
            $data['private_set'] = $this->input->post('private');            
            $data['snipurl_set'] = $this->input->post('snipurl');
            $data['remember_set'] = $this->input->post('remember');
            $data['paste_set'] = $this->input->post('paste');
            $data['title_set'] = $this->input->post('title');
            $data['reply'] = $this->input->post('reply');
            $data['lang_set'] = $this->input->post('lang');
        }
        return $data;
    }

    function index()
    {
        if(!isset($_POST['submit']))
        {
            $data = $this->_form_prep();
            $this->load->view('home', $data);
        }
        else
        {
            $this->load->model('pastes');
            $this->load->library('validation');
        
            $rules['code'] = 'required';
            $rules['lang'] = 'min_length[1]|required|callback__valid_lang';

            $fields['code'] = 'Main Paste';
            $fields['lang'] = 'Language';
            
            $this->validation->set_rules($rules);
            $this->validation->set_fields($fields);
            $this->validation->set_message('min_length', 'The %s field can not be empty');
            $this->validation->set_error_delimiters('<div class="message error"><div class="container">', '</div></div>');
            
            if ($this->validation->run() == FALSE)
            {
                $data = $this->_form_prep();
                $this->load->view('home', $data);
            }
            else
            {
                if(isset($_POST['acopy']) and $_POST['acopy'] > 0)
                {
                    $this->db_session->set_flashdata('acopy', 'true');
                }
                
                if($this->input->post('remember') and $this->input->post('reply') == false )
                {
                    $user_data = array(
                            'name' => $this->input->post('name'),
                            'lang' => $this->input->post('lang'),
                            'expire' => $this->input->post('expire'),
                            'acopy' => $this->input->post('acopy'),
                            'snipurl' => $this->input->post('snipurl'),
                            'private' => $this->input->post('private'),
                            'remember' => $this->input->post('remember')
                        );
                    $this->db_session->set_userdata($user_data);
                }
                
                if($this->input->post('remember') == false and $this->db_session->userdata("remember") == 1)
                {
                    $user_data = array(
                            'name' => '',
                            'lang' => 'php',
                            'expire' => '0',
                            'acopy' => '0',
                            'snipurl' => '0',
                            'private' => '0',
                            'remember' => '0'
                        );
                    $this->db_session->unset_userdata($user_data);
                }
                
                redirect($this->pastes->createPaste());
            }
        }
    }
    
    function lists()
    {
        $this->load->model('pastes');
        $data = $this->pastes->getLists();
        $this->load->view('list', $data);
    }


Messages In This Thread
CI and Phil Strugeons REST API - by El Forum - 11-15-2009, 04:48 PM
CI and Phil Strugeons REST API - by El Forum - 11-16-2009, 04:53 AM
CI and Phil Strugeons REST API - by El Forum - 11-16-2009, 06:51 AM
CI and Phil Strugeons REST API - by El Forum - 11-16-2009, 11:39 AM
CI and Phil Strugeons REST API - by El Forum - 11-17-2009, 08:44 AM
CI and Phil Strugeons REST API - by El Forum - 11-17-2009, 01:49 PM
CI and Phil Strugeons REST API - by El Forum - 11-17-2009, 05:23 PM
CI and Phil Strugeons REST API - by El Forum - 11-18-2009, 08:58 AM
CI and Phil Strugeons REST API - by El Forum - 11-18-2009, 09:24 AM
CI and Phil Strugeons REST API - by El Forum - 11-18-2009, 10:35 AM
CI and Phil Strugeons REST API - by El Forum - 11-18-2009, 10:50 AM
CI and Phil Strugeons REST API - by El Forum - 11-18-2009, 12:09 PM
CI and Phil Strugeons REST API - by El Forum - 02-04-2010, 03:28 AM
CI and Phil Strugeons REST API - by El Forum - 02-04-2010, 04:06 AM
CI and Phil Strugeons REST API - by El Forum - 02-04-2010, 04:13 AM
CI and Phil Strugeons REST API - by El Forum - 02-04-2010, 04:23 AM
CI and Phil Strugeons REST API - by El Forum - 02-05-2010, 08:28 AM
CI and Phil Strugeons REST API - by El Forum - 02-19-2010, 05:15 AM
CI and Phil Strugeons REST API - by El Forum - 02-25-2010, 04:17 AM
CI and Phil Strugeons REST API - by El Forum - 07-21-2010, 07:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB