GithubHelp home page GithubHelp logo

kohana-nav's Introduction

Nav

Navigation menu simple helper for Kohana3 PHP framework

Data "types"

Navitem, a link formatted as array

$navitem = array(
    'title' => 'Item1',
    'href'  => 'http://domain.es',
    'target'=> '_blank'
);

Navdata, an array of navitems

$navdata = array(
    array(
        'title'=>'Item1'
        'href'=>'http://google.es'
    ),
    array(
        'title'=>'Item2'
    )
);

Usage

As a static helper, you can call Nav from wherever you want. There are some examples calling Nav in different ways, that may help you.

Creates a breadcrumb

$nav = Nav::instance();
$nav->add_navitem(
    array(
        'title'  => $group->name,
        'href'   => URL::site($group->link)
        'target' => '_blank'
    ) );
$nav->add_navitem(
    array( 
        'title'  => $subgroup->name,
        'href'   => URL::site($subgroup->link)
    ) )
$nav->add( $product->name, URL::site($product->link) )
$nav->add( $subproduct->name );
$html = $nav->render();

Creates a breadcrumb using chainable methods, from a view

<html>
    <body>
    <?php echo Nav::instance()->add('Home','/')->add('News','/news')->add('New'); ?>
    </body>
</html>

The render() method is automagically called using __toString() The resultant code is:

<ul id="nav">
    <li><a href="/">Home</a></li>
    <li><a href="/news">News</a></li>
    <li>New</li>
</ul>

You can easily stylize it using CSS.

The way I use it

I use the Controller_Template to manage the views of my App, and then I added a private $nav; atribute to my Controller_Base wich extends the Controller_Template and from wich the rest of my controllers extend. I initialize $nav on the it's constructor, with an initial Home value.

$this->nav = Nav::instance()->add('Home', URL::site());

Later, on whathever action method of any app controller, I add specific navigation info.

$this->template->nav->add( $promo->name,    $promo->link )
                    ->add( $cat->name,      $cat->link )
                    ->add( $product->name );

And finally, the data has to be rendered somewhere. I added it to my template

<html>
    <body>
        <div id="header"><?php echo $nav->render(); ?></div>
    </body>
</html>

Other Info

Version 0.6 - 2011/02/06

License (http://creativecommons.org/licenses/by-sa/3.0/ "CC BY-SA 3.0")

Author Jesús Díez

kohana-nav's People

Contributors

jesusdiez avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.