Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

2 Stron V   1 2 >  
Reply to this topicStart new topic
> [ZendFramework]Brak formularza
PawelC
post 30.11.2010, 19:40:29
Post #1





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


Witam, mam taki problem, stworzyłem sobie formularz w ZF:
  1. ?php
  2. class Form_LoginForm extends Zend_Form
  3. {
  4. public function __construct($option = null)
  5. {
  6. parent::__construct($option);
  7. $form=new Zend_Form();
  8. $this->setName('login');
  9. $username=new Zend_Form_Element_Text('username');
  10. $username->setLabel('Username:')
  11. ->setRequired();
  12.  
  13. $password=new Zend_Form_Element_Password('password');
  14. $password->setLabel('Password:')
  15. ->setRequired(TRUE);
  16.  
  17. $login=new Zend_Form_Element_Submit('login');
  18. $login->setLabel('Login');
  19.  
  20. $this->addElements(array($username,$password,$login));
  21. $this->setMethod('post');
  22. $this->setAction('/autoryzacja/login');
  23.  
  24. }
  25. }


W kontrolerze robię tak:
  1. $form=new Form_LoginForm();
  2. $this->view->form=$form;

A w widoku echo $this->form;

Problem jest taki, że nie widać tego formularza sad.gif plik z formularzem, czyli LoginForm.php jest wgrany w folderze application/forms

Ktoś ma jakieś pomysły?
Go to the top of the page
+Quote Post
melkorm
post 30.11.2010, 19:51:59
Post #2





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


Nie w konstruktorze tylko w init();

Manual

czyli tak:

  1. class Form_LoginForm extends Zend_Form
  2. {
  3. public function init()
  4. {
  5.  
  6.  
  7. $this->setName('login');
  8. $username=new Zend_Form_Element_Text('username');
  9. $username->setLabel('Username:')
  10. ->setRequired();
  11.  
  12. $password=new Zend_Form_Element_Password('password');
  13. $password->setLabel('Password:')
  14. ->setRequired(TRUE);
  15.  
  16. $login=new Zend_Form_Element_Submit('login');
  17. $login->setLabel('Login');
  18.  
  19. $this->addElements(array($username,$password,$login));
  20. $this->setMethod('post');
  21. $this->setAction('/autoryzacja/login');
  22.  
  23. }
  24. }


Ten post edytował melkorm 30.11.2010, 19:55:17


--------------------
Go to the top of the page
+Quote Post
PawelC
post 30.11.2010, 20:13:24
Post #3





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


Ehh efekt ten sam sad.gif biała strona i nic więcej

Formularz mam tak jak napisałeś, w kontrolerze mam:
  1. <?php
  2. class HomeController extends Zend_Controller_Action
  3. {
  4. function init()
  5. {
  6.  
  7. }
  8.  
  9. function indexAction()
  10. {
  11.  
  12. }
  13.  
  14. function formAction()
  15. {
  16. $form=new Form_LoginForm();
  17. $this->view->form = $form;
  18.  
  19. }
  20.  
  21.  
  22. }

Plik LoginForm.php mam w katalogu application/forms/LoginForm.php
W application/views/scripts/home/ mam plik form.phtml, a w nim:
  1. <?
  2. echo $this->form;


I mimo to wszystko jest biała strona sad.gif
Go to the top of the page
+Quote Post
melkorm
post 30.11.2010, 20:15:40
Post #4





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


ThrowExceptions i DisplayExceptions w zendzie masz ustawione na ON?
Bo może jakimś błędem rzuca?


--------------------
Go to the top of the page
+Quote Post
PawelC
post 30.11.2010, 20:21:20
Post #5





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


W index.php mam $frontController->throwExceptions(true); ale nie pokazuje żadnych błędów
Go to the top of the page
+Quote Post
aart3k
post 30.11.2010, 20:42:08
Post #6





Grupa: Zarejestrowani
Postów: 72
Pomógł: 10
Dołączył: 2.02.2008
Skąd: Kraków

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


a short tagi na pewno Ci działają?
może wystarczy dać
  1. <?php echo $this->form
bo kod sam w sobie wydaje się ok
Go to the top of the page
+Quote Post
PawelC
post 30.11.2010, 20:58:28
Post #7





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


Tak sprawdzałem i chodzi wszystko ok.

Ustawiłem w kontrolerze home, i akcji form, takie coś $this->form->test="test";
i wywaliłem to:
  1. $form=new Form_LoginForm();
  2. $this->view->form = $form;
