0

So I've a problem that made me crazy :(, I create a form and when I use the class form in my controller I got this error:

Fatal error: Class 'Application\forms\ArticleForm' not found in C:\wamp2\www\test\module\Application\src\Application\Controller\BlogController.php

and even when I try to use Application\forms\ArticleForm this path doesn't found, this is a part of my action : Update the code :

public function addAction()
{       
    $form = new ArticleForm();// here the class doesn't found !!
    //var_dump($form);die;
    $form->initForm();
    $request = $this->getRequest();
    $form->setData($request->getPost());

And this is my ArticleForm :

class ArticleForm extends Form {

 public function __construct()
 {
    parent::__construct('UserEntry');

$this->setAttribute('method', 'post');
$this->setAttribute('enctype', 'multipart/form-data');
$this->setAttribute('class', 'contact_form');
 }

public function initForm()
  {
  $this->addFormFields(); //function where we added all fields

$articleInputFilter = new ArticleInputFilter();
$this->setInputFilter($articleInputFilter->getInputFilter()); //Asign input Filter to      form
}

protected function addFormFields()
 {
   $this->addSubmit();
   $this->addTitle();
   $this->addContent();
   $this->addDate();
   $this->addPublication();
   $this->addImage();
  }

/**
 *
 */
protected function addTitle()
{
    $this->add(array(
            'name' => 'title',
            'attributes' => array(
                    'type' => 'text',
            ),
            'options' => array(
                    'label' => _('Title')
            ),
    ));
}

/**
 *
 */
protected function addContent()
{
    $this->add(array(
            'name' => 'content',
            'attributes' => array(
                    'type' => 'text',
            ),
            'options' => array(
                    'label' => _('Content')
            ),
    ));
}

/**
 *
 */
protected function addDate()
{
    $this->add(array(
            'name' => 'date',
            'attributes' => array(
                    'type' => 'date',
            ),
            'options' => array(
                    'label' => _('Date'),
                    'id'    => 'datepicker',
            ),
    ));
}

/**
 *
 */
protected function addPublication()
{
    $this->add(array(
            'name' => 'publication',
            'attributes' => array(
                    'type' => 'checkbox',
            ),
            'options' => array(
                    'label' => _('Publication'),
                    'use_hidden_element' => true,
                    'checked_value' => 1,
                    'unchecked_value' => 'no',
            ),
    ));
}

/**
 *
 */
protected function addImage()
{
    $this->add(array(
            'name' => 'Image',
            'attributes' => array(
                    'type' => new ImageForm(),
            ),
            'options' => array(
                    'label' => _('Image')
            ),
    ));
}

/**
 *
 */
protected function addSubmit()
{
    $this->add(array(
            'name' => 'submit',
            'attributes' => array(
                    'type' => 'submit',
                    'value' => _('Add'),
                    'class' => 'submit',
            ),
    ));
}
}

Finally this is my ArticleInputFilter :

 class ArticleInputFilter extends InputFilter implements InputFilterAwareInterface 
  {
/**
 * @var string
 */
public $title;

/**
 * @var int
 */
public $image;

/**
 * @var string
 */
public $content;

/**
 * @var Date
 */
public $date;

/**
 * @var Boolean
 */
public $publication;

/**
 * @param $data
 */
public function exchangeArray($data)
{
    $this->title     = (isset($data['title']))     ? $data['title']     : $this->title;
    $this->image     = (isset($data['image']))     ? $data['image']     :  $this->image;
    $this->content     = (isset($data['content']))     ? $data['content']     : $this->content;
    $this->publication   = (isset($data['publication']))       ? $data['publication']   :  $this->publication;
    $this->date      = (isset($data['date']))      ? $data['date']  :  $this->date;
}

/**
 * @param InputFilterInterface $inputFilter
 * @return void|InputFilterAwareInterface
 * @throws \Exception
 */
public function setInputFilter(InputFilterInterface $inputFilter)
{
    throw new \Exception("Not used");
}

/**
 * @return InputFilter|InputFilterInterface
 */
public function getInputFilter()
{
    if (!$this->inputFilter) {
        $inputFilter = new InputFilter();
        $factory     = new InputFactory();

        $inputFilter->add($factory->createInput(array(
                'name'     => 'title',
                'required' => true,
                'filters'  => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                ),
                'validators' => array(
                        array(
                                'name'    => 'StringLength',
                                'options' => array(
                                        'encoding' => 'UTF-8',
                                        'min'      => 6,
                                        'max'      => 100,
                                ),
                        ),
                ),
        )));

        $inputFilter->add($factory->createInput(array(
                'name'     => 'content',
                'required' => true,
                'filters'  => array(
                        array('name' => 'StripTags'),
                        array('name' => 'StringTrim'),
                ),
                'validators' => array(
                        array(
                                'name'    => 'StringLength',
                                'options' => array(
                                        'encoding' => 'UTF-8',
                                        'min'      => 10,
                                ),
                        ),
                ),
        )));

        $inputFilter->add($factory->createInput(array(
                'name'     => 'publication',
                'required' => false,
        )));

        $inputFilter->add($factory->createInput(array(
                'name'     => 'date',
                'required' => true,
        )));

        $inputFilter->add($factory->createInput(array(
                'name'     => 'image',
                'required' => true,
        )));

        $this->inputFilter = $inputFilter;
    }

    return $this->inputFilter;
}
  }

So please if someone has any idea or solution to my problem I will be very appreciative.

Mohammadov
  • 595
  • 3
  • 13
  • 34
  • "forms" is lowercase - is this intended. My guess would be for that being the error. – Sam Feb 25 '14 at 20:45

2 Answers2

2

Probably an autoloading problem.

Where is defined your ArticleForm ?

Note : you'd better use the form element manager to get form instance. You can read more on this subject here

jmleroux
  • 947
  • 6
  • 17
  • yes i am sure it some kind of autoloading problem, this is my path : Application/forms/ArticleForm, so where can i found this autoload and change it ?? – Mohammadov Feb 25 '14 at 17:20
  • any idea @jmleroux ?? – Mohammadov Feb 25 '14 at 19:31
  • 2
    No idea because you didn't include the interresting part : the namespace déclaration :). I suspect that your namespace declaration is not synchronized with your filesystem. – jmleroux Feb 25 '14 at 22:05
0

I had the same problem. The answer is pretty simple. The problem is in the autoloader so you need to "refresh" or "sincronyze everything" before you get started. So at the top of the function addAction() or the file just require the autoload.php file that is inside of the vendor folder to "update" your project. Something like this:

require 'vendor/autoload.php';

Obviously, you need to write your own path. I hope that would help.

German Rocha
  • 55
  • 1
  • 14