Re: Dynamic menu content in layout

2014-03-06 Thread Art Sir
nice!! i was looking for this information as well.

On Wednesday, February 26, 2014 4:58:21 PM UTC-5, euromark wrote:
>
> Take a look at the ideas here:
> https://github.com/MenschDankeGmbH/cake-menu_builder
> Maybe that helps.
>
>
> Am Samstag, 22. Februar 2014 11:46:16 UTC+1 schrieb Sam Clauw:
>>
>> What I'm trying to do is to put two dynamic navigation menus in my 
>> CakePHP layout (default.ctp). The main menu should have multiple levels 
>> (with a dropdown functionality). The secondary menu is the one that shows 
>> the dropdown content of the main menu in a left sidebar.
>>
>> I've read the CakePHP documentation but I'm confused how to fit those 
>> menus in the layout. I know that you have 4 different parts in a view layer 
>> (as documented in http://book.cakephp.org/2.0/en/views.html):
>>
>>- views
>>- elements
>>- layouts
>>- helpers
>>
>> But with the knowledge I have right now, I think none of this parts can 
>> be used to fill my needs. A navigation menu is a part that you only load 
>> ONES in a layout, so it isn't an element or a helper. So what's the best 
>> practice...
>>
>>- ... where to create the menu tree?
>>- ... where / how to echo it in the layout file?
>>
>> Can anybody clearify my issue? Thanks in advance! ;)
>>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Dynamic menu content in layout

2014-02-28 Thread Dr. Tarique Sani
What you are really wanting is the ViewModel. CakePHP does not implement
that explicitly but you can get the same functionality by creating a helper
and accessing your model in the helper keeping the view clean.

HTH

Tarique



On Thu, Feb 27, 2014 at 1:09 AM, Sam Clauw  wrote:

> Okay, let's suppose I want to put my menu in an element called
> "top_menu.ctp". I want to get my data out of the database, so probably, I
> shouldn't connect with my
>




-- 
=
The Conference Schedule Creator : http://shdlr.com

PHP for E-Biz : http://sanisoft.com
=

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Dynamic menu content in layout

2014-02-26 Thread euromark
Take a look at the ideas here:
https://github.com/MenschDankeGmbH/cake-menu_builder
Maybe that helps.


Am Samstag, 22. Februar 2014 11:46:16 UTC+1 schrieb Sam Clauw:
>
> What I'm trying to do is to put two dynamic navigation menus in my CakePHP 
> layout (default.ctp). The main menu should have multiple levels (with a 
> dropdown functionality). The secondary menu is the one that shows the 
> dropdown content of the main menu in a left sidebar.
>
> I've read the CakePHP documentation but I'm confused how to fit those 
> menus in the layout. I know that you have 4 different parts in a view layer 
> (as documented in http://book.cakephp.org/2.0/en/views.html):
>
>- views
>- elements
>- layouts
>- helpers
>
> But with the knowledge I have right now, I think none of this parts can be 
> used to fill my needs. A navigation menu is a part that you only load ONES 
> in a layout, so it isn't an element or a helper. So what's the best 
> practice...
>
>- ... where to create the menu tree?
>- ... where / how to echo it in the layout file?
>
> Can anybody clearify my issue? Thanks in advance! ;)
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Dynamic menu content in layout

2014-02-26 Thread Thomas von Hassel
No, you don't want to anything in the view that involves querying the database. 
The controller action for that given page should know what menu to fetch from 
database and set that to the view.


/thomas


On 26 Feb 2014, at 20:39, Sam Clauw  wrote:

> Okay, let's suppose I want to put my menu in an element called 
> "top_menu.ctp". I want to get my data out of the database, so probably, I 
> shouldn't connect with my database in that .ctp file. I wonder if that's the 
> right way to do so? MVC normally split us the model logic and the view logic, 
> but now you'll all get it in one file? Or am I missing something? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Dynamic menu content in layout

2014-02-26 Thread Sam Clauw
Okay, let's suppose I want to put my menu in an element called 
"top_menu.ctp". I want to get my data out of the database, so probably, I 
shouldn't connect with my database in that .ctp file. I wonder if that's 
the right way to do so? MVC normally split us the model logic and the view 
logic, but now you'll all get it in one file? Or am I missing something? ;)

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Dynamic menu content in layout

2014-02-22 Thread Salines
hi, 
You can put the tree menu directly in the layout or in a separate menu 
elements and include them in a specific place on your layout. 

If you want to highlight active link in your menu, you can do the 
following: 

// menu

..link to 
contacts views
..link to 
contacts views
...

// in Posts/index.ctp
// in Posts/view.ctp
..
$this->set('active','posts');

If you want to dynamically add or modify the sidebar, use and expand the 
view blocks
http://book.cakephp.org/2.0/en/views.html#extending-views

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.


Re: Dynamic menu based on deep relationships

2010-09-18 Thread meekamoo
Ah thanks for your help, I managed to sort it out.

Got it working quite nicely with ajax menu on the sidenav.

/countries/view/204 is the main screen showing the provinces for the
country (only one country now, so countries arent really used)
/provinces/view/xxx views the regions belonging to the province

the ajax menu calls /(currentaction)/ajaxmenu/(currentvalue) so even
if a user goes directly to a region/suburb etc then the ajax menu will
start where it should.

Thanks for your help though, managed to get it sorted after a stroke
of genius!

On Aug 30, 6:53 am, Sam  wrote:
> I think I know what you want but I'm not sure... let me know if I'm
> close.
>
> I'd do it one of two ways
>
> 1) User selects a province, page refreshes and now there are two
> dropdown boxes, first one has province selected, in the second user
> chooses region(and so forth)
> 2) User selects a province, select box appears with regions in that
> province(and so on and so forth)
>
> For method 1 I'd have the javascript submit the page each time a
> dropdown is changed- then the controller can figure out which menu
> items to load for the next select box. If several select boxes have
> been chosen, such as province, region and suburb, and province is
> changed, then the form would basically reset to only show the province
> and region select boxes.
>
> For method 2 I'd either use ajax to query the database based on the
> change in any of the select boxes, and reload the values in the select
> boxes. When the last select is chosen it loads the proper view.
>
> As for the menu knowing where the user is, simply set the relevant
> fields(province_id, region_id, suburb_id and establishment_id) based
> on the data that is loaded... if you load a suburb it should be
> relatively easy to get the region_id and province_id for that suburb.
>
> On Aug 29, 10:59 am, Bryan Paddock  wrote:
>
>
>
> > Hey all,
>
> > I've looked through pretty much every menu tutorial out there for cakephp
> > and have sat for ages to try and think up how I can achieve this but to no
> > avail.
>
> > I have a semi-complex database structure of establishments (restaurants,
> > hotels etc).
>
> > Province -> Region -> Suburb -> Establishment
>
> > as well as
>
> > Category -> Subcategory -> Establishment
>
> > Now the user needs to be able to select the province from the list, have it
> > show the regions under that province, then the suburbs, then a list of
> > subcategories under that province that contain establishments. I can handle
> > the fetching the data (eg how to pull out the list using containable etc)
> > but it's the starting foundation I'm having problems figuring out. IT will
> > be done in ajax but the actual ajax part I could probably do myself.
>
> > I would like to have the menu also build itself from the page that the user
> > is on (eg the user can browse around the menu in itself but if he also goes
> > to the a related page (eg suburbs/view/cape-town) then the menu should know
> > where the user is)
>
> > I honestly can't think of even where I should start here. Building a menu is
> > simple in plain php with simple relationships but it's getting pretty tricky
> > with all the extra levels.
>
> > Does anyone have any advice on a starting point which I could work with...
> > I'm trying to make it extendable in the sense that I don't want to hard code
> > anything.
>
> > I'm starting to think it may be better off to handle the menu separately in
> > a menu model and update the menu on each of the related models afterSave(),
> > etc callback but that seems a bit unnecessary as it would just be duplicated
> > data.
>
> > Thanks in advance!
>
> > Bryan

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Dynamic menu based on deep relationships

2010-08-29 Thread Sam
I think I know what you want but I'm not sure... let me know if I'm
close.

I'd do it one of two ways

1) User selects a province, page refreshes and now there are two
dropdown boxes, first one has province selected, in the second user
chooses region(and so forth)
2) User selects a province, select box appears with regions in that
province(and so on and so forth)

For method 1 I'd have the javascript submit the page each time a
dropdown is changed- then the controller can figure out which menu
items to load for the next select box. If several select boxes have
been chosen, such as province, region and suburb, and province is
changed, then the form would basically reset to only show the province
and region select boxes.

For method 2 I'd either use ajax to query the database based on the
change in any of the select boxes, and reload the values in the select
boxes. When the last select is chosen it loads the proper view.

As for the menu knowing where the user is, simply set the relevant
fields(province_id, region_id, suburb_id and establishment_id) based
on the data that is loaded... if you load a suburb it should be
relatively easy to get the region_id and province_id for that suburb.

