Unfortunately it still not working.
I started to create a multi-module app.
<?php
use Phalcon\Mvc\Router,
Phalcon\Mvc\Application,
Phalcon\DI\FactoryDefault;
$config = new Phalcon\Config\Adapter\Ini('../multiple/config/config.ini');
$di = new FactoryDefault();
$loader = new \Phalcon\Loader();
$loader->registerDirs(
array(
"../multiple/plugins/",
"../multiple/apps/models/"
)
);
$loader->register();
$di->set('session', function() {
$session = new Phalcon\Session\Adapter\Files();
$session->start();
return $session;
});
//Specify routes for modules
$di->set('router', function () {
$router = new Router();
$router->setDefaultModule("user");
$router->add("/:module/:controller/:action", array(
'module' => 1,
'controller' => 2,
'action' => 3
));
$router->add("/login", array(
'module' => 'user',
'controller' => 'index',
'action' => 'login',
));
$router->add("/admin/products/:action", array(
'module' => 'backend',
'controller' => 'products',
'action' => 1,
));
$router->add("/products/:action", array(
'controller' => 'products',
'action' => 1,
));
return $router;
});
$di->set('db', function() use ($config) {
return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->name
));
});
try {
//Create an application
$application = new Application($di);
// Register the installed modules
$application->registerModules(
array(
'frontend' => array(
'className' => 'Multiple\Frontend\Module',
'path' => '../multiple/apps/frontend/Module.php',
),
'user' => array(
'className' => 'Multiple\User\Module',
'path' => '../multiple/apps/user/Module.php',
)
)
);
//Handle the request
echo $application->handle()->getContent();
} catch(\Exception $e){
echo $e->getMessage();
}
Forthemore \multiple\apps\user\models\Users.php is not work too. But, I think, itt will be good, if a found the answer to the original question.
I am going to home from work, I'll check the answer later.
What namespace are you using ?
The plugins/Test.php file can be defined as :
namespace Plugins;
class Test{
public function test($string){
var_dump($string);
return $string;
}
}
And in IndexController.php :
namespace Apps\User\Controllers;
use \Plugins\Test;
class UserController extends \Phalcon\Mvc\Controller
{
public function loginAction()
{
var_dump('ooo'); //output ooo
$test = new Test();
var_dump($test->test('gr')); //output nothing
}
}