Skip to content

Instantly share code, notes, and snippets.

@flavius
Created February 18, 2011 17:58
Show Gist options
  • Save flavius/834090 to your computer and use it in GitHub Desktop.
Save flavius/834090 to your computer and use it in GitHub Desktop.
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