Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZendFramework] Form, Nie pokazuje sie formularz
phpsuse
post
Post #1





Grupa: Zarejestrowani
Postów: 59
Pomógł: 0
Dołączył: 22.06.2008

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


Witam,
Zgodnie z wcześniejszymi zaleceniami wstawiłem w odpowiednie miejsce kod formularza niestety w widoku nic się nie pokazuje

AuthControler:
  1. <?php
  2. public function getForm()
  3.    {
  4.        $form = new Zend_Form();
  5.        $form->setAction('/Auth/login')
  6.            ->setMethod('post');
  7.        
  8.        $username = $form->createElement('text', 'username');
  9.        $username->addValidator('alnum')
  10.                ->addValidator('regex', false, array('/^[a-z]+/'))
  11.                ->addValidator('stringLength', false, array(6, 20))
  12.                ->setRequired(true)
  13.                ->addFilter('StringToLower');
  14.        
  15.        $password = $form->createElement('password', 'password');
  16.        $password->addValidator('StringLength', false, array(6))
  17.                ->setRequired(true);
  18.        
  19.        $form->addElement($username)
  20.            ->addElement($password)
  21.            ->addElement('submit', 'login', array('label' => 'Login'));
  22.    return $form;
  23.    }
  24.  
  25.  
  26.  
  27. public function init()
  28.    {
  29.        $this->view->login = $this->getForm();
  30.        $this->render('login');
  31.        $this->initView();
  32.        $this->view->baseUrl = $this->_request->getBaseUrl();
  33.    }
  34. ?>


teraz w widoku /Auth/login.phtml jak wstawie coś takiego to mam komunikat:
Fatal error: Call to a member function render() on a non-object in C:\xampp\htdocs\ims\application\views\scripts\Auth\login.phtml on line 2

  1. <?php echo $form->render($view); ?>


jak zrobie:
  1. <?php
  2. echo $this->form
  3. ?>

to nie ma nic



te przykłady na stronie ZendFramewoka są tak dobrane że ciezko sie połapać co do czego. Czemu używając Zend_Form pliki tez ponazywali form. Jak to początkujący ma rozróżnić.

Prosze o pomoc w moim temecie

Przemek
Go to the top of the page
+Quote Post
-=Peter=-
post
Post #2





Grupa: Zarejestrowani
Postów: 304
Pomógł: 51
Dołączył: 4.02.2005
Skąd: Kraków

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


Formularz podstawiłeś do zmiennej login a nie form, więc go tak wyświetlasz:

  1. <?php
  2. echo $this->login
  3. ?>


Oczywiście jeśli w chcesz go wyświetlić z wysokości widoku. Jeśli chcesz go wyświetlić z wysokości akcji to masz dostęp do niego za pomocą

  1. <?php
  2. $this->view->login
  3. ?>


Ten post edytował -=Peter=- 15.07.2009, 10:38:30


--------------------
Go to the top of the page
+Quote Post
phpsuse
post
Post #3





Grupa: Zarejestrowani
Postów: 59
Pomógł: 0
Dołączył: 22.06.2008

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


Cytat(-=Peter=- @ 15.07.2009, 11:36:58 ) *
Formularz podstawiłeś do zmiennej login a nie form, więc go tak wyświetlasz:

  1. <?php
  2. echo $this->login
  3. ?>


Pokazuje mi błąd:

Catchable fatal error: Method Zend_Form::__toString() must return a string value in C:\xampp\htdocs\ims\application\views\scripts\Auth\login.phtml on line 2
Go to the top of the page
+Quote Post
-=Peter=-
post
Post #4





Grupa: Zarejestrowani
Postów: 304
Pomógł: 51
Dołączył: 4.02.2005
Skąd: Kraków

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


to pozostaje
  1. <?php
  2. echo $this->login->render($widok);
  3. ?>


--------------------
Go to the top of the page
+Quote Post
phpsuse
post
Post #5





Grupa: Zarejestrowani
Postów: 59
Pomógł: 0
Dołączył: 22.06.2008

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


Cytat(-=Peter=- @ 15.07.2009, 11:41:26 ) *
to pozostaje
  1. <?php
  2. echo $this->login->render($widok);
  3. ?>


Nic nie pokazuje. Pusto !
Go to the top of the page
+Quote Post
nexis
post
Post #6





Grupa: Zarejestrowani
Postów: 1 012
Pomógł: 109
Dołączył: 26.09.2003
Skąd: nexis.pl

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


