Friday, June 12, 2015

Call a external Model inside Plugin Controller

Hi to all,

I need to use themes (for admin section) in my new CakePHP 3 app. Themes now require create a plugin. Ok, I did it and works. But I have a problem.
Inside the plugin I have controllers (for admin methods) but the models (Tables) related still outside the plugin (app/src/Model/Table) because they are shared between admin controllers and public controllers.

When I try to do something like:

// app/plugins/Root/src/Controller/SchoolController.php

    public function index()
    {
        $this->paginate = [
            'contain' => ['Countries', 'Languages']
        ];
        $this->set('schools', $this->paginate($this->Schools));
        $this->set('_serialize', ['schools']);
    }

I have the next error message: Schools is not associated with Countries

Without pagination, all works fine:

// app/plugins/Root/src/Controller/SchoolController.php

    public function index()
    {
        $this->set('schools', $this->paginate($this->Schools));
        $this->set('_serialize', ['schools']);
    }

Anothers methods like Add, Edit that use another Tables (to create html selectors inputs) in adition of School Table doen't work.

The question is, Is possible to use an external model (table) call it from plugin's controller? I read the doc and api without results.

Thanks for advance ans sorry for my poor English.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: