[SOLVED]Class xxx Not Found, please advise

I add a routing rule below in index.php

$router->add("/MyController/{partner:[a-zA-Z0-9]{3}}",                  ['controller' => 'MyController',  'action' => 'handler'])
    ->convert('partner', function($partner) {
        return 'Android_' . $partner;
    });

MyController->handlerAction

public function handlerAction()
{
    $partner = $this->dispatcher->getParam('partner');
    if (class_exists($partner)) {
        $p = new $partner();
        $p->process();
    } else {
        echo "Class {$partner} Not Found.";
    }
}

and I put AndroidXXX classes into application/library, but I got Class AndroidXXX Not Found, any idea? library folder already register via \Phalcon\Loader.

Thanks.

Using registerPrefixes, the class can be found now.

What does the library folder registration code look like.

Also, please wrap your code in three backticks ( ` ) and "php" and follow it with three more backticks - that will enable syntax highlighting.

Like this, but with backticks instead of apostrophes

'''php code here '''



14.7k
    $loader = new \Phalcon\Loader();
    $loader->registerDirs([
        $application . DIRECTORY_SEPARATOR . 'controllers',
        $application . DIRECTORY_SEPARATOR . 'models',
        $application . DIRECTORY_SEPARATOR . 'library'
    ])->register();


7.1k
edited Mar '14

Dump your

$application . DIRECTORY_SEPARATOR . 'controllers',

and check controllers directory exists. After this, you can use namecpaces, it's easy and faster.

Did you do mistake here? ['controller' => 'MyController', 'action' => 'handler'] should ['controller' => 'My', 'action' => 'handler']

$router->add("/MyController/{partner:[a-zA-Z0-9]{3}}",                  ['controller' => 'MyController',  'action' => 'handler']) //My than MyController
  ->convert('partner', function($partner) {
    return 'Android_' . $partner;
  });


14.7k

the controllers folder does exist, and router does work, the message is from handler action, it shows "Class Android_XXX Not Found.", I think namespaces may work, but how? Do namespaces need to be registered in index.php?