CodeIgniter Forums
Dynamic Menu - getting 404 when trying to navegate. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Dynamic Menu - getting 404 when trying to navegate. (/thread-22108.html)



Dynamic Menu - getting 404 when trying to navegate. - El Forum - 08-29-2009

[eluser]MEM[/eluser]
Newbie trying to build a dynamic menu with CI :


On my view v_header,I'm getting the links with url and category name.:

Code:
<?php
echo "<ul>";
foreach ($listacategorias as $categoria)
{
   echo "<li>";
   echo anchor("c_categoria/$categoria->id_cat",$categoria->nome_cat);
   echo "</li>";
}
echo "</ul>";

This works. Nice.
It will give me something like:
http://site.com/c_categoria/1
http://site.com/c_categoria/2
http://site.com/c_categoria/3

The issue is that, when I click on those links I get a 404 error.

Please help me out:

In my controller c_categoria, I'm having the following:
Code:
function cat($id)
{
    $cat = $this->M_Categoria->getCategoria($id);
                
    $data['titulo'] = "As nossas soluções para ".$cat->nome_cat;
    $data['listacategorias'] = $this->M_Categoria->getCategoriasPrincipais();
        
    $data['categoria'] = $cat;
        
    //o homepage_tpl should get this value:    
    $data['main'] = 'v_categoria';
        
        
    $this->load->vars($data);
    $this->load->view('homepage_tpl');
        
}



My template homepage_tpl, grab the array key main as $main, here:
Code:
<div id="container">
        
&lt;?php $this->load->view('v_header'); ?&gt;
            
&lt;?php $this->load->view($main); ?&gt;
    
&lt;?php $this->load->view('v_footer'); ?&gt;
    
</div>





Can anyone help me out on debugging this, and understand why I'm I getting a 404 ?

Sad
Márcio


Ps- on the controller I have also tried like this:
$cat = $this->M_Categoria->getCategoria($this->uri->segment(3));

No luck. Same 404 as ever.


Dynamic Menu - getting 404 when trying to navegate. - El Forum - 08-29-2009

[eluser]bretticus[/eluser]
UPDATED!!! I got your controller and method backwards. Perhaps you noticed already. Fixed below...

Looks like you're missing the method in your path. Try:

Code:
&lt;?php
echo "<ul>";
foreach ($listacategorias as $categoria)
{
   echo "<li>";
   echo anchor("c_categoria/cat/{$categoria->id_cat}",$categoria->nome_cat);
   echo "</li>";
}
echo "</ul>";



Dynamic Menu - getting 404 when trying to navegate. - El Forum - 08-29-2009

[eluser]MEM[/eluser]
Thanks a lot, I'm so tired... Smile

I will give it a try, but, maybe I will put all this to the index method of my c_categoria and, by doing that, I will avoid yet another URI segment.

I will post back the results...


Regards,
Márcio


Dynamic Menu - getting 404 when trying to navegate. - El Forum - 08-29-2009

[eluser]MEM[/eluser]
Thanks! At least the 404 is gone

.

1)
I was hoping to see the template visuals or some sort of echo on my v_categorias view, but only white appears. ... Confused :~~~ Any imediat clue? (if not, I will look for it tomorrow, np).
And, at least the 404 is gone.


2) I have copy paste the code from cat method, change index() to accept an $id like so index($id) and change the anchor and deleted the /cat/ reference there.
I get a 404.
If I create a function and I update the anchor to accept /cat/, I get no 404. Confused
I don't understand why this doesn't work if I put the code inside the index() method with $id as param ?


3) In your code provided, what should the use of {} means there?



Thanks A LOT,
Kind Regards,
Márcio


Note: I haven't try putting this on my controller constructor yet.
Note: I will come back in a 7 hours, need to sleep.


Dynamic Menu - getting 404 when trying to navegate. - El Forum - 08-31-2009

[eluser]MEM[/eluser]
1) The issue was that I have not uploaded ALL required files to the server.

2) The issue was related with the fact that CI only places as function params segment values after the second segment. By using index, and not explicitly write /index/ on our anchor URL, we will get a 404.

3) I believe the {} is something to do with parsing variables or, in this case, objects. But I believe we can have it without {} as well. Should we use with {} or without curly braces?


Regards,
Márcio