Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Co to za tablica?
mylovelyengland
post 28.05.2016, 09:18:32
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 19.10.2015

Ostrzeżenie: (0%)
-----


  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
Go to the top of the page
+Quote Post
kpt_lucek
post 28.05.2016, 09:40:34
Post #2





Grupa: Zarejestrowani
Postów: 428
Pomógł: 77
Dołączył: 10.07.2011
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Przecież w jakiś sposób musisz przekazać zmienne do templatek?


--------------------


Cytat
There is a Bundle for that
Lukas Kahwe Smith - October 31th, 2014
Go to the top of the page
+Quote Post
Pyton_000
post 28.05.2016, 09:52:16
Post #3





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

Ostrzeżenie: (0%)
-----


Masz błędną logikę.

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


TO jest tablica 2 wymiarowa.
Go to the top of the page
+Quote Post
by_ikar
post 28.05.2016, 10:14:55
Post #4





Grupa: Zarejestrowani
Postów: 1 798
Pomógł: 307
Dołączył: 13.05.2009
Skąd: Gubin/Wrocław

Ostrzeżenie: (0%)
-----


Zwyczajna tablica asocjacyjna http://www.tutorialspoint.com/php/php_arrays.htm
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 09:25