the main question about my topic is, where should I put the data for title-tag, aside-tag …
Actual stand:
I’m building a webpage without database. I’ve put in /templates/element files like nav.php and footer.php.
In /templates/Pages files like home.php and site_notice.php, so the PagesController rule the /templates/Pages directory, right?!
If I try to talk to the /templates/Pages via self made actions below the CakePHP standard function in PagesController it doesn’t work.
I read, that Controllers are normally used for the connection between database and views. The Components are additions for the Controllers, right?
So my idea is to make a own PHP file where I put some functions with
for every site I’ve made, because I don’t want to mix up my /template files with PHP and HTML code.
Should I solve it this way? Is it CakePHP confirm?
Where should I put my own PHP files if they nothing have to do with any kind of database?
Now I would try to set the title which should be for /templates/Pages/home.php: Home and for /templates/Pages/site_notice: Site notice.
In /templates/element I have aside.php. It should display on Home: Home and on Site notice: Site notice.
I’m very unsure if it’s a good idea to solve it with an selfmade controller, because (if I understand it in a right way) the given CakePHP Controller “PagesControler” handles /templates/pages already and I use no database. In CakePHP Cookbook they write, that Controllers are only for communication between views and databases…
So should I build some own PHP files with own logic?
If yes, where should I put them?
The given Cake structure is a little bit confusing for me by now (I’m a absolute beginner in CakePHP).
templates/element/nav.php
<ul>
<li> <?= $this->Html->link(__('Click me to View Page 1'),'/pages/page1']) ?> </li> <!-- will load "templates/pages/page1.php"-->
<li> <?= $this->Html->link(__('Click me to View Page 2'),'/pages/page2']) ?> </li> <!-- will load "templates/pages/page2.php"-->
<li> <?= $this->Html->link(__('Click me to View Page 3'),'/pages/page3']) ?> </li> <!-- will load "templates/pages/page3.php"-->
<li> <?= $this->Html->link(__('Click me to View Page 4'),'/pages/page4']) ?> </li> <!-- will load "templates/pages/page4.php"-->
<li> <?= $this->Html->link(__('Click me to View Page 5'),'/pages/page5']) ?> </li> <!-- will load "templates/pages/page5.php"-->
</ul>
Great so I’m in the right way for sure - that’s a good feeling
Thank you so much, dirk!
One question again…
If we think about the patterns of Clean Code, is it not better to solve all title assignments for every page in it’s own function in one extra file and include it in /templates/Pages/home.php, /site_notice.php and so on?
I´m not sure, if i get the meaning of your question.
This:
should be at the beginning of each page in /templates/pages.
“Sitename” is to be replaced with the text you want to see in your brwoser tab.
There is nood need for one extra file.