Welcome Guest, Not a member yet? Register   Sign In
passing parameters to controller, please help!
#1

[eluser]Crawley[/eluser]
hello, why can't I pass parameters to my controllers via uri?
Code:
<?php
class Dvd extends Controller {

...

    function dvdinfo($id)
    {
        echo $id;
        
    }

}
?>

now when i load the following uri:
Code:
http://.../index.php/dvd/dvdinfo/123

i get following error:
Quote:A PHP Error was encountered

Severity: Warning

Message: Missing argument 1 for Dvd::dvdinfo(), called in .../dvd/system/codeigniter/CodeIgniter.php on line 207 and defined

Filename: controllers/dvd.php

Line Number: 17
#2

[eluser]Dan Bowling[/eluser]
Can you paste in the entire controller?
#3

[eluser]TheFuzzy0ne[/eluser]
That's quite strange. First of all, I recommend that you set your controller method to assume that one hasn't been provided:

Code:
function dvdinfo($id=NULL)
{
    if ( ! $id) { show_error('No ID specified'); }
}

Then you can code your method to fail gracefully if an ID is not provided.

What does:

Code:
echo $this->uri->uri_string();

give you when called from within your method?
#4

[eluser]Crawley[/eluser]
[quote author="TheFuzzy0ne" date="1241559665"]

What does:

Code:
echo $this->uri->uri_string();

give you when called from within your method?[/quote]

It gives following:
Quote:/dvd/dvdinfo/123
#5

[eluser]TheFuzzy0ne[/eluser]
...And what happens when you use the controller method I posted? Does it give you an error?

I'm really at a loss here. The only thing I can think of, might be to change uri_protocol in the config.php file. REQUEST_URI or QUERY_STRING might help.
#6

[eluser]Crawley[/eluser]
[quote author="TheFuzzy0ne" date="1241562953"]...And what happens when you use the controller method I posted? Does it give you an error?
[/quote]

Yup, that works:
Quote:An Error Was Encountered

No ID specified
#7

[eluser]Crawley[/eluser]
[quote author="TheFuzzy0ne" date="1241562953"]I'm really at a loss here. The only thing I can think of, might be to change uri_protocol in the config.php file. REQUEST_URI or QUERY_STRING might help.[/quote]

I already tried all 5 of them.
#8

[eluser]TheFuzzy0ne[/eluser]
Do you have any routes set up? Also, what does your htaccess file look like?
#9

[eluser]Crawley[/eluser]
[quote author="TheFuzzy0ne" date="1241563767"]Do you have any routes set up? [/quote]
my config/routes.php:
Code:
$route['default_controller'] = "application";

$route['scaffolding_trigger'] = "";



Quote:Also, what does your htaccess file look like?
Code:
RewriteEngine on
RewriteRule ^$ /index.php [L]
RewriteCond $1 !^(index\.php|img|css|js|video_files|robots\.txt|favicon\.ico)
RewriteRule ^(.*)$ /index.php/$1 [L]
I don't know much about this file, but the result seems to be the same even if I delete it...
#10

[eluser]TheFuzzy0ne[/eluser]
Please try changing the last line to this:

Code:
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]




Theme © iAndrew 2016 - Forum software by © MyBB