Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony]obiekt w pliku idnex.php
Mgorka
post
Post #1





Grupa: Zarejestrowani
Postów: 209
Pomógł: 3
Dołączył: 6.04.2010
Skąd: Słupca

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


Witajcie potrzebuję stworzyć obiekt który będzie generowany wpliku index oraz będę mógł się odwoływać do niego w komponencie od menu próbowałem metodą:
index.php
  1. <?php
  2.  
  3.  
  4. require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
  5.  
  6. $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
  7. sfContext::createInstance($configuration)->dispatch();
  8.  
  9. $aa='sss';
  10. //$aa[2]='aaa';
  11. //$aa[3]='555';
  12.  
  13. sfContext::getInstance()->set('blue',$aa);
  14. //sfContext::

w komponencie odwołuję się do obiektu tak
  1. $aa=sfContext::getInstance()->get('blue');

lecz symfony zwraca mi błąd że nie istnieje taki obiekt
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Sinevar
post
Post #2





Grupa: Zarejestrowani
Postów: 40
Pomógł: 13
Dołączył: 21.02.2008

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


Jeśli nazwałeś swoja aplikację dajmy na to frontend, to:

w apps/frontend/config/filters.yml

  1. rendering: ~
  2. security: ~
  3.  
  4. # insert your own filters here
  5. variables:
  6. class: variablesFilter
  7. enabled: on
  8. param:
  9. param1: something
  10.  
  11. cache: ~
  12. execution: ~


i tworzysz sobie klasę apps/frontend/lib/variablesFilter.php

  1. class variablesFilter extends sfFilter
  2. {
  3. public function execute($filterChain)
  4. {
  5. $param1 = $this->getParameter('param1');
  6. $this->getContext()->getUser()->setAttribute('blue', 'bleblu');
  7. $this->getContext()->getUser()->setAttribute('param1', $param1);
  8.  
  9. $filterChain->execute();
  10. }
  11. }


I teraz, jeśli jesteś w akcji/komponencie: $this->getUser()->getAttribute('blue'), a jeśli w templatce: $sf_user->getAttribute('blue'), a jeśli zaś w modelu: sfContext::getInstance()->getUser()->getAttribute('blue')

Jak coś, to to co wpiszesz do usera, możesz też wydumpować w $_SESSION (IMG:style_emoticons/default/wink.gif)

Ten post edytował Sinevar 28.04.2012, 22:55:44
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 4.10.2025 - 16:16