1

Version_DefaultComponentForm.php

namespace ComponentManagement\Form;
class Version_DefaultComponentForm extends VersionForm {
    public function __construct($name = null) {

ComponentManagementController.php

namespace ComponentManagement\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use ComponentManagement\Form;
use ComponentManagement\Model\Component;

    class ComponentManagementController extends AbstractActionController {
        protected $albumTable;
        public function indexAction() {
            $componentForm = new Form\ComponentForm();
            $versionForm = new Form\VersionForm();
            $version_DefaultComponentForm = new Form\Version_DefaultComponentForm();

I got this error:

Fatal error: Class 'ComponentManagement\Form\Version_DefaultComponentForm' not found in D:\WEB\xampp\htdocs_zend\module\ComponentManagement\src\ComponentManagement\Controller\ComponentManagementController.php on line 15

Can not find any bug by myself...Could anyone tell me why? using php 5.4.7 with zend 2.0

No idea why,but it works correctly now.

namespace ComponentManagement\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use ComponentManagement\Form;
use ComponentManagement\Model\Component;

class ComponentManagementController extends AbstractActionController {

    public function indexAction() {
        $componentForm = new Form\ComponentForm();
        $versionForm = new Form\VersionForm();

        $request = $this->getRequest();
        if ($request->isPost()) {
            $component = new Component();
            $componentForm->setInputFilter($component->getInputFilter());
            $componentForm->setData($request->getPost());

            if ($componentForm->isValid()) {

            }
        }
        return array('forms' => array(
                'ComponentForm' => $componentForm,
                'VersionForm' => $versionForm,
            )
        );
    }
5
  • 3
    Wild guess: you didn't include_once("Version_DefaultComponentForm.php")? Commented Jan 8, 2013 at 5:24
  • Still need include that file after using namespace in php? Commented Jan 8, 2013 at 6:12
  • I do not know, some how it works now, without include. There is a ComponentManagement\Model\Component Class works fine all the way. no idea why... Commented Jan 8, 2013 at 10:05
  • 2
    @TKL, I think it may be because your original class name contained an underscore, pretty sure the StandardAutoloader will transform that to a / Commented Jan 8, 2013 at 10:20
  • "Class and Interface naming All classes, interfaces, and abstracts must begin with an uppercase character. They may contain additional capital letters and underscores. Any underscores in class names will be converted to the DIRECTORY_SEPARATOR when attempting to auto-load." news.php.net/php.standards/2 Commented Oct 11, 2013 at 0:58

1 Answer 1

1

http://framework.zend.com/manual/2.0/en/modules/zend.loader.standard-autoloader.html

Zend\Loader\StandardAutoloader is designed as a PSR-0-compliant autoloader. It assumes a 1:1 mapping of the namespace+classname to the filesystem, wherein namespace separators and underscores are translated to directory separators. :P

Sign up to request clarification or add additional context in comments.

1 Comment

I'm sure the PSR-0-compliance people thought to themselves "Yeah, sure, nobody ever uses underscores in file names!"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.