Welcome Guest, Not a member yet? Register   Sign In
Uri Routing
#1

[eluser]Dizza[/eluser]
Hi,

Oke, im stuck (again, lol). I want to pass an id to a next page (so it can be loaded there with all the info).

Im having this

Controller
Code:
function meer()
    {
        redirect('home/#_Meer/');
    }

and the view:

Code:
<div class="iLayer" id="waVoorgerecht" title="Voorgerechten">
    

    
        &lt;?php
$query = $this->db->get('voorgerecht');

foreach ($query->result() as $row)
{

?&gt;
<div class="menukaart">
    <div class="img">      &lt;?php $link = base_url().'uploads/' . $row->afbeelding;?&gt;
         <a href="&lt;?php echo $link; ?&gt;">&lt;?php echo img('uploads/thumbs/' . $row->afbeelding );?&gt;</a></div>
    <div class="tekst"><a href="#_Voorgerecht">
   <b> &lt;?php  echo $row->naam;  ?&gt;</b><br />
    &lt;?php  echo $row->beschrijving;  ?&gt;<br />
    <b>prijs</b> &lt;?php  echo $row->prijs;  ?&gt;
&lt;?php echo anchor('home/meer/' . $row->id); ?&gt;

     </div>  
</div>
   &lt;?php    
}
?&gt;
    
  
    
    </div>

the part where i use &lt;?php echo anchor('home/meer/' . $row->id); ?&gt; in the view has to pass the id to the controller, but it wont work, can someone help me please? Im stuck with this thing for almost 2 days Tongue
#2

[eluser]Cristian Gilè[/eluser]
Code:
function meer()
{
    $id = $this->uri->segment(3,1); //The second parameter permits you to set a default value if the segment is missing.  
    redirect('path/to/the/controller/method/'.$id);
}


Cristian Gilè
#3

[eluser]Dizza[/eluser]
Wow, thanks! That worked out my problem!
Do you maybe know how i can get that id to work? I need to echo it, if its possible!

Thanks! Big Grin

Edit: Hmm i found out to echo the uri, but it wont echo the 3 one. Only the first(home) if i state that it should echo

Code:
&lt;?php $id = $this->uri->segment(3);?&gt;
    <h3>&lt;?php echo $id; ?&gt;</h3>

i dont see anything Sad

Anyone knows where it goes wrong? Could it be that i am stating the wrong uripath?
#4

[eluser]Cristian Gilè[/eluser]
Could you be more clear?

If your full URL is:

Code:
http://example.com/index.php/news/local/metro/crime_is_up

news is the segment 1
local is the segment 2
metro is the segment 3
crime_is_up is the segment 4

so, if you echo

Code:
$this->uri->segemnt(2);

it will ouptput local

if you echo

Code:
$this->uri->segemnt(4);

it will output crime_is_up...and so on.

If your full URL is:

Code:
http://example.com/index.php/news/local

and you echo

Code:
$this->uri->segemnt(3);

the third segment is missing and the function returns FALSE.

If you echo

Code:
$this->uri->segemnt(3,0);

because the third segment is missing, it will output 0.


Please, read the user guide.


Cristian Gilè
#5

[eluser]Dizza[/eluser]
Im sorry, the thing is that if i echo:

Code:
&lt;?php echo $this->uri->segemnt(1,0); ?&gt;
the output is:
Code:
home

It grabs the first segment, which is home:
http://jtbfolio.nl/cms/index.php/home/#_Meer/129

if i echo
Code:
&lt;?php echo $this->uri->segemnt(2,0); ?&gt;
the output is:
But it should be #_Meer
http://jtbfolio.nl/cms/index.php/home/#_Meer/129

If i echo
Code:
&lt;?php echo $this->uri->segemnt(3,0); ?&gt;
the output is:
But it should be 129

http://jtbfolio.nl/cms/index.php/home/#_Meer/129

Could it be because i added the #_Meer part in my controller?
Code:
redirect('home/#_Meer/'.$id);
that it wont display the 2nd and 3rd segment?


Hope i explained it better this time Smile
btw, you can also see what i mean @ http://jtbfolio.nl/cms/index.php/home/#_Home > voorgerechten and then click the link under the price.
#6

[eluser]Dizza[/eluser]
hmm i keep getting the same problem as above, i almost tried everything, anyone got a clue?
#7

[eluser]Cristian Gilè[/eluser]
Quote:A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*.

Change the name of the #_Meer function


Cristian Gilè




Theme © iAndrew 2016 - Forum software by © MyBB