R
R
Roman2018-03-05 10:53:21
Phalcon
Roman, 2018-03-05 10:53:21

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;
    }
}

File /apps/frontend/models/Pages.php:
use Phalcon\Mvc\Model;
class Pages extends Model{
    public $testvar = "777";
}

In the router, the rule is to send everything to the PagesController.
As a result, when accessing, an error pops up that they say:
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

The 11th line is actually: echo Pages::testvar;
You can put find or something else, it doesn't matter.
I will repeat, just in case, once again, the skeleton of a multi-module application is taken from the github, i.e. there is not much of my own activity in it.
Tell me what is my mistake?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2018-03-05
@RomanOracool

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 question

Ask a Question

731 491 924 answers to any question