Welcome Guest, Not a member yet? Register   Sign In
Sending variables
#1

[eluser]szulcseban[/eluser]
I want to send a variable $id in that way:
<a href="&lt;?php echo site_url('admin/edit/$id');?&gt;">Edytuj...</a>.

How can I get this variable from 'edit' controller?
#2

[eluser]reset[/eluser]
Hello,

You can do that with the URI library. There's a function ($this->uri->segment(n)), you can do for this url

http://localhost/codeigniter/edit/$id

n = 1 $this->uri->segment(1) --&gt; for controller
n = 2 $this->uri->segment(2)--&gt; for $id


...
#3

[eluser]jcopling[/eluser]
If you have a controller called edit that looks like this:
Code:
class Edit extends Controller{
    
    function Edit(){
        parent::Controller();
    }
}
Then you would also have a function called index as the default function. The easiest way to retrieve the $id variable would be to include it as a parameter of the index function. So it would end up looking like this:
Code:
class Edit extends Controller{
    
    function Edit(){
        parent::Controller();
    }
        function index($id){
        //do something with $id
    }
}
However, if you do it this way it is important to note that you would then call this as /admin/edit/index/$id instead of /admin/edit/$id




Theme © iAndrew 2016 - Forum software by © MyBB