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

ResourceController handler class cannot be loaded

LOADER CODE

<?php

$loader = new \Phalcon\Loader();

$loader->registerNamespaces(
    array(
        'Site\Front\Controller'         =>  __DIR__ . '/../../app/controllers/',
        'Site\Model'                    =>  __DIR__ . '/../../app/models/',
    )
)->register();

CONTROLLER CODE

namespace Site\Front\Controller;

Use Site\Library\Form\Resource;

class resourceController extends ControllerBase  {

    public function indexAction()
    {
        echo 'in';
        // New Form
        //$objForm =  new Resource\NewForm();
        //$this->view->setVar('newForm', $objForm->createForm());
    }

    // Add New Resource
    public function addAction()
    {
        $strResource = $this->request->getPost('url', 'string');

        // Creating Form
        $objForm = new Resource\SubmitForm();
        $this->Tag->setDefault('urlName', $strResource);
        $this->view->setVar('addForm', $objForm->createForm());
    }
} 

Why is the controller not loading?



2.0k
edited Jul '14

I think you do not register all the namespaces e.g: Site\Library\Form



98.9k

Try changing the class name from resourceController to ResourceController



33.7k

I renamed 'resourceController' to 'ResourceController' still same result.



98.9k

Can you post your code somewhere? Like on Github?



33.7k
edited Jul '14

Here is my code

Bootsrap-

<?php

error_reporting(E_ALL);

//(new Phalcon\Debug())->listen();

//try {

    /**
     * Read the configuration
     */
    $config = include __DIR__ . "/../app/config/config.php";

    /**
     * Read auto-loader
     */
    include __DIR__ . "/../app/config/loader.php";

    /**
     * Read services
     */
    include __DIR__ . "/../app/config/services.php";

    /**
     * Handle the request
     */
    $application = new \Phalcon\Mvc\Application($di);

    echo $application->handle()->getContent();

/*} catch (\Exception $e) {
    echo $e->getMessage();
}*/

Loader and controller code are posted above



33.7k
Accepted
answer

Thansk for your responses.

I have found the cause of the problem. It is NAMESPACE defination. I did not setup the "$dispatcher->setDefaultNamespace('Site\Front\Controller');"