to wyświetla normalnie test, jak wstawie to, to jest biała strona

Ten post edytował ExPlOiT 30.11.2010, 21:08:59
Go to the top of the page
+Quote Post
melkorm
post 30.11.2010, 21:51:09
Post #8





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


Ubierz to w try catch i zmień nazwę na Form_Loginform (nazwe pliku / klasy itp).

I daj jeszcze var_dump'a na form'a.


--------------------
Go to the top of the page
+Quote Post
PawelC
post 30.11.2010, 22:31:42
Post #9





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


Nadal nic, biała strona, a dałem taki kod w kontrolerze:
  1. try{
  2. $form=new Form_Loginform();
  3. $this->view->form=$form;
  4. var_dump($form);
  5. }catch(Exception $e)
  6. {
  7. echo $e->getMessage();
  8. }
Dziwne jest to, że jak wpiszę nazwe kontrolera który nie istnieje, albo akcji z kontrolera której nie ma w nim, to pokazuje się tylko biała strona, nic więcej.
Go to the top of the page
+Quote Post
aart3k
post 1.12.2010, 12:45:09
Post #10





Grupa: Zarejestrowani
Postów: 72
Pomógł: 10
Dołączył: 2.02.2008
Skąd: Kraków

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


czyli raportowanie błędów leży
Go to the top of the page
+Quote Post
PawelC
post 1.12.2010, 12:50:59
Post #11





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


W wampserv jest właczone, w index.php Zenda jest $frontController->throwException(true); do tego jest error_reporting włączony i nic, biała strona.
Go to the top of the page
+Quote Post
luki100011
post 2.12.2010, 07:34:03
Post #12





Grupa: Zarejestrowani
Postów: 243
Pomógł: 20
Dołączył: 20.04.2004
Skąd: Wielkopolska

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


error reporting ? masz włączone w php.ini questionmark.gif
a najlepiej odpal działającą akcję i usuń w niej jakiś ; i powiedz czy zgłosi błąd czy też biała strona będzie ?

Ten post edytował luki100011 2.12.2010, 07:34:25


--------------------
Go to the top of the page
+Quote Post
PawelC
post 2.12.2010, 11:32:52
Post #13





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


Generalnie już pokazuje mi błędy. mam taki index.php
  1. <?
  2. set_include_path('.'.PATH_SEPARATOR.'library/'.PATH_SEPARATOR.'application/controllers/'.PATH_SEPARATOR.'application/models'.PATH_SEPARATOR.get_include_path());
  3.  
  4. require_once 'Zend/Application.php';
  5.  
  6. //Zend Loader
  7. include 'Zend/Loader.php';
  8.  
  9. //Wczytywanie klas
  10. Zend_Loader::loadClass('Zend_Controller_Front');
  11. Zend_Loader::loadClass('Zend_DB');
  12. Zend_Loader::loadClass('Zend_DB_Table');
  13. Zend_Loader::loadClass('Zend_Registry');
  14. Zend_Loader::loadClass('Zend_Config_Ini');
  15. Zend_Loader::loadClass('Zend_Layout');
  16.  
  17. Zend_Layout::startMvc('application/layouts',true);
  18.  
  19.  
  20. $config=new Zend_Config_Ini('application/config.ini','general');
  21. $registry=Zend_Registry::getInstance();
  22. $registry->set('config',$config);
  23. $db=Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
  24. Zend_Db_Table::getDefaultAdapter($db);
  25.  
  26. //Z tym formularze nie działają
  27. $frontController=Zend_Controller_Front::getInstance();
  28. $frontController->setControllerDirectory('application/controllers/');
  29. $frontController->throwExceptions(true);
  30. $frontController->dispatch();
  31.  
  32.  


I wywala mi błąd np Class Form_Login not found, a plik Login.php jest wgrany w application/forms
Go to the top of the page
+Quote Post
drakos
post 2.12.2010, 11:33:01
Post #14





Grupa: Zarejestrowani
Postów: 25
Pomógł: 1
Dołączył: 28.10.2010

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


W index.php APPLICATION_ENV na development // IMO pewniejsze i w jednym miejscu ustawiane

Masz wyłączony przedrostek "Application_" w application.ini i Bootstrapie?
Go to the top of the page
+Quote Post
PawelC
post 2.12.2010, 11:33:42
Post #15





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


Tak wyłączony

Ten post edytował ExPlOiT 2.12.2010, 11:35:52
Go to the top of the page
+Quote Post
R4D3K
post 3.12.2010, 03:00:09
Post #16





