简体   繁体   中英

CodeIgniter URI segments captured as variables?

well, i have a function within a controller called test, and i can access it by going to http://localhost/nwk/control/test

this is my function. I want to use the data given in the next segment from the "test" as a php variable.

so if i put

function test() { $var = $this->uri->segment(3); echo $var; }

according to the user guide if I enter control/test/data, my variable should be equal to 'data'?

doesn't seem to be working.

Am I missing something here?

您缺少赋值运算符

function test() { $var = $this->uri->segment(3); echo $var; }

You could simply make like this:

function test($var, $another_var)
{
    echo $var.' '.$another_var;
}

And opening http://localhost/nwk/control/test/it/works would echo "it works"

$config['name'] = $this->uri->segment(3, 0);
echo $name;

For some reason me autoloading the URI library made this whole functionality not work.

Everything is fine now. Thanks everyone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM