• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get 'id' from URL?

#1
[eluser]tahakirmani[/eluser]
Hi

I am trying to get 'id' from URL in order to delete that specific selected product. I have used $this->uri->segment(3) but its not getting any value from URL. Although i can see the 'product_id' in my URL.
If i used $this->url->segment(2) it gives me the second value form URL, but i am unable to get product Id.
Following is my code. Kindly guide me.

Code:
//VIEW
        echo "<a href='delete_controller?product_id=$product_id'>";
        echo $name;
        echo "</a>";

The following URL is generating when i click on $name.
Code:
http://localhost/designs2/index.php/products_controller/delete_controller?product_id=70




Code:
public function delete_controller()
        {
            echo $product_id =$this->uri->segment(3);          
            echo "Taha";
            $this->load->view('delete_confirmation');
        }

Thanks,
Taha

#2
[eluser]noideawhattotypehere[/eluser]
Code:
class Example extends CI_Controller {

    public function example_deletion($id) {
        //deletion code... and whatever you want
    }

}

Then you access it like:
yourdomain.com/example/example_deletion/$id,
if you had more arguments in your method, it would look like
yourdomain.com/controller/method/$arg1/$arg2/... etc.,
but if you wanna keep it with GET approach you access it via
Code:
$this->input->get('name_of_your_get_value');

#3
[eluser]InsiteFX[/eluser]
or use CI uri_segment method

#4
[eluser]tahakirmani[/eluser]
Thank You So Much! You Guys are Great ! Smile

#5
[eluser]Scared[/eluser]
[quote author="noideawhattotypehere" date="1389946186"]
Code:
class Example extends CI_Controller {

    public function example_deletion($id) {
        //deletion code... and whatever you want
    }

}

Then you access it like:
yourdomain.com/example/example_deletion/$id,
if you had more arguments in your method, it would look like
yourdomain.com/controller/method/$arg1/$arg2/... etc.,
but if you wanna keep it with GET approach you access it via
Code:
$this->input->get('name_of_your_get_value');
[/quote]

Sorry, newbie question, am I right in thinking you have to setup the routing accordingly for this to work? What would the routing rule look like? Would it be this?:

Code:
$route['example/example_deletion/(:any)'] = 'example/example_deletion/$1';

#6
[eluser]noideawhattotypehere[/eluser]
[quote author="Scared" date="1390226886"][quote author="noideawhattotypehere" date="1389946186"]
Code:
class Example extends CI_Controller {

    public function example_deletion($id) {
        //deletion code... and whatever you want
    }

}

Then you access it like:
yourdomain.com/example/example_deletion/$id,
if you had more arguments in your method, it would look like
yourdomain.com/controller/method/$arg1/$arg2/... etc.,
but if you wanna keep it with GET approach you access it via
Code:
$this->input->get('name_of_your_get_value');
[/quote]

Sorry, newbie question, am I right in thinking you have to setup the routing accordingly for this to work? What would the routing rule look like? Would it be this?:

Code:
$route['example/example_deletion/(:any)'] = 'example/example_deletion/$1';
[/quote]

You could setup other route if you want in routes.php, but by default codeigniter urls looks like this:
base_url/controller/method/param1/param2/.../
this means that your example doesnt need any entries in routes.php

#7
[eluser]Scared[/eluser]
Thank you!

#8
[eluser]InsiteFX[/eluser]
Users Guide URI Class


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.