CodeIgniter Forums

Full Version: Get URI segment returns nothing.... [RESOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]Frychiko[/eluser]
Hi,

I started using CI yesterday to convert over an online price comparison shop, anyway this problem stopped me dead in my tracks.

I have an URL:

Code:
http://localhost/ci/manufacturer/edit/10

* manufacturer is my controller
* edit is a function within the manufacturer controller

I want to get a URI segment within the edit function with:

Code:
$this->uri->segment(n)

ie.

Code:
function edit() {
   echo "segment:".$this->uri->segment(3);
}

I tried 'n' with values from 0-3 but nothing is returned.

Perhaps I'm missing a configuration setting or something?

cheers,
Frychiko

El Forum

[eluser]sophistry[/eluser]
welcome to CI.

these may seem obvious but, did you...
confirm that the edit() method is being called?
strip routing from routes.php that may be confusing the matter?
check any other parts of the uri with other functions? eg.
Code:
$this->uri->uri_string()
test a different way ie. reorganize the method so you assign parameters on method call? eg.
Code:
function edit($seg1, $seg2)
{
//do something
}

El Forum

[eluser]iainco[/eluser]
Code:
http://localhost/ci/manufacturer/edit/10

Code:
function edit($n) {
   echo $n;
}

I thought it worked so that the above function would output 10.

http://localhost/ci/manufacturer/edit/10 = Manufacturer.edit(10)

See "Passing URI Segments to your Functions" at http://ellislab.com/codeigniter/user-gui...llers.html


Iain

El Forum

[eluser]Hannes Nevalainen[/eluser]
I hope you have loaded the url-helper ($this->load->helper('url'))..

El Forum

[eluser]iainco[/eluser]
It's not the URL helper, it's the URI class/library which is loaded automatically.

El Forum

[eluser]Hannes Nevalainen[/eluser]
Oh, my bad. Think i might lack som sleep =S

El Forum

[eluser]Frychiko[/eluser]
Thanks for the welcome!

edit() is being called since there is the following output:

Code:
segment:

I checked the routing file and cleared any default controllers.

$this->uri_string() returns nothing
I've tested things in index() also but there's nothing..
Code:
function edit($seg1, $seg2)
{
  echo $seg1;
  echo $seg2;
}

doesn't work, missing argument for $seg1 and $seg2

I'm thinking it's an apache/php setting or something..

El Forum

[eluser]Frychiko[/eluser]
[quote author="Iainco" date="1217454560"]
Code:
http://localhost/ci/manufacturer/edit/10

Code:
function edit($n) {
   echo $n;
}

I thought it worked so that the above function would output 10.

http://localhost/ci/manufacturer/edit/10 = Manufacturer.edit(10)

See "Passing URI Segments to your Functions" at http://ellislab.com/codeigniter/user-gui...llers.html


Iain[/quote]
Code:
Missing argument $n

The URI is completely blank

El Forum

[eluser]iainco[/eluser]
Do you have an .htaccess file for mod_rewrite? Just noticed you have no index.php in your URL.

http://localhost/ci/index.php/manufacturer/edit/10

Controller is manufacturer with function edit and then passing 10 as the argument to that function, no?

The segment numbers in your case here are:

1. manufacturer
2. edit
3. 10

If it's not the index.php missing then I can only guess you've got a mistake with one of the settings in your main index.php for pointing to your system and application folders.

Sorry if I'm not much help!

Iain

El Forum

[eluser]Frychiko[/eluser]
Yep, I have a .htaccess file in their to remove the index.php, found the tutorial in the wiki section.

I guess I will try a fresh install of ci when I get back from work today. (well it's already a fresh install but er.. well)
Pages: 1 2