Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZF] formsy i fatal error :|
Forum PHP.pl > Forum > PHP > Frameworki
matchor
Fatal error: Class 'forms_ContactForm' not found in /xxx/application/controllers/RegisterController.php on line 38
mam takie pliki w takich lokalizacjach
  1. /xxx/application/forms/ContactForm
  2. /xxx/public/index.php
  3. /xxx/controllers/RegisterController.php


=============================
/xxx/application/forms/ContactForm
  1. <?php
  2.  
  3. class forms_ContactForm extends Zend_Form
  4. {
  5. public function __construct($options = null)
  6. {
  7. parent::__construct($options);
  8. $this->setName('contact_us');
  9.  
  10. $title = new Zend_Form_Element_Select('title');
  11. $title->setLabel('Title')
  12. ->setMultiOptions(array('mr'=>'Mr', 'mrs'=>'Mrs'))
  13. ->setRequired(true)->addValidator('NotEmpty', true);
  14.  
  15. $firstName = new Zend_Form_Element_Text('firstName');
  16. $firstName->setLabel('First name')
  17. ->setRequired(true)
  18. ->addValidator('NotEmpty');
  19.  
  20. $lastName = new Zend_Form_Element_Text('lastName');
  21. $lastName->setLabel('Last name')
  22. ->setRequired(true)
  23. ->addValidator('NotEmpty');
  24.  
  25. $email = new Zend_Form_Element_Text('email');
  26. $email->setLabel('Email address')
  27. ->addFilter('StringToLower')
  28. ->setRequired(true)
  29. ->addValidator('NotEmpty', true)
  30. ->addValidator('EmailAddress');
  31.  
  32.  
  33. $submit = new Zend_Form_Element_Submit('submit');
  34. $submit->setLabel('Contact us');
  35.  
  36. $this->addElements(array($title, $firstName,
  37. $lastName, $email, $submit));
  38.  
  39. }
  40. }



=============================
/xxx/controllers/RegisterController.php
  1. public function indexAction()
  2. {
  3.  
  4. $form = new forms_ContactForm(); // <========= tu sie wykrzacza



=============================

/xxx/public/index.php :

  1. <?php
  2. // Set the initial include_path. You may need to change this to ensure that
  3. // Zend Framework is in the include_path; additionally, for performance
  4. // reasons, it's best to move this to your web server configuration or php.ini
  5. // for production.
  6. set_include_path(implode(PATH_SEPARATOR, array(
  7. realpath(dirname(__FILE__) . '/../library'),
  8. )));
  9.  
  10. // Define path to application directory
  11. defined('APPLICATION_PATH')
  12. || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
  13.  
  14. // Define application environment
  15. defined('APPLICATION_ENV')
  16. || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
  17.  
  18. /** Zend_Application */
  19. require_once 'Zend/Application.php';
  20.  
  21. // Create application, bootstrap, and run
  22. $application = new Zend_Application(
  23. APPLICATION_ENV,
  24. APPLICATION_PATH . '/configs/application.ini'
  25. );
  26. $application->bootstrap();
  27. $application->run();
nospor
zgodnie z dokumentacją zenda i ich autoloadera:

nie: /xxx/application/forms/ContactForm
a: /xxx/application/forms/Contact.php

nie: class forms_ContactForm extends Zend_Form
a: class Form_Contact extends Zend_Form

nie: $form = new forms_ContactForm();
a: $form = new Form_Contact();
matchor
zrobilem jak piszesz ale nie pomoglo:

  1. Fatal error: Class 'Form_Contact' not found in /xxx/application/controllers/RegisterController.php on line 38
nospor
Napewno zastosowałeś się do wszystkich trzech rzeczy? Pokaż teraz wszystko jak u Ciebie wygląda: struktura plikow, nazwa pliku i zawartosc i wywołanie
nospor
kurcze.........................................
przeciez WYRAŹNIE napisałem:
class Form_Contact extends Zend_Form
matchor
i tak jest w

Contact.php:
  1.  
  2. class Form_Contact extends Zend_Form
  3. {
  4. public function __construct($options = null)
  5. {
  6. parent::__construct($options);
  7. $this->setName('contact_us');
  8.  
  9. $title = new Zend_Form_Element_Select('title');
  10. $title->setLabel('Title')
  11. ->setMultiOptions(array('mr'=>'Mr', 'mrs'=>'Mrs'))
  12. ->setRequired(true)->addValidator('NotEmpty', true);
  13.  
  14. $firstName = new Zend_Form_Element_Text('firstName');
  15. $firstName->setLabel('First name')
  16. ->setRequired(true)
  17. ->addValidator('NotEmpty');
  18.  
  19. $lastName = new Zend_Form_Element_Text('lastName');
  20. $lastName->setLabel('Last name')
  21. ->setRequired(true)
  22. ->addValidator('NotEmpty');
  23.  
  24. $email = new Zend_Form_Element_Text('email');
  25. $email->setLabel('Email address')
  26. ->addFilter('StringToLower')
  27. ->setRequired(true)
  28. ->addValidator('NotEmpty', true)
  29. ->addValidator('EmailAddress');
  30.  
  31.  
  32. $submit = new Zend_Form_Element_Submit('submit');
  33. $submit->setLabel('Contact us');
  34.  
  35. $this->addElements(array($title, $firstName,
  36. $lastName, $email, $submit));
  37.  
  38. }
  39. }
  40.  

nospor
Cytat
i tak jest w
tja... tylko ze w poprzednim poscie, który notabene już edytowałeś, napisałes:
class Form_ContactForm extends Zend_Form

stąd moje podirytowanie smile.gif

Wiec dziala już? A jak nie działa to napewno masz dokładnie tak jak teraz podajesz?
matchor
edytowalem bo wkleilem zle;)

tak jest dokladnie to co mam na serwerze i wciaz mam

  1. Fatal error: Class 'Form_Contact' not found in /xxx/application/controllers/RegisterController.php on line 38


nie wiem za bardzo co jest problem jzu kombinowalem roznie - obstawialem ze moze sciezki w index.php :|
nospor
to spróbuj jeszcze ustawić autoloadera:
http://framework.zend.com/manual/en/zend.l...r-resource.html

choć domyślnie tam jest napisane, że ten autoloader dla formsów jest ustawiony.
matchor
w Bootstrap mialem juz ustawionego Autoloadera

  1. protected function _initAutoload()
  2. {
  3. $autoloader = new Zend_Application_Module_Autoloader(array(
  4. 'namespace' => 'Default',
  5. 'basePath' => dirname(__FILE__),
  6. ));
  7. return $autoloader;
  8. }


klase musialem zdeklarowac

class Default_Form_Contact extend ...

  1. $form = new Default_Form_Contact();
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.