SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ZEND: Error: Class 'forms_ContactForm' not found (new to Zend)

    Hello

    I am just starting Zend (my first project where Im trying to pull all the pieces together and make a test functional site) and have a MVC structure setup and bootstrapped successfully. I have Zend Layout working and have a simple layout going. I am now trying to take the Zend Form example from akrabat.com and incorporate it into my dev site.

    I am getting this error:
    Warning: include(forms\ContactForm.php) [function.include]: failed to open stream: No such file or directory in C:\xampp\php\PEAR\Zend\Loader.php on line 83

    Warning: include() [function.include]: Failed opening 'forms\ContactForm.php' for inclusion (include_path='.;.;C:\xampp\php\PEAR;../library;../application/classes/;../application/models/') in C:\xampp\php\PEAR\Zend\Loader.php on line 83

    Fatal error: Class 'forms_ContactForm' not found in C:\xampp\htdocs\zendproject\application\controllers\ContactController.php on line 10
    Here is my structure:
    application
    ----controllers
    --------ContactController.php
    ----forms
    --------ContactForm.php
    ----views
    --------scripts
    ------------contact
    ----------------index.phtml
    html
    library

    my index/bootstrap file
    PHP Code:
    <?php 
    set_include_path
    ('.' 
                        
    PATH_SEPARATOR get_include_path()
                        . 
    PATH_SEPARATOR '../library'
                        
    PATH_SEPARATOR '../application/classes/'
                        
    PATH_SEPARATOR '../application/models/'    
                                                              

                        
    );
                                                                
    require_once 
    'Zend/Controller/Front.php';

    include_once(
    'Zend/Loader/Autoloader.php');
    $loader Zend_Loader_Autoloader::getInstance();
    $loader->setFallbackAutoloader(true);
    $loader->suppressNotFoundWarnings(false);

    $options = array(
        
    'layout' => 'layout',
        
    'layoutContent' => '../application/views/layouts/',
        
    'contentKey' => 'content'    );

    new 
    DbInitialize();
    Zend_Layout::startMvc($option);


    /**
     * Setup controller
     */
    $controller Zend_Controller_Front::getInstance();
    $controller->setControllerDirectory('../application/controllers');
    $controller->throwExceptions(false); // should be turned on in development time 

    // run!
    $controller->dispatch();
    ContactController.php
    PHP Code:
    <?php

    class ContactController extends Zend_Controller_Action
    {
        function 
    indexAction()
        {
            
    $this->view->pageTitle "Zend_Form Example";
            
    $this->view->bodyCopy "<p>Please fill out this form.</p>";

            
    $form = new forms_ContactForm();

            if (
    $this->_request->isPost()) {
                
    $formData $this->_request->getPost();
                if (
    $form->isValid($formData)) {
                    echo 
    'success';
                    exit;
                } else {
                    
    $form->populate($formData);
                }
            }

            
    $this->view->form $form;
        }
        
        
    }
    ContactForm.php
    PHP Code:
    <?php

    class forms_ContactForm extends Zend_Form 

        public function 
    __construct($options null
        { 
            
    parent::__construct($options);
            
    $this->setName('contact_us');
            
            
    $title = new Zend_Form_Element_Select('title');
            
    $title->setLabel('Title')
                  ->
    setMultiOptions(array('mr'=>'Mr''mrs'=>'Mrs'))
                  ->
    setRequired(true)->addValidator('NotEmpty'true);
            
            
    $firstName = new Zend_Form_Element_Text('firstName');
            
    $firstName->setLabel('First name')
                      ->
    setRequired(true)
                      ->
    addValidator('NotEmpty');

            
    $lastName = new Zend_Form_Element_Text('lastName');
            
    $lastName->setLabel('Last name')
                     ->
    setRequired(true)
                     ->
    addValidator('NotEmpty');
                 
            
    $email = new Zend_Form_Element_Text('email');
            
    $email->setLabel('Email address')
                  ->
    addFilter('StringToLower')
                  ->
    setRequired(true)
                  ->
    addValidator('NotEmpty'true)
                  ->
    addValidator('EmailAddress'); 
                  
            
            
    $submit = new Zend_Form_Element_Submit('submit');
            
    $submit->setLabel('Contact us');
            
            
    $this->addElements(array($title$firstName
                
    $lastName$email$submit));
            
        } 
    }
    index.phtml
    PHP Code:
    <h2><?php echo $this->pageTitle ;?></h2>
    <?php echo $this->bodyCopy ;?>

    <?php echo $this->form ;?>
    I have also attached a zip file containing the site/structure (minus the library)
    Attached Files Attached Files

  2. #2
    SitePoint Guru ripcurlksm's Avatar
    Join Date
    Aug 2004
    Location
    San Clemente, CA
    Posts
    859
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So as a test, I copied the entire class from ContactForm.php and pasted it into the same page as the controller ContactController.php and the page worked... I am completely new to this and am assuming that either a simple syntax naming error is causing the problem or I have to define somewhere in the code so it knows where to look to find the class??

    How can I point my script to look for the ContactForm.php page so it can recognize my forms_ContactForm class?


Bookmarks

Posting Permissions

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