⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

how can I do to hide Id from URL?



palme
  • profile picture
  • Member

Posted 28 February 2012 - 17:12 PM

Hi,
how can I do to hide Id From URL?
I need to create a form where each user can modify our data but can not see the ID parameter in the url

sorry for my english!

[color=#282828][font=helvetica, arial, sans-serif]Best Regards[/font][/color]
[color=#282828][font=helvetica, arial, sans-serif]Ale[/font][/color]

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 28 February 2012 - 22:14 PM

I am sorry but there is not a simple way to do this as grocery CRUD operations are based on the url primary id.

The only simple way to not have the id in URL is to have your form in an iframe. I know that you are looking at something else more secure but there is the only solution I can think for now.

twister88888
  • profile picture
  • Member

Posted 05 July 2012 - 12:21 PM

Something new about this, would be nice to find a solution for security

palme
  • profile picture
  • Member

Posted 19 February 2013 - 18:27 PM

Hi all. I solved my problem:
 
First Step: Create a core system class in application/core/MY_URI.php
<?php
class MY_URI extends CI_URI {

    function __construct()
    {
        parent::__construct();
    }
    
    function set_segment($n,$value)
    {
      $this->segments[$n] = $value;
      return $this;            
    }        
}
 

 

Second Step: The controller 
 
My URI string is /admin/users/profile/
public function profile()
{        
    $user_id = $this->session->userdata('user_id');


    if($this->uri->segment(4) == 'edit'){
        $this->uri->set_segment(5,$user_id);            
    }
                                
    $crud = new grocery_CRUD();
    $crud->set_table('users');
    $crud->edit_fields('email','lastname');        
    $crud->unset_add();
    $crud->unset_back_to_list();
    $crud->unset_list();                    
    try{
        $output = $crud->render();
        $this->_example_output($output);
    } catch(Exception $e) {        
        if($e->getCode() == 14){
            redirect('admin/users/profile/edit');
        }else {
            show_error($e->getMessage());
        }
    }        
}
 

 

The segments may vary according to the url
 
Excuse my english!
I hope you find it useful
Best regards

davidoster
  • profile picture
  • Member

Posted 20 February 2013 - 23:00 PM

Where do you initialize your uri class object?


palme
  • profile picture
  • Member

Posted 21 February 2013 - 13:23 PM

Hi Davidoster!

The class is instantiated by calling the controller automatically.

Look this link:  http://ellislab.com/codeigniter/user-guide/general/core_classes.html