Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][Symfony]Problem z sf_params
lobopol
post
Post #1





Grupa: Zarejestrowani
Postów: 1 729
Pomógł: 346
Dołączył: 4.04.2009

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


Właśnie przerabiam sobie kurs i pojawił mi się niestety problem. Według książki użycie
  1. echo $sf_params->get('name', 'anonim')

Powinno wyświetlić anonim gdy wartość name nie jest ustalona, ale niestety tak się nie dzieje, ba gdy przesyłam wartość dla name powinna ona się wyświetlić, ale niestety nie idzie.
Oczywiści:
  1. echo $sf_params->get('name')

wyświetla dobrze wartość name jeżeli jest przesłane bądź nic jak nie jest wysłane.

  1. public function executeUpdate($request)
  2. {
  3. $this->name = $request->getParameter('name');
  4. }

template updateSuccess:
  1. <p>Cześć, <?php echo $sf_params->get('name', 'Anonim') ?>!</p>
  2. <?php echo $sf_params->get('name') ?>


template showSuccess
  1. <?php if ($hour >= 18): ?>
  2. <p>A może raczej dobry wieczór? W końcu jest <?php echo $hour ?>.</p>
  3. <?php endif; ?>
  4. <form method="post" action="<?php echo url_for('content/update') ?>">
  5. <label for="name">Jak się nazywasz</label>
  6. <input type="text" name="name" id="name" value="" />
  7. <input type="submit" value="Ok"/>
  8. <?php echo link_to('Nie powiem', 'content/update?name=anonim',
  9. 'class' => 'special_link',
  10. 'confirm' => 'jesteś pewien?',
  11. 'absolute' => 'true'
  12. )) ?>
  13.  
  14. </form>
  15.  


--------------------
Go to the top of the page
+Quote Post
Silny
post
Post #2





Grupa: Zarejestrowani
Postów: 117
Pomógł: 2
Dołączył: 29.06.2010

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


Tak ogólnie, to powinieneś używać jakiegoś systemu szablonów, bo niezbyt wygląda php html winksmiley.jpg
Go to the top of the page
+Quote Post
lobopol
post
Post #3





Grupa: Zarejestrowani
Postów: 1 729
Pomógł: 346
Dołączył: 4.04.2009

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


Na razie jestem na etapie kursu, później nad szablonem pomyślę.


--------------------
Go to the top of the page
+Quote Post
Silny
post
Post #4





Grupa: Zarejestrowani
Postów: 117
Pomógł: 2
Dołączył: 29.06.2010

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


pokaz cały kod, bo ja zrobiłem normalnie
  1. <p>Siemka, <?php echo $sf_params->get('name', 'Gościu z Archiwum X') ?>!</p>
pyka mi piknie winksmiley.jpg
Go to the top of the page
+Quote Post
lobopol
post
Post #5





Grupa: Zarejestrowani
Postów: 1 729
Pomógł: 346
Dołączył: 4.04.2009

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


No nie ma co więcej pokazywać moduł content:
action.class.php
  1. class contentActions extends sfActions
  2. {
  3. public function executeShow()
  4. {
  5. $today = getdate();
  6. $this->hour = $today['hours'];
  7. }
  8. public function executeUpdate($request)
  9. {
  10. $this->name = $request->getParameter('name');
  11. }

templatka showSuccess.php
  1. <?php if ($hour >= 18): ?>
  2. <p>Dobry wieczór? W końcu jest <?php echo $hour ?>.</p>
  3. <?php endif; ?>
  4. <form method="post" action="<?php echo url_for('content/update') ?>">
  5. <label for="name">Jak się nazywasz</label>
  6. <input type="text" name="name" id="name" value="" />
  7. <input type="submit" value="Ok"/>
  8. <?php echo link_to('Nie powiem', 'content/update?name=anonymous',
  9. 'class' => 'special_link',
  10. 'confirm' => 'jesteś pewien?',
  11. 'absolute' => 'true'
  12. )) ?>
  13.  
  14. </form>

templatka updateSuccess.php
  1. <p>Cześć, <?php echo $sf_params->get('name', 'test') ?>!</p>


Jak wchodzę w trybie debugowania wyrzuca błąd:
Kod
Call to undefined method contentActions::getParameter.
    * at ()
      in SF_ROOT_DIR\lib\vendor\symfony\lib\action\sfComponent.class.php line 373 ...
             370.     $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'component.method_not_found', array('method' => $method, 'arguments' => $arguments)));
             371.     if (!$event->isProcessed())
             372.     {
             373.       throw new sfException(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
             374.     }
             375.
             376.     return $event->getReturnValue();

całość na:
http://www.wklejto.pl/72610


--------------------
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 Aktualny czas: 21.08.2025 - 16:05