On Aug 29, 10:59 am, Bryan Paddock  wrote:
> Hey all,
>
> I've looked through pretty much every menu tutorial out there for cakephp
> and have sat for ages to try and think up how I can achieve this but to no
> avail.
>
> I have a semi-complex database structure of establishments (restaurants,
> hotels etc).
>
> Province -> Region -> Suburb -> Establishment
>
> as well as
>
> Category -> Subcategory -> Establishment
>
> Now the user needs to be able to select the province from the list, have it
> show the regions under that province, then the suburbs, then a list of
> subcategories under that province that contain establishments. I can handle
> the fetching the data (eg how to pull out the list using containable etc)
> but it's the starting foundation I'm having problems figuring out. IT will
> be done in ajax but the actual ajax part I could probably do myself.
>
> I would like to have the menu also build itself from the page that the user
> is on (eg the user can browse around the menu in itself but if he also goes
> to the a related page (eg suburbs/view/cape-town) then the menu should know
> where the user is)
>
> I honestly can't think of even where I should start here. Building a menu is
> simple in plain php with simple relationships but it's getting pretty tricky
> with all the extra levels.
>
> Does anyone have any advice on a starting point which I could work with...
> I'm trying to make it extendable in the sense that I don't want to hard code
> anything.
>
> I'm starting to think it may be better off to handle the menu separately in
> a menu model and update the menu on each of the related models afterSave(),
> etc callback but that seems a bit unnecessary as it would just be duplicated
> data.
>
> Thanks in advance!
>
> Bryan

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Dynamic Menu

2010-08-24 Thread _k10_
Not sure if this answers your query but have a look @
http://book.cakephp.org/view/1023/find-threaded


On Aug 23, 10:29 pm, nightshadex101  wrote:
> Hi All,
>
> I'm trying to build a menu system.
> I've already created a table in the database, a model (with tree
> behavior), and a controller.
>
> The idea is that the menu has 2 levels (it will probably get 3 levels
> later), and the following is showed:
>
> -All parent of 1st level pages (controllers)
> If I'm on a parent page (ie: a controller)
>     -All my children/2nd level pages (funcions in that controller)
> If I'm on a 2nd level page
>     -All the other children of my parent (all the other functions in
> that controller)
>
> What I'm not getting is how to call this function from an element (to
> later insert in the layout) so that I can pass the current page to the
> controller function.
>
> This is the db table:
>
> CREATE TABLE IF NOT EXISTS `menus` (
>   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
>   `parent_id` int(10) DEFAULT NULL,
>   `lft` int(11) DEFAULT NULL,
>   `rght` int(11) DEFAULT NULL,
>   `name` varchar(255) COLLATE latin1_general_cs DEFAULT '',
>   `location` varchar(255) COLLATE latin1_general_cs DEFAULT '',
>   `status` tinyint(1) NOT NULL,
>   `created` datetime DEFAULT NULL,
>   `modified` datetime DEFAULT NULL,
>   PRIMARY KEY (`id`)
>
> Model:
>
>  class Menu extends AppModel {
>         var $name = 'Menu';
>         var $actsAs = array('Tree');}
>
> ?>
>
> Controller:
>
>  class MenusController extends AppController {
>
>         var $name = 'Menus';
>
>         function getMenu($location = null) {
>                 if(substr($location,-1,1) == '/')
>                         $location = substr($location,0,strlen($location)-1);
>                 $locationId = $this->Menu->field('id', array('location' =>
> $location));
>                 $allParents = $this->Menu->find('all', array(
>                         'fields'         => array('Menu.id', 'Menu.name', 
> 'Menu.location'),
>                         'conditions' => array('Menu.parent_id' => null, 
> 'Menu.status'      =>
> 1)
>                 ));
>                 $myParent = $this->Menu->getparentnode($locationId);
>
>                 if ($myParent) {
>                         $secondLevel = 
> $this->Menu->children($myParent['Menu']['id'],
> true);
>                 } else {
>                         $secondLevel = $this->Menu->children($locationId, 
> true);
>                 }
>
>                 $secondLevelFiltered = array();
>                 $i = 0;
>                 foreach ($secondLevel as $children) {
>                         if ($children['Menu']['status'] == 1) {
>                                 $secondLevelFiltered[$i]['id'] = 
> $children['Menu']['id'];
>                                 $secondLevelFiltered[$i]['name'] = 
> $children['Menu']['name'];
>                                 $secondLevelFiltered[$i]['location'] = 
> $children['Menu']
> ['location'];
>                                 $i++;
>                         }
>                 }
>
>                 $menuTree = array();
>                 $i = 0;
>                 foreach ($allParents as $parent) {
>                         $menuTree[$i] = $parent['Menu'];
>                         if ($myParent) {
>                                 if ($myParent['Menu']['id'] == 
> $parent['Menu']['id']) {
>                                         $menuTree[$i]['children'] = 
> $secondLevelFiltered;
>                                 }
>                         } else {
>                                 if($locationId == $parent['Menu']['id']) {
>                                         $menuTree[$i]['children'] = 
> $secondLevelFiltered;
>                                 }
>                         }
>                         $i++;
>                 }
>                 return($menuTree);
>         }}
>
> ?>
>
> Could someone give me some orientation on how to procede from here?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Dynamic Menu

2009-09-17 Thread iFeghali

Yes, I did in cake.

I am no expert, so be aware that my solution can have some flaws.

so in app_controller.php :

Auth->user()) {
$controllerList = Configure::listObjects('controller');
$permittedControllers = array();

foreach ($controllerList as $controllerItem) {
if (($controllerItem != 'App')
&& ($this->__permitted($controllerItem, 'index'))
) {
$permittedControllers[] = $controllerItem;
}
}

/**
 * build menu based on user's permissions
 */
$this->nav = array_intersect($this->nav,
$permittedControllers);

/**
 * build sub menu based on user's permission
 */
foreach ($this->subnav as $k => $s) {
if (is_array($s)) {
if (empty($s)) {
unset($this->subnav[$k]);
continue;
}
$s = (string)array_shift($s);
}

if (!$this->__permitted($this->name, $s)) {
unset($this->subnav[$k]);
}
}
}

