Answer the question
In order to leave comments, you need to log in
How to use a model in a controller on a multi-module Phalcon?
Please help a newbie. The second day I struggle and don't understand...
I took the skeleton from here and try to set it up:
https://github.com/phalcon/mvc/tree/master/multiple
File /apps/frontend/controllers/PagesController.php:
namespace Multiple\Frontend\Controllers;
use Phalcon\Mvc\Controller;
class PagesController extends Controller{
public function indexAction(){
echo Pages::testvar;
exit;
}
}
use Phalcon\Mvc\Model;
class Pages extends Model{
public $testvar = "777";
}
Fatal error: Uncaught Error: Class 'Multiple\Frontend\Controllers\Pages' not found in /var/www/phalcon.loc/apps/frontend/controllers/PagesController.php:11 Stack trace: #0 [internal function]: Multiple\Frontend\Controllers\PagesController->indexAction('xxxpage') #1 [internal function]: Phalcon\Dispatcher->callActionMethod(Object(Multiple\Frontend\Controllers\PagesController), 'indexAction', Array) #2 [internal function]: Phalcon\Dispatcher->dispatch() #3 /var/www/phalcon.loc/public/index.php(93): Phalcon\Mvc\Application->handle() #4 /var/www/phalcon.loc/public/index.php(98): Application->main() #5 {main} thrown in /var/www/phalcon.loc/apps/frontend/controllers/PagesController.php on line 11
Answer the question
In order to leave comments, you need to log in
I find something on the Toaster less and less often... it's sad...
I finished it myself again. I leave the solution to the problem (I don’t know the correct solution or not) for posterity :-)
In the controller, we specify the model we are going to work with:
use Multiple\Frontend\Models\Pages as Pages;
and in the model itself, we specify the namespace where it lies:
namespace Multiple\Frontend\Models;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question