Next Chapter: CakePHP upload Images

Creating Reusable View Components in CakePHP

2019-05-13 16:19:38.969472+00

The are some information on the views which appear several times. Those elements should be developed once and reused. In our book the navigation appears in the top on in the bottom of the page.

First we create a file for the chapter navigation with the name "ChapterNavigation.ctp"

vi /usr/local/www/logikfabrik.com/cakephp/app/View/Elements/ChapterNavigation.ctp

The content of "ChapterNavigation.ctp" is as follows


<?php

echo '<div class="btn-group btn-group-justified paddingBottom20" role="group" aria-label="...">';

if (!empty($chapter[0][0]['prev_title'])) {
  echo '<a class="btn btn-default" role="button" href="/books/' 
  echo $chapter[0][0]['book_id'] . '/' . $chapter[0][0]['name']. '/';
  echo $chapter[0][0]['prev_id'] . '/' . $chapter[0][0]['prev_title']. '">';
  echo '<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> ' . $chapter[0][0]['prev_title'] . '</a>';
}

echo '<a  class="btn btn-default" role="button" href="/books/';
echo $chapter[0][0]['book_id'] . '/' . $chapter[0][0]['name']. '">';
echo ' TOC'  . ' <span class="glyphicon glyphicon-chevron-up" aria-hidden="true"></span></a>';


if (!empty($chapter[0][0]['next_title'])) {
  echo '<a  lass="btn btn-default" role="button" href="/books/';
  echo $chapter[0][0]['book_id'] . '/' . $chapter[0][0]['name']. '/';
  echo $chapter[0][0]['next_id'] . '/' . $chapter[0][0]['next_title']. '">';
  echo $chapter[0][0]['next_title'] . ' <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span></a>';
}
echo '</div>';

Tag: cakephp2

Previous Chapter: CakePHP 2.x: Registration for a new book

Next Chapter: CakePHP upload Images