Grupa: Zarejestrowani
Postów: 144
Pomógł: 12
Dołączył: 16.03.2007

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


Obczaj swoją formę:
  1. $username->setLabel('Username:')
  2. ->setRequired();
  3. $password=new Zend_Form_Element_Password('password');
  4. $password->setLabel('Password:')
  5. ->setRequired(TRUE)


Może wymaganie labela (raczej ciężko wymagać go od usera) powoduje takie dziwne zachowanie i jakiego ZF używasz questionmark.gif
I po drugie nie ->setRequired(); tylko ->setRequired(TRUE)

Go to the top of the page
+Quote Post
PawelC
post 3.12.2010, 09:11:40
Post #17





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


Używam ZF 1.11

Takie same problemy mam, nawet jak całkiem usunę to setRequired, i nawet jak do tego dodam true.
Go to the top of the page
+Quote Post
R4D3K
post 3.12.2010, 11:44:32
Post #18





Grupa: Zarejestrowani
Postów: 144
Pomógł: 12
Dołączył: 16.03.2007

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


Spróbuj tak może:
  1. Zend_debug::dump($form);


I zobacz co się wyświetla
Go to the top of the page
+Quote Post
melkorm
post 3.12.2010, 12:55:34
Post #19





Grupa: Zarejestrowani
Postów: 1 366
Pomógł: 261
Dołączył: 23.09.2008
Skąd: Bydgoszcz

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


Cytat
Może wymaganie labela (raczej ciężko wymagać go od usera) powoduje takie dziwne zachowanie i jakiego ZF używasz
I po drugie nie ->setRequired(); tylko ->setRequired(TRUE)


1. jakie wymaganie labela? On ustawia required na element (setLabel zwraca element formularza).
2. setRequired ma default TRUE, więc nie trzeba się powtarzać .

P.S. nadal masz błąd że formularz nieznaleziony?
P.S.2 Czy używasz podziału na moduły?


--------------------
Go to the top of the page
+Quote Post
PawelC
post 3.12.2010, 14:13:36
Post #20





Grupa: Zarejestrowani
Postów: 1 173
Pomógł: 121
Dołączył: 24.09.2007
Skąd: Toruń

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


  1.  
  2. <?
  3. set_include_path('.'.PATH_SEPARATOR.'library/'.PATH_SEPARATOR.'application/controllers/'.PATH_SEPARATOR.'application/models'.PATH_SEPARATOR.get_include_path());
  4.  
  5. require_once 'Zend/Application.php';
  6.  
  7. //Zend Loader
  8. include 'Zend/Loader.php';
  9.  
  10. //Wczytywanie klas
  11. Zend_Loader::loadClass('Zend_Controller_Front');
  12. Zend_Loader::loadClass('Zend_DB');
  13. Zend_Loader::loadClass('Zend_DB_Table');
  14. Zend_Loader::loadClass('Zend_Registry');
  15. Zend_Loader::loadClass('Zend_Config_Ini');
  16. Zend_Loader::loadClass('Zend_Layout');
  17.  
  18. Zend_Layout::startMvc('application/layouts',true);
  19.  
  20.  
  21. $config=new Zend_Config_Ini('application/config.ini','general');
  22. $registry=Zend_Registry::getInstance();
  23. $registry->set('config',$config);
  24. $db=Zend_Db::factory($config->db->adapter, $config->db->config->toArray());
  25. Zend_Db_Table::getDefaultAdapter($db);
  26.  
  27. //Z tym formularze nie działają
  28. c
  29.  
  30. //Z tym chodzą bez problemu
  31. $application = new Zend_Application(
  32. APPLICATION_ENV,
  33. APPLICATION_PATH . '/configs/application.ini'
  34. );
  35. $application->bootstrap()
  36. ->run();


jak dam w index.php to:
  1. $frontController=Zend_Controller_Front::getInstance();
  2. $frontController->setControllerDirectory('application/controllers/');
  3. $frontController->throwExceptions(true);
  4. $frontController->dispatch();

To formularze nie działają mi, pokazuje że nie znaleziono. Jak zamiast tego, dam to:
  1. $application = new Zend_Application(
  2. APPLICATION_ENV,
  3. APPLICATION_PATH . '/configs/application.ini'
  4. );
  5. $application->bootstrap()
  6. ->run();
to wszystko działa elegancko.

Nie mam podziału na moduły.
Go to the top of the page
+Quote Post

2 Stron V   1 2 >
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: 25.04.2024 - 15:20