// controllers.php use Symfony\Component\HttpFoundation\Response; function list_action() { $posts = get_all_posts(); return new Response($html); } function show_action($id) { $post = get_post_by_id($id); return new Response($html); } // helper function to render templates { require $path; return $html; }
// index.php require_once 'vendor/autoload.php'; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $request = Request::createFromGlobals(); $uri = $request->getPathInfo(); if ('/' === $uri) { $response = list_action(); } elseif ('/show' === $uri && $request->query->has('id')) { $response = show_action($request->query->get('id')); } else { $html = '<html><body><h1>Page Not Found</h1></body></html>'; $response = new Response($html, Response::HTTP_NOT_FOUND); } // echo the headers and send the response $response->send();
Chodzi mi o zapis array('posts' => $posts) i array('post' => $post) Wg mojej logiki to jest zapisane błędnie wygląda to mi na tablice dwuwymiarową
byłbym wdzięczny gdyby ktoś mi wytłumaczył zasade działania funkcji render_template() i zastosowanie funkcji extract
