How to make menu navigation structures with Kohana? - php

I had created my own little lightweight framework for small projects, and now switched to Kohana.
But I wonder what's the way to go to achieve navigation hierarchies.
Example: I have a menu like this:
Home | Products | Support | Contact
In my old framework, when the user clicked on "Products", my framework knew which navigation layer this is and then my view attached an "_active" suffix to the css class of that menu item, so it's highlighted. The same for all parent navigation elements.
How are you setting up your site in Kohana to achieve something like this?
I thought about making one big layout view that contains the menu bar. There, I would have to implement all the logic to figure out which menu item has to be highlighted as active. Is there any clever mechanism for this, or would I just have to figure out from the current url somehow in a bunch of if-statements, if an url segment matches the menu item?

You can use the uri::segment() method to get the current page, and then determine what your suffix should be based on that.
Example:
# Example Url: http://www.example.com/index.php/article/paris/hilton/
echo $this->uri->segment(3); // Returns 'hilton'
From there it's just a matter of checking the returned value against each one of your navigation links - when it maches, add your suffix.

Related

ZF2 Navigation: How to show some pages ONLY in breadcrumb navigation

In Zend Framework 2 I use ZendNavigation for the main navigation and the breadcrumb-navigation. I want the Breadcrumb-Navigation to show on every page, but I do not want every page to appear in the main navigation.
So in other words I want some pages to show ONLY in breadcrumb navigation.
Is there any way to achieve this? Maybe an option that can be set in the navigation-array? Or do I need to create two different navigations and use one as main navigation and the other as breadcrumb?
Edit
It doesn't really make sense to duplicate the 'pages' configuration as you can instruct the view helper to render what you need. So you can use the same navigation container to render different menus (e.g. breadcrumb vs main navigation).
You can do this by either using the provided breadcrumb methods such as setMaxDepth() or setMinDepth(). Alternatively, for more flexibility, use a view partial as I explained bellow.
In each case you are simply filtering down the complete container into the seletion you want to render.
You can use a view partial to render the breadcrumbs.
This method will find the deepest active page and pass an array of pages that leads to the active page to the partial view script.
The example in the attached link uses array_map to render the contents of $this->pages, however you can achieve the same result with a loop.
foreach($this->pages as $page) {
printf('%s', $page->getHref(), $page->getLabel());
}
Keep in mind however you will now need to check the accessibility of the page manually for the current user if you are using the ACL - This can be done using the methods available for MVC or URL pages

Joomla article pretty url that's not tied to a menu

I am working in Joomla 1.5 and have an article that I don't want listed in any of my menus. It is a special promotional page that exclusive people will be given the link to. Is there a way to give the article a pretty URL?
Currently the URL that works is /index.php?option=com_content&view=article&id=35. I would like that to be /15k.
Anyone help me?
I have seen this question, but the URL isn't quite what I'm looking for.
To get that URL you will need Joomla!'s SEF/SEO settings turned on (I'm assuming you've already got that setup).
In Joomla you have to create a new menu, call it something like "Utility Menu" but don't give it a "Module Title" - you don't want to display this menu so you don't need the module.
Then create a "Single Article" menu item with the alias 15k as a menu item within the "Utility Menu". You should now be able to access the article at the http://www.yoursite.com/15k
If you want to link to this from another menu create a menu item alias and point it at the 15k menu item. If you want to link from within an article simply point the link to the 15k menu item.
[Edit]
Routing in Joomla! first looks through the user defined paths (i.e. menu's and their menu items) then if it can't find a match for the requested resource that way it asks the particular component to build the route and if the components router is basic (i.e. nearly every single one in Joomla! 1.5) then you get the ?option=com_somecomponent&id=X style result. In 2.5 this is much improved but still uses the same routing mechanism.

Can I create a menu with sub-menus in Agile Toolkit?

The menu class documentation - and the provided example - do not seem to show any way for me to build a navigation menu with more than 1 level of navigation.
What do I do if I want to build an 'app-style' menu - like 'File' or 'Edit' - which will include sub-menus? Is there a way to create this automagically with Agile Toolkit, or is this something that would have to be coded by hand with html templates, css files, etc.?
there is no such component by default - however, View "plug'n'play" also works for Menu's
here is one example of real life 2-level submenu:
http://www.gradpool.ie/gradmatcher/graduate/company.html?id=38
idea there is that menu is constructed, and drop downs which fall out are yet another menu objects inserted into menu items.
add-on for this purpose has been created, read here:
http://www.ambienttech.lv/blog/2012-07-06/tree_view_in_agile_toolkit.html
I would suggest to use your own CSS along with Menu_Light, which is designed to get out of your way as much as possible.
https://github.com/romaninsh/atk4-sitesample/blob/day1/templates/Symisun_01/shared.html
https://github.com/romaninsh/atk4-sitesample/blob/day1/lib/Application.php
The only thing it does is adding a class to your menu template, the rest you control over the HTML.
As a result you'll get something like this: http://example.agiletoolkit.org/examples/website/index.symisun
Be sure to use page tag around page names account/register.

Joomla - configuring basic parameteres for my component in menu manager

Im still relatively new to Joomla component development.
I have a component that manages rsvps to events.
In the administration side you create various events and specify the details of when where and what time the event starts etc. Each event has an eventid.
In the frontend I want to be able to show a specific events details when a menuitem is clicked.
In Joomla administration, my thinking is as follows:
1) Go to Menus->Top Menu
2) Click on [New] to create a new Top Menu Item
3) My component is listed there as MyRSVPComponent
But when I click on it, nothing happens??
All the other default components like search have submenus that you can click on that takes you to a Menu Item page and you are able to configure the Basic Parameters on the right hand side.
I want my component to behave like that as well and I want to be able to pick the event from a list that I want displayed for that menu item. How would I go about doing this?
Please do note that I have not followed the Joomla 1.5 MVC structure for my component.
Can I still make this work, or am I forced to create the project with the MVC structure.
I have my reasons for not wanting to go with MVC for this particular project so please do not just suggest that I go MVC unless that is the ONLY way that I going to achieve what I need to do.
The options you see in the menus are controlled directly by the views in your component. You will need a view for each menu item type you would like to have. You don't have to go MVC but it would certainly make life easier.
I just came across this question with the view to integrate a Symfony project into a Joomal component. Naturally I don't want to use the Joomla MVC for this as well.
I have done some debugging on how to create your menu links:
You need to have the link field set for your component, matching your component folder
You need to have the views folder, matching the "option" field value of your component database entry
As soon as you have this, the menu manager is going to show your views as options
To have specific view sub options, you need to create /com_yourcomponent/views/yourview/layout.xml, copy these from com_content. In there you can also define your menu options.

is there a way to use a view as a menu in drupal?

I want to have a view displayed as a menu either in primarylinks or secondarylinks.
I searched and looked up all modules with no luck.
should I build this functionality manually ==> build a module?
thanks in advance
Primary and secondary links (in fact, all menus) are rendered as unordered lists of links using a theme function like theme_links(). You can get pretty close to the same functionality by using the HTML List style within a view.
You can't duplicate it exactly because Drupal's menu system requires static menu items: it doesn't handle wildcards like the results of a query.
That is, Drupal's menu system is cached, and is only rebuilt upon request (e.g. by adding a menu item manually, clearing the cache, etc.) A view, on the other hand, is a wrapper to a query: every time you access the view, unless it too is cached, it runs a query to get the latest results.
So, if you were to inject a view into a menu, it'd only be the results at the time of first request, and any subsequent changes would require rebuilding the menu.
The solution I suggested will let you keep the functionality of the view, theme it to look like a menu, and avoid the caveats of the menu system.

Categories