Zen
Zen

Reputation: 7385

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?

Upvotes: 0

Views: 2077

Answers (4)

Zen
Zen

Reputation: 7385

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

Everything is fine now. Thanks everyone.

Upvotes: 0

bassneck
bassneck

Reputation: 4043

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"

Upvotes: 1

Vamsi Krishna B
Vamsi Krishna B

Reputation: 11490

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

Upvotes: 0

Shakti Singh
Shakti Singh

Reputation: 86406

You are missing the assignment operator

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

Upvotes: 1

Related Questions