$this->set('nav', $this->nav);
$this->set('subnav', $this->subnav);
}
?>

"nav" holds an array of "menu items". In my case all items are
controller names, because i build my menu based on them. then I have a
"subnav" that holds the controllers actions so I show only the action
that the user has access to. so in the layout (or view) I loop into
the vars "nav" and "subnav" building the menu.

of course you can hack it to have a different approach.

Best,
~IF.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic Menu

2006-10-23 Thread Sonic Baker
Hi Sten,Thank you for your reply and code samples. I'm sure this will be a great help. I'll let once I get a change to try and implement the menu's.Cheers,Sonic

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


Re: Dynamic Menu

2006-10-23 Thread Steniskis

Hello
I have created a component with my menus
I began with the menu tutorial in the wiki
http://wiki.cakephp.org/tutorials:building_a_cakephp_site_part_-_1

I call the menu from my controller
lass RapportsController extends AppController {

var $name = "Rapports";
var $layout = "page";
var $helpers= array('html', 'javascript', 'ajax', 'time', 'page',
'thickbox', 'awbarplot');
var $components = array('Menu');
var $beforeFilter = array('init');
function init() {
// Create menu component
$this->Menu->controller = &$this;
$this->Menu->init($this->name);
}
...
?>

then I have the menuComponent where I build an array. The variable
$_SERVER['REQUEST_URI']; is used to know which on which page we are.
 'accueil/',
"Collecte" => array(
1 => "Collecte",
"Tournées" => "tournees/",
"Equipes" => "equipes/",
"Personnels" => "personnels/",
"Secteurs" => "secteurs/"
),

"Rapports" =>  "rapports/",

"Admin" => array(
1 => "Admin",
"Droits Accès" => "acces/",
"Usagers et groupes" => "usagers/",
"Importations" => "importations/"
),
"Réclamations"  => "reclamations/",
"Déchetteries"  => "dechetteries/"
);

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


 function init () {
$this->controller->set('les_menus',$this->les_menus);
$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
} //méthode

}
?>
then in your view you include your element
renderElement('nav',$les_menus); ?>

then here is your element




 $valeur): ?>

';
}
 elseif ($i==1){
 echo '';
}
 elseif ($i==$taille_1){
 echo '';
}
 else {
 echo ''."\n";
}

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

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

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

   echo '';
if 
(is_numeric($slibelle)){

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

}
else {
echo $html->link($slibelle,FULL_BASE_URL . $this->webroot .$svaleur);
}
echo "\n";
}
else {

echo '';
if (is_numeric($slibelle)){
echo $html->link($svaleur,'#');
}
else {
echo $html->link($slibelle,FULL_BASE_URL . $this->webroot .$svaleur);
}
echo "\n";
}
echo  '';

}
elseif ($j==2){
 

Re: Dynamic Menu

2006-10-22 Thread Sonic Baker
Hi there,I'm also looking for a solution to this problem but haven't gotten round to it yet. I was searching cakeforge for one but there doesn't seem to be one.I was thinking of something like a series of nested 'tab menus' which look something like the tab menus on the cake API.
Once a tab is active it stays highlighted as that active menu even when navigating through sub menus.There is a tutorial on the wiki about caching dynamic menus but that only sorts out the optimisation part of things.
I'd appreciate it if you could let me know if you find something.Cheers,Sonic

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