Welcome Guest, Not a member yet? Register   Sign In
How to add Images to my CRUD methods?
#1

[eluser]design_shuffle[/eluser]
Hi,

I am working on my second CI application. I have created some simple CRUD methods in my controller. My client has requested that each record includes an image. I have searched the forums and other resources for help but haven't had much luck.

I have managed to upload files into a directory using the File Uploading Class, my problem though is how to associate the uploaded file/s with the relevant record.

Here are the relevant parts of my MVC.., any help/point in the right direction would be appreciated.

View - admin/locationEdit.php
----------------------------------
Code:
<form method="post" action="<?php echo $action; ?>">
        <div class="data">
        <table>
            <tr>
                <td width="30%">ID</td>
                <td>&lt;input type="text" name="id" disabled="disable" class="text" value="&lt;?php echo $this-&gt;validation->id; ?&gt;"/></td>
                &lt;input type="hidden" name="id" value="&lt;?php echo $this-&gt;validation->id; ?&gt;"/>
            </tr>
            <tr>
                <td valign="top">Name<span style="color:red;">*</span></td>
                <td>&lt;input type="text" name="name" class="text" value="&lt;?php echo $this-&gt;validation->name; ?&gt;"/>
                &lt;?php echo $this->validation->name_error; ?&gt;</td>
            </tr>
            <tr>
                <td valign="top">Address<span style="color:red;">*</span></td>
                <td>&lt;input type="text" name="address" class="text" value="&lt;?php echo $this-&gt;validation->address; ?&gt;"/>
                    &lt;?php echo $this->validation->address_error; ?&gt;</td>
            </tr>
            
            <tr>
                <td>&nbsp;</td>
                <td>&lt;input type="submit" value="Save"/&gt;&lt;/td>
            </tr>
        </table>
        </div>
        &lt;/form&gt;
Controller - location.php
-----------------------------

Code:
function add(){
        // set validation properties
        $this->_set_fields();
        
        // set common properties
        $data['title'] = 'Add new location';
        $data['message'] = '';
        $data['action'] = site_url('admin/location/addLocation');
        $data['link_back'] = anchor('admin/location/index/','Back to list of locations',array('class'=>'back'));
    

        
            // Write to $title
      $this->template->write('title', 'Admin - Add New Location!');
    // Write to $sidebar
      $this->template->write_view('content', 'admin/locationEdit', $data);
      // Render the template
      $this->template->render();
      
    }
    
    function addLocation(){
        // set common properties
        $data['title'] = 'Add new location';
        $data['action'] = site_url('admin/location/addLocation');
        $data['link_back'] = anchor('admin/location/index/','Back to list of locations',array('class'=>'back'));
        
        // set validation properties
        $this->_set_fields();
        $this->_set_rules();
        
        // run validation
        if ($this->validation->run() == FALSE){
            $data['message'] = '';
        }else{
            // save data
            $location = array('name' => $this->input->post('name'),
                            'address' => $this->input->post('address'));
            $id = $this->locationModel->save($location);
            
            // set form input name="id"
            $this->validation->id = $id;
            
            // set user message
            $data['message'] = '<div class="success">add new location success</div>';
        }
        
            // Write to $title
      $this->template->write('title', 'Admin - Add New Location!');
    // Write to $sidebar
      $this->template->write_view('content', 'admin/locationEdit', $data);
      // Render the template
      $this->template->render();
    }


Messages In This Thread
How to add Images to my CRUD methods? - by El Forum - 06-22-2010, 08:13 AM
How to add Images to my CRUD methods? - by El Forum - 06-27-2010, 09:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB