Where should the breading path be declared (in other words, in which MVC letter)? While I am declaring this in controllers, I recently started working with CakePHP, where everything is done in Views, and it surprised me.
I am going to answer this question because there is a lot of confusion about what should and should not be done with breadcrumbs.
A model is a layer that contains business logic that consists of domain objects, data cards, and services. Read more about the model here .
: , . / . , , , , , , .
, . :
:
class=current
/** * So we're in the home controller, and index action * * @route localhost/home or localhost/home/index * (depending on .htaccess, routing mechanism etc) */ class Home extends Controller { public function index() { // Get current class name, so we have the current page $class = __CLASS__; // Let say the page heirachy is tied to the model, so get pages for current method, or however you want to implement it $pages = $model->getPages($class); // So the TEMPLATE handles the breadcrumbs creation, and the controller passes it the data that it needs, retrieved from the model // (new Template) is PHP 5.4 constructor dereferencing, also included is some lovely method chaining // setBreadcrumbs() would assign variables to the view // Render would do just that (new Template)->setBreadcrumbs($currentPage, $pages)->render(); } }
, ... , PHP 5.4, ...
<body> <?php foreach($breadcrumbs as $b) { ?> <li <?=($b['current'])?'class="current"':''?>> <a href="<?=$b['page']['url']?>"> <?=$b['page']['title']?> </a> </li> <?php } ?> </body>
. , , , , .
googling "php mvc breadcrumbs", . !
, "" "" , . Controller, - , , -, MVC.
. CodeIgniter -
$data['breadcrumb'][0] = array("title" => "Home", "alt" => "Home Page", "path" => "home/"); $data['breadcrumb'][1] = array("title" => "About", "alt" => "About Me", "path" => "home/about");
.
<ul class="breadcrumbs"> foreach($breadcrumb as $b) { ?> <li><a href="<?php echo base_url(); ?>index.php/<?php echo $b['path'];?>" alt="<?php echo $b['alt']; ?>"><?php echo $b['title']; ?></a></li> <?php } </ul>
, , .. - .
ALL . , .
,
<?php echo ($loggedin)?"Logged in as" . $user->firstname:"Not logged in";?>
. . . . , . HTML, .
(, , , script , javascript ..), .
IMO, , , . , . , , , , , . , -, MVC , DRY >
, breadcrumb , , , url . , , , .
, . CakePHP ( PHP, ), , . , . .
$this->Html->addCrumb('Home', '/pages/home'); $this->Html->addCrumb('Contacts', '/pages/contacts'); echo $this->Html->getCrumbs('»', 'StartText');
Source: https://habr.com/ru/post/1749732/More articles:Error deploying web application in OSGI container using pax website - jettyHow to add similar functionality to multiple methods in java? - javaDependency properties, change notification, and setting values ββin the constructor - c #UIAlertView subclass with text fields for iOS 4 - iphoneIt is possible to set a filter on a subform from the parent form before loading subform data - ms-accessAbout sorting Algorithms applied to stacks and queues - javawhich png format should i use? - imageUIViewController removes subview - iphoneUsing delegation methods and methods - c #How to use taglib - javaAll Articles