We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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();
     }

 }

 ?>


85.5k
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
    )
);


22.7k
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!!!