URI segment not working correctly |
[eluser]Darker[/eluser]
It is My_photos controller which is reached when going to base_url/my-photos. But when i go to base_url/my-photos/delete/1/ the $photo_id returns no value. Why ? Code: <?php Thanks.
[eluser]CroNiX[/eluser]
Because you didn't define $photo_id in your delete() method, which is the method you are accessing. It doesn't know anything about $photo_id in your index() method.
[eluser]Darker[/eluser]
[quote author="CroNiX" date="1351466367"]Because you didn't define $photo_id in your delete() method, which is the method you are accessing. It doesn't know anything about $photo_id in your index() method.[/quote] What about an example ? Because everything what i'm trying to do is not working.
[eluser]CroNiX[/eluser]
Code: public function delete(){
[eluser]CroNiX[/eluser]
Also, you should avoid using my_ to prefix things unless you are extending a CI Core Class/Library/Helper, which your controller isn't doing. You can get yourself in trouble if you don't understand how it works and you do this elsewhere.
[eluser]Darker[/eluser]
[quote author="CroNiX" date="1351469330"]Also, you should avoid using my_ to prefix things unless you are extending a CI Core Class/Library/Helper, which your controller isn't doing. You can get yourself in trouble if you don't understand how it works and you do this elsewhere.[/quote] Okay, i renamed it and tried to do anything i can, but... I realized that delete() function isn't even called. Now i tried to disable any view in delete() but nothing. Help me please ![]() Code: <?php Thanks.
[eluser]mr lister[/eluser]
As CroNiX says, you need to obtain the $photo_id from the 3rd segment of the URL, you have it being obtained from your 2nd segment, which would give you: Code: $photo_id = "delete" Also, and correct me if I am wrong, but you could also do it this way, (as an option): Code: public function delete( $photo_id = NULL ) { This way, if there is no 3rd segment, $photo_id = NULL, else, if there is a 3rd segment, $photo_id will equal that segment value. domain.com/photos/delete will have $photo_id equaling NULL, whereas; domain.com/photos/delete/4 will have $photo_id equaling a value of 4 Does this make sense? http://ellislab.com/codeigniter/user-gui...passinguri explains more.
[eluser]Darker[/eluser]
[quote author="mr lister" date="1351530080"]As CroNiX says, you need to obtain the $photo_id from the 3rd segment of the URL, you have it being obtained from your 2nd segment, which would give you: Code: $photo_id = "delete" Also, and correct me if I am wrong, but you could also do it this way, (as an option): Code: public function delete( $photo_id = NULL ) { This way, if there is no 3rd segment, $photo_id = NULL, else, if there is a 3rd segment, $photo_id will equal that segment value. domain.com/photos/delete will have $photo_id equaling NULL, whereas; domain.com/photos/delete/4 will have $photo_id equaling a value of 4 Does this make sense? http://ellislab.com/codeigniter/user-gui...passinguri explains more. [/quote] Thanks for your answer, but delete() function doesn't work when you go to /photos/delete. Dunno why, but it still uses index().
|
Welcome Guest, Not a member yet? Register Sign In |