Welcome Guest, Not a member yet? Register   Sign In
Mega Doubt - Categories and SubCategories Dynamic Navegation Menu
#1

[eluser]MEM[/eluser]
I hope to get your help on this:

Preliminary:
a) I'm using template views, or views loading other views as my system. I'm sorry, I just feel more comfortable like this.
b) I'm having one table categories with one "parent_id_cat" column. I don't have two tables.

Request:
The point here is to have, on a page, three category menus:
One: for the main categories. (it will be on top).
A Second: for the sub categories. (it will be on the left side).
The third: for the sub-subcategories (it will be side-by-side with menu 2).
I can put the first and second menus nicely. But when I put the third, it overs my second one, because I’m using the same method for both.

What I have:
On my MODELI have the following:
Code:
function getSubCategorias($id_cat)
{
    $this->db->where('parent_id_cat', $id_cat);
            
    $this->db->where('activa_cat =', 1);
            
    $query=$this->db->get('categoria');
            
    if($query->num_rows()>0)
    {
        return $query->result();
    }
}}

On my CONTROLLER I have this:
Code:
function seccao($id)
{
        
$cat = $this->M_Categoria->getCategoria($id);
                
$data['menuprincipal'] = $this->M_Categoria->getCategoriasPrincipais();
        
    $data['menucategorias'] = $this->M_Categoria->getSubCategorias($cat->id_cat);
        
    $data['categoria'] = $cat;
        
    $data['main'] = 'v_categoria';
    
$this->load->vars($data);    
$this->load->view('geral_tpl');



On my VIEWS have this:


Header view

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

?&gt;

Category view:
Code:
<div id="menu_vertical">
    &lt;?php
     echo "<ul>";
         foreach ($menucategorias as $subcategoria)
         {
            echo "<li>";
echo anchor("c_categoria/seccao/{$subcategoria- >id_cat}",$subcategoria->nome_cat);
            echo "</li>";
          }
        echo "</ul>";    
    ?&gt;
</div>




Can I have your help on modifying this, in order to have the third menu also displayed like the other two?




Thanks a lot,
Márcio
#2

[eluser]brianw1975[/eluser]
can you be a bit clearer?

you say
Quote:I can put the first and second menus nicely. But when I put the third, it overs my second one, because I’m using the same method for both.

what do you mean by that?
#3

[eluser]MEM[/eluser]
[quote author="brianw1975" date="1251874488"]can you be a bit clearer?[/quote]

Yes, of course.

The layout is something like this:



LOGO
CATEGORIES MENU

sub_cat1 sub_subcat1
sub_cat2 sub_subcat2 {produt list}
sub_cat3 sub_subcat3
sub_cat4

Footer


For displaying the CATEGORIES MENU (on top of the page) I have done:

On the model (m_categoria.php):

Code:
function getCategoriasPrincipais()
{
    $this->db->where('parent_id_cat', NULL);
            
    $this->db->where('activa_cat =', 1);
            
    $query=$this->db->get('categoria');
            
    if($query->num_rows()>0)
    {
        return $query->result();
    }
}

On the controller (c_categoria.php):
Code:
$data['menuprincipal'] = $this->M_Categoria->getCategoriasPrincipais();

On the view (v_header.php):
Code:
&lt;?php
   echo "<ul>";
     foreach ($menuprincipal as $categoria)
     {
      echo "<li>";
    echo anchor("c_categoria/seccao/{$categoria->id_cat}",$categoria->nome_cat);
      echo "</li>";
     }
   echo "</ul>";
?&gt;


For displaying the subcategories menu (on the left side of the page):
On my model (m_categoria.php):
Code:
function getSubCategorias($id_cat)
{
    $this->db->where('parent_id_cat', $id_cat);
    $this->db->where('activa_cat =', 1);
    $query=$this->db->get('categoria');
            
    if($query->num_rows()>0)
    {
        return $query->result();
    }
}

On my controller (c_categoria.php):
Code:
$data['menucategorias'] = $this->M_Categoria->getSubCategorias($cat->id_cat);

On my view (v_categoria.php) (not header):
Code:
&lt;?php
  echo "<ul>";
   foreach ($menucategorias as $subcategoria)
   {
     echo "<li>";
       echo anchor("c_categoria/seccao/{$subcategoria->id_cat}",$subcategoria->nome_cat);
     echo "</li>";
   }
  echo "</ul>";    
?&gt;

The third menu, also displays using this same code (for displaying menu 2). Because, as we can see, it plays with IDs and URI segment values.

The issue is that, If I keep this system, NEVER, the second level menu and the third level menu will appear one near each other. I will always have, either the sub_menu or the sub_submenu on my page. The intended result was to have both: the sub_menu and the sub_submenu, to appear side by side.

Hope it's more clear now. But, if not, I'm absolutely online now for some long hours.



Regards and thanks for your reply,
Márcio
#4

[eluser]jedd[/eluser]
It sounds like you've already identified that you have a design issue here - so you either need to change it so that you have separate view partials for your separate sub/sub/submenu things, or have both sub/sub and sub/sub/sub menus generated within the same view (but sensibly, so that it can produce HTML to show both components in one go).
#5

[eluser]MEM[/eluser]
[quote author="jedd" date="1251906467"]It sounds like you've already identified that you have a design issue here - so you either need to change it so that you have separate view partials (...), or have both sub/sub and sub/sub/sub menus generated within the same view (but sensibly, so that it can produce HTML to show both components in one go).[/quote]

Exactly. On my newbie thoughts, I still deal with a confusion that it's calling "view" to the page we are seeing on the browser. Confused

Without hoping to arrive on a dead end, I'd like to have one view do deal with the display of my sub/sub and sub/sub/sub categories.

I do not intend to make a fancy menu or something. Something really simple. Two separate blocks.

I just need some dialectic to have some clicks on my head, because I'm tired of trying conditional instructions on my c_category, that leads nowhere. Confused

Any push?



Regards,
Márcio
#6

[eluser]jedd[/eluser]
Users, of course, are dumb. Will they be confused by three separate menus? Almost definitely. How about you have one menu, and it's as hierarchical as you need it to be. That way it's easier for your users - they have one place on-screen to use to navigate around your site. And it's easier for you, as you can generate one menu table/div block for all your menu goodness.

Generating a menu system with 2 levels of items is insanely simple (heck, I wrote one of those, and it works - qed). With varying levels is slightly more convoluted, but still the kind of thing that shouldn't make your toes curl. Compare and contrast an arrangement with : 1 x top menu , 1 x sub-menu , 1 x sub-sub-menu
#7

[eluser]MEM[/eluser]
When you talked about designer, I was thinking on another kind of design. Anyway, yes... for the subcategories/subsubcategories (the vertical part) I believe a menu would serve the propose.

[quote author="jedd" date="1251913331"]Users, of course, are dumb. Will they be confused by three separate menus? Almost definitely.[/quote]
They will not. But that's the design side of things. I have seen the layout that I have to work with, and I don't see where they will get confused. I think you have to trust me on this. Smile

[quote author="jedd" date="1251913331"]How about you have one menu, and it's as hierarchical as you need it to be. (...) it's easier for you, as you can generate one menu table/div block for all your menu goodness.[/quote]
I can have that kind of menu on the sub-categories/sub-subcategories side of things. I can visually separate them according to the designer needs, and still, create one menu only on this case.


Now, I just need to find a way to create a 2 level menu but, instead of starting with the categories, I start with the subcategories. Maybe a if "parent_id_cat != NULL" somewhere will get me there?

I will try to create that 2 level menu...


Regards,
Márcio
#8

[eluser]InsiteFX[/eluser]
2 level menu

add a parent_id field to your database, all parent menus the parent_id will = 0
all sumenus parent_id will be greater than 0

So if the parent_id = 0 then it is a main parent menu item else it will be a submenu item.

in your databse query parent_id sort ASC
jedd,
I now have the menu system displaying main menu with muliple dropdowns top menu bottom menu and verical menus
with unlimited dropdows or flyouts for vertical menus.

Enjoy
InsiteFX
#9

[eluser]MEM[/eluser]
[quote author="InsiteFX" date="1251928634"]
2 level menu

add a parent_id field to your database, all parent menus the parent_id will = 0
all sumenus parent_id will be greater than 0

So if the parent_id = 0 then it is a main parent menu item else it will be a submenu item.
[/quote]

I understand, and I have that already on my category table. I have a parent_id_cat, the code above shows that. Sad

More then table, or design problem, I have a php problem and the, a MVC problem, and lastly, a CI problem. Confused I realise that, and I'm sorry for ask this here.


I have tried this also:

On my CONTROLLER c_categoria I have added this:

Code:
if ($this->uri->segment(4) != NULL)
{
  $subcat = $this->M_Categoria->getCategoria($this->uri->segment(4));
  $data['menusubcategorias'] = $this->M_Categoria->getSubCategorias($subcat->id_cat);
}

On my VIEW v_categoria I have added this second menu:
Code:
<div id="menu_vertical2">
&lt;?php
$pag_actual=uri_string();
echo "<ul>";
  foreach ($menusubcategorias as $sub_subcategoria)
  {
   echo "<li>";
    echo anchor("$pag_actual{$sub_subcategoria->id_cat}",$sub_subcategoria->nome_cat);
   echo "</li>";
  }
echo "</ul>";    
?&gt;
</div>

It's not all correct, but at least is something.
Then to highlight the CURRENT menu item of both, the sub_category, and the sub_subcategory, maybe I can create some conditions based on the URI segments and the categories ID ?


Confused

M.




Theme © iAndrew 2016 - Forum software by © MyBB