Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Kohana]Headers Css
Forum PHP.pl > Forum > PHP > Frameworki
PiotrekM
Mam dziwny problem, gdyż nie mogę wysłać nagłówków.

  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. /**
  3.  * Everything is a page
  4.  * Everything inside is a module
  5.  */
  6.  
  7. class Controller_File extends Controller
  8. {
  9. const TEMPLATE_PATH = 'application/templates/';
  10. public function action_index()
  11. {
  12. //get path
  13. $template_file = ORM::factory('templatefile') -> where('name', '=', $this -> request -> param('name')) -> find();
  14.  
  15. $this->request->headers('Content-Type', 'text/css');
  16.  
  17. echo $template_file -> content;
  18. }
  19.  
  20. } // End Welcome


to mój controller... próbowałem też tradycyjnym sposobem i nic...
kod wypluwa w plain texcie

pierwszy raz się z czymś takim spotykam... może to wina nowej kohany 3.2?

edit: to wina kohany, bo w osobnym pliku jest ok. co zrobić?
skowron-line
Próbowałeś
  1. $this->request->send_headers();
PiotrekM
desperacko próbowałem, choć wiedziałem, że to tylko w KO3.0 a nie w 3.2
edit: wygląda to na BUG... zrobiłem tak: wysłałem header tradycyjnie tj. header('Content-type: text/css'); i nie wyechowałem kodu tylko umartwiłem smile.gif
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. /**
  3.  * Everything is a page
  4.  * Everything inside is a module
  5.  */
  6.  
  7. class Controller_File extends Controller
  8. {
  9. const TEMPLATE_PATH = 'application/templates/';
  10.  
  11. public function action_index()
  12. {
  13. //get path
  14. $template_file = ORM::factory('templatefile') -> where('name', '=', $this -> request -> param('name')) -> find();
  15.  
  16. header('Content-type: text/css');
  17. die($template_file -> content);
  18. }
  19.  
  20. } // End Welcome
skowron-line
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. /**
  3.  * Everything is a page
  4.  * Everything inside is a module
  5.  */
  6.  
  7. class Controller_File extends Controller
  8. {
  9. const TEMPLATE_PATH = 'application/templates/';
  10. public function action_index()
  11. {
  12. //get path
  13. $template_file = ORM::factory('templatefile') -> where('name', '=', $this -> request -> param('name')) -> find();
  14.  
  15. $this->response->headers('Content-Type', 'text/css');
  16.  
  17. echo $template_file -> content;
  18. }
  19.  
  20. } // End Welcome
tak powinno zadziałać działa
Kedan
Możesz też przez
  1. $template_file->render();


Ponieważ dziedziczysz po klasie Controller a nie po Controller_Template automatyczne renderowanie jest 'wyłączone' więc wszystkie widoki musisz wyświetlać ręcznie. W Controller_Template masz zmienną $auto_render domyślnie ustawioną na TRUE - jeśli w danej akcji nie jest Ci potrzebna to ustawiasz na false i tyle...
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.