Reputation: 83
I'm trying to implement phalcon multi module with namespace. normally its working. but models not loading from its location(/apps/models/). if I paste all of my models file into controller dir then its working. It should load from models dir. how could i solve this problem.
[Front Module]
$loader->registerNamespaces(
array(
'Multiple\Frontend\Controllers' => '../apps/frontend/controllers/',
'Multiple\Frontend\Models' => '../apps/frontend/models/',
));
[Blogs Model]
namespace Multiple\Frontend\Controllers;
use Phalcon\Mvc\Model;
class Blogs extends Model{}
i also try "namespace Multiple\Frontend\Models;" but not success. getting error like:
Fatal error: Uncaught Error: Class 'Multiple\Frontend\Controllers\News' not found in C:\xampp\htdocs\pm\apps\frontend\controllers\IndexController.php:38 Stack trace: #0 [internal function]:
i have my dispatcher like:
public function registerServices(DiInterface $di)
{
# Registering a dispatcher
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace("Multiple\Frontend\Controllers");
return $dispatcher;
});
i think the error : "Error: Class 'Multiple\Frontend\Controllers\Blogs' not found" for this cause default namespace is frontend\controller. how to solve it? please
Upvotes: 0
Views: 1066
Reputation: 1369
You need to load your models obviously outside of modules. The registerNamespaces is only hit in this module when this module is hitted by dispatcher.
Actually i thought that you have problems with using models in different modules. If you have this error Multiple\Frontend\Controllers\News
that this can't be found it means that you just don't have proper use statement and it's looking for class in same namespaces, just add use Multiple\Frontend\Models\News
. Are you even using any IDE ?
Upvotes: 2
Reputation: 166
I think you need to add one extra line in your controller like...
namespace Multiple\Frontend\Controllers;
use Phalcon\Mvc\Controller;
use Multiple\Frontend\Models\Blogs as Blogs; //** This line should Add **//
class IndexController extends Controller
{
public function indexAction()
{}
}
Upvotes: 0