0

In my Zend Framework project I have the forms folder in which I have a form

class Application_Forms_Loginextends Zend_Form { public function init() { $this->setMethod('post'); $username = $this->createElement('text', 'username'); $username->setLabel('Username')->setAttrib('maxLength', 75); $password = $this->createElement('password', 'password'); $password->setLabel('password:')->setAttrib('maxLength', 75); $signin = $this->createElement('submit', 'signin'); $signin->setLabel("sign in")->setIgnore(true); $this->addElements(array( $username, $password, $signin )); } 

}

I use this class in a UserController, but this error appears

Fatal error: Class 'LoginForm' not found in 

edit:

 public function loginAction() { $users = new Application_Model_Users(); $form = new Application_Forms_Login(); $this->view->form = $form; } 

Now I am getting this error

Warning: include_once(Application/Forms/Login.php): failed to open stream: No such file or directory in /home/myFolder/public_html/library/Zend/Loader.php 

edit: added project structure

project structure

3
  • Show your controller code where you creating your form object. Commented Jan 22, 2014 at 9:20
  • you are using it wrong, see my answer, hope it clarifies it. Commented Jan 22, 2014 at 9:28
  • Please show your config.ini file. Commented Jan 22, 2014 at 13:34

4 Answers 4

1

your error says it all you said you have forms folders but you are using class of LoginForm

assuming you are using zf1,

and your forms folder is under application,

you should use it like this,

class Application_Forms_LoginFrom extends Zend_Form 

it can very according to your folders name.

also change the call in controller as

 $form = new Application_Forms_LoginForm(); 

it should be as per your folder name whether you use Application_form or Application_Forms.

ah i see, now you are using ,

class Application_Forms_Loginextends Zend_Form 

may be there is typo and you forgot the space between login and extends,

try this,

 class Application_Form_Login extends Zend_Form 
Sign up to request clarification or add additional context in comments.

6 Comments

I did this, but now i get this error Warning: include_once(Application/Forms/LoginForm.php): failed to open stream: No such file or directory in /home/alexandru.luca/public_html/library/Zend/Loader.php
do you have directory named Forms ?? or Form ? under application directory
forms... It works now but I get a different error now, I updated the post
I user Application_Forms_Login extends Zend_Form and I call it like $form = new Application_Forms_Login); The problem is this Warning: include_once(Application/Forms/Login.php): failed to open stream: No such file or directory in /home/myFolder/public_html/library/Zend/Loader.php
yes, remove the s from Application_Forms, and try Application_Form
|
0

class Application_Forms_Loginextends Zend_Form it should be class Application_Form_Login extends Zend_Form

1 Comment

can you please be more specific? i'm new to Zend
0

It should be :

class Application_Form_Login extends Zend_Form { public function init() { $this->setMethod('post'); $username = $this->createElement('text', 'username'); $username->setLabel('Username')->setAttrib('maxLength', 75); $password = $this->createElement('password', 'password'); $password->setLabel('password:')->setAttrib('maxLength', 75); $signin = $this->createElement('submit', 'signin'); $signin->setLabel("sign in")->setIgnore(true); $this->addElements(array( $username, $password, $signin )); } 

and in your controller action :

$form = new Application_Form_Login(); 

If error persist check your application.ini for appnamespace = "Application"

Comments

0

In Zend Framework, the default appnamespace config value is Application.

Name your class Application_Form_Login instead of Application_Forms_Login and it will work with no issue.

class Application_Form_Login extends Zend_Form { public function init() { $this->setMethod('post'); $username = $this->createElement('text', 'username'); $username->setLabel('Username')->setAttrib('maxLength', 75); $password = $this->createElement('password', 'password'); $password->setLabel('password:')->setAttrib('maxLength', 75); $signin = $this->createElement('submit', 'signin'); $signin->setLabel("sign in")->setIgnore(true); $this->addElements(array( $username, $password, $signin )); } 

Hope it helps

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.