Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Implementaţia o adăugăm în fişierul \texttt{functions.php}
- \begin{lstlisting}[numbers=none,title=functions.php]
- function build_menu_from_pages($pages) {
- $r = '<ul>';
- foreach($pages as $pagename => $metadata) {
- $r .= '<li><a href="?show='.$pagename.'">'.$metadata['title'].'</a></li>';
- }
- return $r.'</ul>';
- }
- \end{lstlisting}
- Deoarece această funcţie generează cod HTML, apelul la ea trebuie să aibe loc în
- view logic, deci în cazul nostru în \texttt{layout.php}:
- \begin{lstlisting}
- echo build_menu_from_pages($pages);
- \end{lstlisting}
- Variabila \texttt{\$pages} nu este injectată de către business logic în
- view logic, deci apelul la render va trebui modificat în mod corespunzător:
- \begin{lstlisting}
- render('layout.php', compact('pages', 'page'));
- \end{lstlisting}
- Deasemenea şi \texttt{layout.php} va avea nevoie de mici ajustări.
Add Comment
Please, Sign In to add comment