Results 1 to 2 of 2

Thread: Fatal error: Class 'Form_BugReport' not found

  1. #1
    danielgroves is offline Junior Member
    Join Date
    Jul 2012
    Posts
    1

    Default Fatal error: Class 'Form_BugReport' not found

    Hi,

    I've been working though the Apress book 'Pro Zend Framework Techniques'. I've hit a point where I am trying to render the form on a view.

    The form is called 'BugReport', which is located at 'forms/BugReportForm.php'; here is the contents of the file:

    Code:
    <?php
    
    class Form_BugReportForm extends Zend_Form
    {
    	public function init()
    	{
    		// add element: author textbox
    		$author = this->createElement('text', 'author');
    		$author->setLabel('Enter your name:');
    		$author->setRequired(TRUE);
    		$author->setAttrib('size', 30);
    		$this->addElement($author);
    		
    		// add element: email textbox
    		$email = $this->createElement('text', 'email');
    		$email->setLabel('Your email address:');
    		$email->setRequired(TRUE);
    		$email->addValidator(new Zend_Validate_EmailAddress());
    		$email->addFilters(array(
    			new Zend_Filter_StringTrim(),
    			new Zend_Filter_StringToLower()
    			));
    		$email = setAttrib('size', 40);
    		$this->addElement($email);
    		
    		// add element: date textbox
    		$date = $this->createElement('text', 'date');
    		$date->setLabel('Date the issue occurred (dd-mm-yyyy)');
    		$date->setRequired(TRUE);
    		$date->addValidator(new Zend_Validate_Date('MM-DD-YYYY'));
    		$date->setAttrib('size', 20);
    		$this->addElement($date);
    		
    		// add element: URL textbox
    		$url = $this->createElement('text', 'url');
    		$url->setLabel('Issue URL:');
    		$url->setRequired(TRUE);
    		$url->setAttrib('size', 50);
    		$this->addElement($url);
    		
    		// add element: description text area
    		$description = $this->createElement('textarea', 'description');
    		$description->setLabel('Issue description:');
    		$description->setRequired(TRUE);
    		$description->setAttrib('cols', 50);
    		$description->setAttrib('rows', 4);
    		$this->addElement($description);
    		
    		// add element: priority select box
    		$priority = $this->createElement('select', 'priority');
    		$priority->setLabel('Issue priority:');
    		$priority->setRequired(TRUE);
    		$priority->addMultiOptions(array(
    			'low'	=>	'Low',
    			'med'	=>	'Medium',
    			'high'	=>	'High'
    			));
    		$this->addElement($priority);
    		
    		// add element: status select box
    		$status = $this->createElement('select', 'status');
    		$status->setLabel('Current status:');
    		$status->setRequired(TRUE);
    		$status->addMultiOptions(array(
    			'new'			=>	'New',
    			'in_progress'	=>	'In Progress',
    			'resolved'		=>	'Resolved'
    			));
    		$this->addElement($status);
    		
    		// add element: submit button
    		$this->addElement('submit', 'submit', array('label' => 'Submit'));
    	}
    }
    This form in controlled via the 'BugController' controller located at '/controllers/BugController.php'

    Code:
    <?php
    
    class BugController extends Zend_Controller_Action
    {
    
        public function init()
        {
            /* Initialize action controller here */
        }
    
        public function indexAction()
        {
            // action body
        }
    
        public function createAction()
        {
            // action body
        }
    	
    	public function submitAction()
    	{
    		$frmBugReport = new Form_BugReport();
    		$frmBugReport->setAction('/bug/submit');
    		$frmBugReport->setMethod('post');
    		$this->view->form = $frmBugReport();
    	}
    
    }
    And finally I have the following autoloaders in my bootstrap.

    Code:
    protected function _initAutoload()
    	{
    		// Add autoloader empty namespace
    		$autoLoader = Zend_Loader_Autoloader::getInstance();
    		$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
    			'basePath'		=> APPLICATION_PATH,
    			'namespace'		=> '',
    			'resourceTypes'	=> array(
    				'form'	=> array(
    					'path'		=> 'forms/',
    					'namespace'	=> 'Form_',
    				)
    			),
    		));
    		
    		// Return it so it can be stored by the bootstrap
    		return $autoLoader;
    	}
    The error I am getting can be seen here: http://zend.danielgroves.net/bug/submit

    Or, if you'd rather just read it: Fatal error: Class 'Form_BugReport' not found in /home/www-data/zend.danielgroves.net/htdocs/application/controllers/BugController.php on line 23

    Any ideas on what I've done wrong, and so how this can be fixed?

    Thanks in advance,

    Dan.

  2. #2
    us2n4m2 is offline Junior Member
    Join Date
    Jul 2012
    Posts
    3

    Default

    Hello,

    "The form is called 'BugReport', which is located at 'forms/BugReportForm.php';"
    No ! Your form is not called 'BugReport' !
    Your form is called "BugReportForm" -> "class Form_BugReportForm extends Zend_Form . " located at 'forms/BugReportForm.php'

    Now:
    BugReportForm.php
    Rename: "class Form_BugReportForm extends Zend_Form"
    by: "class Application_Form_BugReportForm extends Zend_Form"

    - Found 2 syntax errors in your form script
    First:
    "$" is missing in this line: $author = this->createElement('text', 'author');
    Correction : $author = $this->createElement('text', 'author');

    Second:
    "->" is missing in this line: $email = setAttrib('size', 40);
    Correction : $email->setAttrib('size', 40);

    BugController.php
    Rename: $frmBugReport = new Form_BugReport();
    by: $frmBugReport = new Application_Form_BugReportForm();

    - Found 1 syntax error in your controller srcipt
    Rename: $this->view->form = $frmBugReport();
    by: $this->view->form = $frmBugReport;

    Bootstrap.php
    All the instructions in the _initAutoload() method are not really necessary, you can put under commment

    That's all.
    Last edited by us2n4m2; 11-11-2012 at 04:27 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •