Created
February 18, 2011 17:58
-
-
Save flavius/834090 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment