CodeIgniter Forums
Get URI segment returns nothing.... [RESOLVED] - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Get URI segment returns nothing.... [RESOLVED] (/showthread.php?tid=10410)

Pages: 1 2


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

[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


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

[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
}



Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

[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-guide/general/controllers.html


Iain


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

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


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

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


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

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


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

[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..


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

[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-guide/general/controllers.html


Iain[/quote]
Code:
Missing argument $n

The URI is completely blank


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

[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


Get URI segment returns nothing.... [RESOLVED] - El Forum - 07-30-2008

[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)