Welcome Guest, Not a member yet? Register   Sign In
accessing data via model functions
#1

[eluser]Unknown[/eluser]
Hi, just starting out with PHP / CodeIgniter and was wondering if someone can give me a hand with the following?

I have two functions, one that a user uploads a .csv file to, and then another function that will parse the file once it's been uploaded. I can successfully get back the file path by passing data to the view, but I cannot access this via the other function in the model. Via the view I can use, $upload_data['full_path']; but I don't know how to pass this between the functions. Below is my code as an example, any help would be GREATLY appreciated!
Code:
<?php
class Uploader_model extends Model {

    var $upload_path;

    function Uploader_model(){
    
    parent::Model();
    
    $this->upload_path = realpath(APPPATH . '../csv');
    $this->load->view('newbroadcast');
    
    }
    
    
    function do_upload() {
        
        $config = array(
            'allowed_types' => 'csv',
            'upload_path' => $this->upload_path
        );
    
        $this->load->library('upload', $config);

        $this->upload->do_upload();
        
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('upload_complete',$data);
            $this->parser();
        }
    }
    
    function parser()
    {
    $row = 1;
    $handle = fopen("C:\wamp\www\site\system\csv\Book1.csv", "r");
    echo("<table>");
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
        echo("<tr>\r\n");
        foreach ($data as $index=>$val) {
                echo("\t<td>$val</td>\r\n");
        }
        echo("</tr>\r\n");
    }
    echo("</table>");
    fclose($handle);
    }
}
?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB