Welcome Guest, Not a member yet? Register   Sign In
Values in URL, but segments are blank. ?

Apparently we found something, ....

You have to use standard single or double quotes, don't use copied stuff

[eluser]gordon Stewart[/eluser]
Didn't copy..

I used double quotes (on all lines - before the equal sign..)

Didn't work...

Changed to single quotes - same as before (no segment values)...

I didn't touch the double quotes after each equal sign......

Its got to be something in the CI programme / files themselves... ?

Search the forum for that, ther're many threads for that

a quick way is to program your news controller as:

//Inside news controller

function index()
//... some code goes here

function item($item = 0)
// ... default for $item is 0
// ... some code goes here

in this way, when you go to: http://domain.com/news/item/1
it will get item 1. You may leave it blank, i.e. http://domain.com/news/item, but you should have a code which handles this.

Good luck

[eluser]gordon Stewart[/eluser]
It does help if values are getting from the URL into the script - I can handle anything Smile

The problem is, CI doesn't know URL's are being given...

No matter what I do in the URL - *all* of the following code output are blank _ no results ...

The phpinfo - _SERVER["REQUEST_URI"] has the values I want - But whats the point in using CI if i'm going to parse the URL anyway ??

function item($cat=0)
echo "CAT $cat<BR>\n";

$config['uri_segment'] = 4;


        $segs = $this->uri->segment_array();
        foreach ($segs as $segment)
            echo "Segment Value - " .$segment;
            echo '<br />';

$total = $this->uri->total_segments();

echo "TOTAL ='$total'<BR>\n";

$segments = $this->uri->segment_array(); // gives the segments

$rsegments = $this->uri->rsegment_array(); // gives the segments after routing

// printing nicely to screen :
echo '<pre>SEGMENTS
' .print_r($segments, true) .'</pre>';

// printing nicely to screen :
echo '<pre>RSEGMENTS
' .print_r($rsegments, true) .'</pre>';

            if ($this->uri->segment(2) === FALSE)
                $item = 0;
                $item = $this->uri->segment(1);
            echo "ITEM1 = '$item' X<BR>\n";
                $item = $this->uri->segment(2);
            echo "ITEM2 = '$item' X<BR>\n";
                $item = $this->uri->segment(3);
            echo "ITEM3 = '$item' X<BR>\n";
                $item = $this->uri->segment(4);
            echo "ITEM4 = '$item' X<BR>\n";

                $item = $this->uri->segment(1);
            echo "ITEMa1 = '$item' X<BR>\n";
                $item = $this->uri->segment(2);
            echo "ITEMa2 = '$item' X<BR>\n";
                $item = $this->uri->segment(3);
            echo "ITEMa3 = '$item' X<BR>\n";
                $item = $this->uri->segment(4);
            echo "ITEMa4 = '$item' X<BR>\n";

            echo "ITEM = '$item' X<BR>\n";

If the segments aren't getting to CI, it doesn't matter which "uri" function you try. None of them will have the information.
CI gets the segment information from the server variables. That's AFTER the url is rewritten, first by any .htaccess rules and then inside CI by the routes.

You need to understand how routes work exactly. They are regular expressions.
If you use this rule:
$route['news/(:any)'] = 'news/item/$1';
it will have these results:
news -> news
news/ ->news/item/
news/item -> news/item/item
news/2 -> news/item/2
news/item/2 ->news/item/item/2
news/home -> news/item/home

A rule like
$route['news/(:any)'] = 'news/item/$2';
will never work because $2 references the SECOND pattern in brackets and there is only one.. so that will never give a result.

To exclude route problems, I would suggest removing this route and first trying by calling the complete url. That would be www.example.com/news/item/1.
This should always work.

If you don't get any segments, you should check config/config.php and try a different method in $config['uri_protocol']. There CAN be differences between servers in how they supply their server variables to PHP. That's what this switch is for.

Finally, on getting a completely blank screen: I have had this happen and it usually meant some kind of unrecoverable PHP error. If that happens inside an output buffer (CI's output is buffered) you could end up with nothing. Check the PHP log, the error should be in there.

[eluser]gordon Stewart[/eluser]
$route['default_controller'] = "root";
$route['scaffolding_trigger'] = "";

$route['safety']    = "root/safety";
$route['about']        = "root/about";
$route['goto']        = "root/goto";

// $route['maps/(:any)'] = "maps/model_maps/$1";
$route['maps/(:any)'] = "maps";

$route['news/(:any)'] = "news/item/$1";
// $route['news/(:any)'] = "news/item/$1";

news/1 - same result... - blank results whe using $1

took out the "news" route values - uploaded & now a 404 error - page not found..

its not reaching news.php

anyway, i've given up - if the system admin wants me to use CI - its his problem...

After taking out the 'news' routes, what address did you request? You should use /news/item/1 then.
Not /news/1 because there is no function called '1' in the news controller.

[eluser]gordon Stewart[/eluser]

activate the script - but no values

edit - thats with the route /news/ taken out

Did you change the uri protocol like I mentioned before?
Check out this post from someone with a similar setup to yours: http://www.shinstudio.com/blog/backend-t...tp-server/

Theme © iAndrew 2016 - Forum software by © MyBB