Welcome Guest, Not a member yet? Register   Sign In
passing data from ijndex function to upload_do()
#1

[eluser]wizzer[/eluser]
Greetings,


I am using a segment to pass a variable to the index() function of a controller. My problem is that I also need to have it available to my upload_do() function without it running first. How would I do this?
#2

[eluser]pistolPete[/eluser]
Please post your controller code.
#3

[eluser]wizzer[/eluser]
Code:
<?php
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);
class EditDocument extends Controller {

    function EditDocument()
    {
        parent::Controller();    
        // Only administrators should be able to access this controller
        $this->authorization_groups = array('user'=>TRUE);
    }
    
    function index()
    {

        $this->load->model('user');
        $this->load->model('document');
        $this->load->model('documenttype_model');
        $data['documenttypes'] = $this->documenttype_model->_getAllDocumentType(5,5);
        $data['stats'] = $this->user->_getStats();
        $data['error'] = array('error'=>'');
        $data['sections'] = $this->user->_getSections();
        
        $documentID = $this->uri->segment(4, 0);
        
        $data['doc'] = $this->document->_getThisDocument($documentID);
    
        $this->load->view('editdocument_view',$data);
    }
    //upload a document
    function do_upload()
    {

        $this->load->model('user');
        $this->load->model('document');
        $data['sections'] = $this->user->_getSections();
        $data['stats'] = $this->user->_getStats();
        $data['error'] = array('error'=>'');
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'txt|doc|gif|jpg|png|pdf';
        $config['max_size']    = '1024'; //1 meg
        $config['max_width']  = '0';
        $config['max_height']  = '0';
        $this->load->library('upload', $config);
        
        // SET VALIDATION RULES
        $this->form_validation->set_rules('section', 'section', 'required');
        $this->form_validation->set_rules('lst_category', 'category', 'required');
        $this->form_validation->set_rules('typeofdoc', 'document type', 'required');
        $this->form_validation->set_rules('accesslevel', 'access level', 'required');
        $this->form_validation->set_rules('documentname', 'document name', 'required');
        
        $this->form_validation->set_rules('ownerfname', 'owners first name', 'required');
        $this->form_validation->set_rules('ownersname', 'owners surname', 'required');
        $this->form_validation->set_rules('owneremailaddress', 'owners email address', 'required');
        $this->form_validation->set_rules('company', 'company', 'required');
        
        $this->form_validation->set_rules('division', 'division', 'required');
        $this->form_validation->set_rules('project', 'project', 'required');
        $this->form_validation->set_rules('location', 'location', 'required');
        $this->form_validation->set_rules('startvalidity', 'start date validity', 'required');

        $this->form_validation->set_rules('endvalidity', 'end date validity', 'required');

        //get form vars
        $section = $this->input->post('section');
        $category = $this->input->post('lst_category');
        $typeofdoc = $this->input->post('typeofdoc');
        $accesslevel = $this->input->post('accesslevel');
        
        $documentname = $this->input->post('documentname');
        $ownerfname = $this->input->post('ownerfname');
        $ownersname = $this->input->post('ownersname');
        $owneremailaddress = $this->input->post('owneremailaddress');
        
        $company = $this->input->post('company');
        $division = $this->input->post('division');
        $project = $this->input->post('project');
        $location = $this->input->post('location');
        
        $startvalidity = $this->input->post('startvalidity');
        $endvalidity = $this->input->post('endvalidity');
        
        $docref = $this->input->post('docref');
        
        $revdate = $this->input->post('revdate');
        $docnotes = $this->input->post('docnotes');
        $userfile = $this->input->post('userfile');
        $UserID = $this->session->userdata('UserID');
/*
        //get this users document cap
        $documentCap = $this->user->_getDocumentCap($UserID);
        
        //get this users document usage thus far
        $usedDocs = $this->user->_getDocumentsUsed($UserID);
        
        // total docs available if any
        $totalDocs = $documentCap - $usedDocs;
        
        if($totalDocs < 1)
        {
            $chkUpload = false;
        }
*/
        if ( ! $this->upload->do_upload() || $this->form_validation->run() == false /*|| @$chkUpload == false*/)
        {
        /*
            if(@$chkUpload == false)
            {
                $data['caperror'] = "Your document limit has been reached";
            }
        */
            //set number of remaning docs if any
            //$this->session->userdata('docsleft') = $totalDocs;
            $data['error'] = array('error'=>$this->upload->display_errors());
            $this->load->view('editdocument_view', $data);
        }    
        else
        {
            $data['upload_data'] = $this->upload->data();    
            $size = $data['upload_data']['file_size'];
            $filename = $data['upload_data']['orig_name'];
            $this->document->_updateDocument($documentID,$section,$category,$typeofdoc,$accesslevel,$documentname,$ownerfname,$ownersname,$owneremailaddress,$company,$division,$project,$location,$startvalidity,$endvalidity,$filename,$size,$docref,$revdate,$docnotes);
            //$this->load->view('managedocument_view', $data);
            redirect('managedocument/index/');
        }
    }    
}                
?&gt;

:-)

I need $documentID from index() to be available to do_upload()

im confused how to do this
#4

[eluser]pistolPete[/eluser]
How about that:

Quote:function do_upload($doc_id)
{
echo $doc_id;
....
}

Access the site using http://example.com/EditDocument/do_upload/123 .
#5

[eluser]wizzer[/eluser]
thanks




Theme © iAndrew 2016 - Forum software by © MyBB