Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Co to za tablica?
Forum PHP.pl > Forum > PHP
mylovelyengland
  1. // controllers.php
  2. use Symfony\Component\HttpFoundation\Response;
  3.  
  4. function list_action()
  5. {
  6. $posts = get_all_posts();
  7. $html = render_template('templates/list.php', array('posts' => $posts));
  8.  
  9. return new Response($html);
  10. }
  11.  
  12. function show_action($id)
  13. {
  14. $post = get_post_by_id($id);
  15. $html = render_template('templates/show.php', array('post' => $post));
  16.  
  17. return new Response($html);
  18. }
  19.  
  20. // helper function to render templates
  21. function render_template($path, array $args)
  22. {
  23. extract($args);
  24. require $path;
  25. $html = ob_get_clean();
  26.  
  27. return $html;
  28. }


  1. // index.php
  2. require_once 'vendor/autoload.php';
  3.  
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6.  
  7. $request = Request::createFromGlobals();
  8.  
  9. $uri = $request->getPathInfo();
  10. if ('/' === $uri) {
  11. $response = list_action();
  12. } elseif ('/show' === $uri && $request->query->has('id')) {
  13. $response = show_action($request->query->get('id'));
  14. } else {
  15. $html = '<html><body><h1>Page Not Found</h1></body></html>';
  16. $response = new Response($html, Response::HTTP_NOT_FOUND);
  17. }
  18.  
  19. // echo the headers and send the response
  20. $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 smile.gif
kpt_lucek
Przecież w jakiś sposób musisz przekazać zmienne do templatek?
Pyton_000
Masz błędną logikę.

Kod
array(array(1,2), array(2,3))


TO jest tablica 2 wymiarowa.
by_ikar
Zwyczajna tablica asocjacyjna http://www.tutorialspoint.com/php/php_arrays.htm
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.