controllers/AuthController.php
  1. <?php
  2. class AuthController extends Zend_Controller_Action
  3. {
  4.    public function getForm()
  5.    {
  6.        $form = new Zend_Form();
  7.        $form->setMethod('post');
  8.        
  9.        $username = $form->createElement('text', 'username');
  10.        $username->addValidator('alnum')
  11.                 ->addValidator('regex', false, array('/^[a-z]+/'))
  12.                 ->addValidator('stringLength', false, array(6, 20))
  13.                 ->setRequired(true)
  14.                 ->addFilter('StringToLower');
  15.        
  16.        $password = $form->createElement('password', 'password');
  17.        $password->addValidator('StringLength', false, array(6))
  18.                 ->setRequired(true);
  19.        
  20.        $form->addElement($username)
  21.             ->addElement($password)
  22.             ->addElement('submit', 'login', array('label' => 'Login'));
  23.        return $form;
  24.    }
  25.    
  26.    public function loginAction()
  27.    {
  28.        $this->view->form = $this->getForm();
  29.    }
  30. }
  31. ?>


views/scripts/auth/login.phtml
  1. <?php echo $this->form; ?>


Ten post edytował nexis 15.07.2009, 10:48:12


--------------------
Zend Certified Engineer

Kliknij POMÓGŁ jeśli moja odpowiedź okazała się użyteczna!
Go to the top of the page
+Quote Post
phpsuse
post
Post #7





Grupa: Zarejestrowani
Postów: 59
Pomógł: 0
Dołączył: 22.06.2008

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


miałem tą linie w inice
jak z ini-ta uzunołem i wstawiłem do loginAction to mam błąd:


Catchable fatal error: Method Zend_Form::__toString() must return a string value in C:\xampp\htdocs\ims\application\views\scripts\Auth\login.phtml on line 2

Żywcem wstawiony przykład ze strony:
http://framework.zend.com/manual/en/zend.f...ickstart.render
punkt: 23.2.6. Putting it together


AuthControler.php
  1. <?php
  2.  
  3. class AuthController extends Zend_Controller_Action
  4. {
  5.    public function getForm()
  6.    {
  7.       $form = new Zend_Form();
  8.        $form->setAction('/Auth/login')
  9.             ->setMethod('post');
  10.        
  11.        // Create and configure username element:
  12.        $username = $form->createElement('text', 'username');
  13.        $username->addValidator('alnum')
  14.                 ->addValidator('regex', false, array('/^[a-z]+/'))
  15.                 ->addValidator('stringLength', false, array(6, 20))
  16.                 ->setRequired(true)
  17.                 ->addFilter('StringToLower');
  18.        
  19.        // Create and configure password element:
  20.        $password = $form->createElement('password', 'password');
  21.        $password->addValidator('StringLength', false, array(6))
  22.                 ->setRequired(true);
  23.        
  24.        // Add elements to form:
  25.        $form->addElement($username)
  26.             ->addElement($password)
  27.             // use addElement() as a factory to create 'Login' button:
  28.             ->addElement('submit', 'login', array('label' => 'Login'));
  29.        return $form;
  30.    }
  31.  
  32.    public function indexAction()
  33.    {
  34.        // render user/form.phtml
  35.        $this->view->form = $this->getForm();
  36.        $this->render('login');
  37.    }
  38.  
  39.    public function loginAction()
  40.    {
  41.        if (!$this->getRequest()->isPost()) {
  42.            return $this->_forward('index');
  43.        }
  44.        $form = $this->getForm();
  45.        if (!$form->isValid($_POST)) {
  46.            // Failed validation; redisplay form
  47.            $this->view->form = $form;
  48.            return $this->render('form');
  49.        }
  50.  
  51.        $values = $form->getValues();
  52.        // now try and authenticate....
  53.    }
  54.    
  55. }
  56. ?>


login.phtml
  1. <h2>Please login:</h2>
  2. <?php echo $this->form ?>


Wynik działania:
Please login:

Catchable fatal error: Method Zend_Form::__toString() must return a string value in C:\xampp\htdocs\ims\application\views\scripts\Auth\login.phtml on line 2


O co to może chodzić. Żywcem wstawiony przykład.
Go to the top of the page
+Quote Post
fander
post
Post #8





Grupa: Zarejestrowani
Postów: 231
Pomógł: 22
Dołączył: 6.10.2008

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


W kontrolerze
Kod
   public function loginAction()
    {
        $this->view->form = $this->getForm()->render();
    }


W widoku:
Kod
       echo $this->form;
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 - 07:42