Hey Chris,
I have created the menu as a component and an element. I call it for a
file called app/app_controller.php
=====================app_controller=======================
class AppController extends Controller {
    var $components  = array('othAuth', 'lemenu'); // necessary, we
need to have the othauth component so it can do it's business logic
     var $helpers = array('Html', 'OthAuth'); // html is always needed,
othauth helper is not a must, but you can do some cool things with it
(see later on)
var $othAuthRestrictions = "*CAKE_ADMIN";
var $uses=array('MenuPage');
//var $layout='page_refresh_permission';
 var $lesmenus;
     // these are the global restrictions, they are very important. all
the permissions defined above
     //are weighted against these restrictions to calculate the total
allow or deny for a specific request.
     function beforeFilter()
     {
$auth_conf = array(
     'login_page'  => '/users/login',
'logout_page' => '/users/logout',
'access_page' => '/users/index',
'hashkey'     => 'MySEcEeTHaSHKeYz',
'noaccess_page' => '/users/noaccess',
'strict_gid_check' => false
                        );
$this->othAuth->controller = &$this;
$this->othAuth->init($auth_conf);
$this->othAuth->check();
 if (low($this->name)!= 'app') {
 $this->lemenu->controller = &$this;

$this->lesmenus=$this->MenuPage->exposer();
$this->set('les_menus',$this->lesmenus);
$this->set('active',$this->lemenu->activer($this->lesmenus));
}//if
} //function
}//class
===============================================

//////////////////////////////////////////////////component
lemenu.php/////////////////////////////////////////////
class LemenuComponent extends Object {
var $active=1;
var $controller = true;



        function startup(&$controller) {
    $this->controller =& $controller;
}


 function init () {
        $this->controller->set('active',$this->activer($this->les_menus));
        $this->controller->set('active',$this->active);
}

  function activer ($les_menus) {
  $uri=$_SERVER['REQUEST_URI'];
  $i=0;

foreach ($les_menus as $valeur){
             if (!is_array($valeur)) {
 $i++;
             if (eregi($valeur,$uri)){

             $this->active=$i;
}
} else {

                             foreach($valeur as $svaleur) {
$i++;
                                     if (eregi($svaleur,$uri)){
                                     $this->active = $i;
}
}//foreach
}//else

}//foreach
  return $this->active;
} //méthode
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



===========================elements/nav.thtml============================
<ul id="nav">
                <?php $k=0; $i=0; $j=0; $menus=''; $k=0; ?>
                <?php $taille_1=count($les_menus); ?>
                <?php foreach ($les_menus as $libelle => $valeur): ?>

                <?php
                     if (!is_array($valeur)) {
        $i++; $k++;
                     if ($k==$active){
                     echo '<li class="active" id="">';
        }
                     elseif ($i==1){
                     echo '<li class="first">';
        }
                             elseif ($i==$taille_1){
                             echo '<li class="last">';
        }
                             else {
                             echo '<li>'."\n";
        }

                             if ($k==$active){
                             $lien=$html->link("$libelle",'#');
                             echo $lien;
        }
                             else {

                              $lien=$html->link($libelle,FULL_BASE_URL . 
$this->webroot .
$valeur);
$lien=ereg_replace('SID/SID', 'SID', $lien);
                             echo $lien;
        }
                             echo '</li>'."\n";
        } else {
                     $taille_2=count($valeur);
                             foreach($valeur as $slibelle => $svaleur) {
                                             $k++;
                                             $j++;
                                             if ($k==$active){

                                             echo '<li class="active">';
        $lien=$html->link($slibelle,$_SERVER['REQUEST_URI']);
$lien=ereg_replace('SID/SID', 'SID', $lien);
                             echo $lien;
        echo "\n";
                                             if ($j==1){
                                                echo '<ul>';
        }
                                                else {
                                                echo '</li>';
        }
        }
                                           elseif ($j==$taille_2){
                                          echo  '<li class="last">';
        $lien=$html->link($slibelle,FULL_BASE_URL . $this->webroot .$svaleur);
$lien=ereg_replace('SID/SID', 'SID', $lien);
                             echo $lien;
        echo '</li>'."\n";
        }
                                                elseif ($j==1){
                                                if (($active<($k+$taille_2)) && 
($active>$k)){

                                                   echo '<li class="active">';
                                                                if 
(is_numeric($slibelle)){

                                                $lien=$html->link($svaleur,'#');
                             echo $lien;

        }
        else {
        $lien= $html->link($slibelle,FULL_BASE_URL . $this->webroot
.$svaleur);
$lien=ereg_replace('SID/SID', 'SID', $lien);
                             echo $lien;
        }
        echo "\n";
        }
                                        else {

                                                echo '<li>';
                                                if (is_numeric($slibelle)){
                                                $lien= 
$html->link($svaleur,'#');
                             echo $lien;
        }
        else {
        $lien= $html->link($slibelle,FULL_BASE_URL . $this->webroot
.$svaleur);
$lien=ereg_replace('SID/SID', 'SID', $lien);
                             echo $lien;
        }
        echo "\n";
        }
                                                echo  '<ul>';

        }
                                                elseif ($j==2){
                                                echo '<li class="first">';


        $lien= $html->link($slibelle,FULL_BASE_URL . $this->webroot
.$svaleur);
$lien=ereg_replace('SID/SID', 'SID', $lien);
                             echo $lien;

        echo "\n";
        }
                                             else {
                                                echo '<li>';
                                                $lien= 
$html->link($slibelle,FULL_BASE_URL . $this->webroot
.$svaleur);
$lien=ereg_replace('SID/SID', 'SID', $lien);
                             echo $lien;
                                                echo '</li>'."\n";

        }//else
        }//foreach
                        $j=0;
        echo '</ul></li>'."\n";
        }//else


                     endforeach;
        echo "\n";

        ?>
        </ul><br />
==============================================================

Cheers
Sten


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to