Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Form is not loading

Hi i created a form following the vokuro sample app.

However i cant make it work

this is my config file

<?php

defined('APP_PATH') || define('APP_PATH', realpath('.'));

return new \Phalcon\Config([
    'database' => [
        'adapter'     => 'Mysql',
        'host'        => 'localhost',
        'username'    => 'root',
        'password'    => '',
        'dbname'      => 'test',
        'charset'     => 'utf8',
    ],
    'application' => [
        'controllersDir' => APP_PATH . '/app/controllers/',
        'modelsDir'      => APP_PATH . '/app/models/',
        'migrationsDir'  => APP_PATH . '/app/migrations/',
        'viewsDir'       => APP_PATH . '/app/views/',
        'pluginsDir'     => APP_PATH . '/app/plugins/',
        'libraryDir'     => APP_PATH . '/app/library/',
        'cacheDir'       => APP_PATH . '/app/cache/',
        'formsDir'       => APP_PATH . '/app/forms/',
        'baseUri'        => '/lanus/',
    ]
]);

?>

this is my loader


<?php

$loader = new \Phalcon\Loader();

/**
 * We're a registering a set of directories taken from the configuration file
 */
$loader->registerDirs(
    [
        $config->application->controllersDir,
        $config->application->modelsDir,
        $config->application->formsDir,
    ]
)->register();

// Register some namespaces
$loader->registerNamespaces(
    array(
       "Lanus"    => APP_PATH . "/"
    )
);

// Register autoloader
$loader->register();
?>

this is the error i get PHP Fatal error: Uncaught Error: Class 'Lanus\Forms\PagoExpressForm' not found in /var/www/html/lanus/app/controllers/CheckoutController.php:22

this is my controller

 <?php

 use Lanus\Forms\PagoExpressForm;
 use Phalcon\Auth\Exception as AuthException;

 class CheckoutController extends \Phalcon\Mvc\Controller
 {

     public function indexAction()
     {

     }

     public function pagoexpressAction()
     {
         $form = new PagoExpressForm();
     }

 }

 ?>


67.7k
edited Aug '16

well is this file Lanus\Forms\PagoExpressForm placed in

/var/www/html/lanus/app/ or/var/www/html/lanus/ cant figure it out by the code you posted

for sure problem with how you defined the loader and / or where you placed that PagoExpressForm.php

aham, actually you need to tell the loader where to look for this form in your loader


$loader->registerNamespaces(
    array(
       "Lanus"    => APP_PATH . "/"
       "Lanus\Forms" => APP_PATH . "/myForms" //or whatever
    )
);


9.3k
Accepted
answer

Yeah we had to do something like this to map to the various packages we wanted to use

   'Lanus\Gallery'                  => __DIR__ . '/../../Lanus/gallery/src/',
   'Lanus\Gallery\Controllers'      => __DIR__ . '/../../Lanus/gallery/src/controllers/',
   'Lanus\Gallery\Models'           => __DIR__ . '/../../Lanus/gallery/src/models',
   'Lanus\Gallery\Forms'            => __DIR__ . '/../../Lanus/gallery/src/forms'

with the namespace on the forms


namespace Lanus\Gallery\Forms;

use Lanus\Gallery\Models\Photos as Photos;

use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Text;
use Phalcon\Forms\Element\TextArea;
use Phalcon\Forms\Element\Password;
use Phalcon\Forms\Element\Select;
use Phalcon\Forms\Element\Submit;
use Phalcon\Forms\Element\Check;
use Phalcon\Forms\Element\Hidden;
use Phalcon\Validation\Validator\PresenceOf;
use Phalcon\Validation\Validator\Email;
use Phalcon\Validation\Validator\Identical;

class GalleryForm extends Form
{

}

Thanks its working now!!!