PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 17, 2022

[FIXED] Where do I set the navbar in CakePHP 3.0 with Bootstrap?

 January 17, 2022     cakephp, cakephp-3.0, twitter-bootstrap     No comments   

Issue

I'm getting started with CakePHP 3.0 and I'm getting stuck on some code location issues. I installed this plugin to integrate Twitter Bootstrap: https://github.com/elboletaire/twbs-cake-plugin I've copied Layout/default.ctp into my main Layout folder and it's working wonderfully, except I'm not sure where to put my Navbar code.

The layout contains this section where the Bootstrap navbar is set up:

<div class="navbar-header">
  <?php if ($this->fetch('navbar.top')): ?>
  <button data-target="#navbar-top" data-toggle="collapse" type="button" class="navbar-toggle">
    <span class="sr-only">Toggle navigation</span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
    <span class="icon-bar"></span>
  </button>
  <?php endif; ?>
  <?=$ this->Html->link(Configure::read('App.name'), '/', ['class' => 'navbar-brand']); ?>
</div>
<?php if ($this->fetch('navbar.top')): ?>
<nav role="navigation" class="collapse navbar-collapse" id="navbar-top">
  <ul class="nav navbar-nav">
    <?=$ this->fetch('navbar.top'); ?>
  </ul>
</nav>
<?php endif; ?>

I know I need to set navbar.top, but I can't figure out where to set it. My attempt to set it from initialize() in AppView.php using:

$this->set('navbar.top', '<li>Hello</li>');

didn't do anything, and I have no idea where else would make sense to put a universal navbar.

I have no problem just putting it into the template, but the code in the default layout for the Bootstrap plugin seems to suggest otherwise.

Can someone help me figure out where I am supposed to set up the Bootstrap navbar code so it's accessible to my default layout? Thanks so much!


Solution

Put the nav bar inside the element folder.

In layout call element

echo $this->element('navbar.top');


Answered By - Sudhir
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing