Guest User

Untitled

a guest
Jul 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Implementaţia o adăugăm în fişierul \texttt{functions.php}
  2. \begin{lstlisting}[numbers=none,title=functions.php]
  3. function build_menu_from_pages($pages) {
  4. $r = '<ul>';
  5. foreach($pages as $pagename => $metadata) {
  6. $r .= '<li><a href="?show='.$pagename.'">'.$metadata['title'].'</a></li>';
  7. }
  8. return $r.'</ul>';
  9. }
  10. \end{lstlisting}
  11.  
  12. Deoarece această funcţie generează cod HTML, apelul la ea trebuie să aibe loc în
  13. view logic, deci în cazul nostru în \texttt{layout.php}:
  14. \begin{lstlisting}
  15. echo build_menu_from_pages($pages);
  16. \end{lstlisting}
  17.  
  18. Variabila \texttt{\$pages} nu este injectată de către business logic în
  19. view logic, deci apelul la render va trebui modificat în mod corespunzător:
  20. \begin{lstlisting}
  21. render('layout.php', compact('pages', 'page'));
  22. \end{lstlisting}
  23. Deasemenea şi \texttt{layout.php} va avea nevoie de mici ajustări.
Add Comment
Please, Sign In to add comment