grocery crud getState for uploads while inserting and updating

I am stuck with codeigniter, Grocery CRUD code, here is portion of the code that keeps troubling me:

   if($state == 'add'){//add state
       $upload_path = '/files/dir1/';
   }
   else if($state == 'edit'){//edit state
       $upload_path = '/files/dir2/';
   }
   $this->crud->set_field_upload('image_url',  $upload_path);

Here I am trying to swap the $upload_path according to the current state. But this one is giving me the trouble. Everything is working fine except the file is getting uploaded to default *$upload_dir* which is set in the Grocery_CRUD.php. After spending a lot of time i found that the $state value is 'upload_file' for all the file uploads(regardless of the add or edit operations). i badly need to differentiate between the insert or update state. I tried to sort it out using

if(strpos($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], '/add')){
             $upload_path = '/files/dir1/';
}
else if(strpos($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], '/edit')){
             $upload_path = '/files/dir2/';
}

and even tried to use:

strpos(current_url, '/add')
strpos(current_url, '/edit')

Everything failed as the Grocery_CRUD.php library file is not able to tell me anything other than 'upload_file' as the current state.

Kindly help me! Thanks in advance.

Answers


I have figured it out myself, the trick is to create a session variable and check it with the previous state before the upload was called.

for that create a variable in session, check it's value against add or edit and assign the path accordingly.

$upload_path = '';
if( $state == 'add' || $state == 'edit'){//only create the session if $state is add or edit
    $this->session->set_userdata('statevar',$state);
}
if($this->session->userdata('statevar') == 'add'){//add state
    $upload_path = 'files/dir1/';
}
else if($this->session->userdata('statevar') == 'edit'){//edit state
    $upload_path = 'files/dir2/';
}
$this->crud->set_field_upload('imgurl', $upload_path);

Need Your Help

Android OpenGL ES 2 Texture Quadrants Rotated

android opengl-es-2.0

I'm trying to load a simple 2D texture onto a square and display it in the back of my GLSurfaceView. I've copied over and fixed the code from Draw a 2D Image using OpenGL ES 2.0, but when I install...

How to set bing traffic maps to show traffic by default?

html bing-maps traffic

I'm trying to code up a bing traffic map for my site and everything is fine except for two annoyances that I must be rid of: