And yet another question about namespaces (here regarding Package models)

Permalink
Dear Fivers – how do you call Concrete5 users btw? –,

I'd like to use a model in my custom package but the system fails to load it, most probably because of a namespace issue.

I followed the recommended file structure and everything went fine (I can install the package, I get the link in the dashboard, the view displays fine). I now need to make use of a model which is my dB access wrapper (I followed Remo's book example) but I'm not able to access it.

Here is my tree
└── ginox_product
    ├── controller.php
    ├── controllers
    │   └── single_page
    │       └── dashboard
    │           └── modularity.php
    ├── icon.png
    ├── models
    │   └── dashboard
    │       └── modularity.php
    └── single_pages
        └── dashboard
            └── modularity.php

Here is my model:
<?php namespace Concrete\Package\GinoxProduct\Models\Dashboard\Modularity;
use \Concrete\Core\Legacy\Model;
use Loader;
class GinoxModularity extends Model {
        public static function getAll() {
            $query = 'SELECT * FROM btModularity';
            return GinoxModularity::getModularity($query);
        }
    ....

and there my controller:
<?php namespace Concrete\Package\GinoxProduct\Controller\SinglePage\Dashboard;
use \Concrete\Core\Page\Controller\DashboardPageController;
use \Concrete\Package\GinoxProduct\Models\Dashboard\Modularity\GinoxModularity as GinoxModularity;
use Package;
use BlockType;
use SinglePage;
use Loader;
class Modularity extends DashboardPageController {
   public $helpers = array('form', 'html');
   public function view() {
       $this->set('modularities', GinoxModularity::getAll());
   }
  ...

I suspect that the following line is culprit but I couldn't find any proper fix for it:
use \Concrete\Package\GinoxProduct\Models\Dashboard\Modularity\GinoxModularity as GinoxModularity;

Do you guys have any clues about this?
Thank you in advance

kloport
 
hutman replied on at Permalink Reply
hutman
The namespacing and class name in your model is not correct you need it to be

namespace Concrete\Package\GinoxProduct\Models\Dashboard;
use \Concrete\Core\Legacy\Model;
use Loader;
class Modularity extends Model


If you don't want to change your class name you need to change the name of the model file to be ginox_modularity.php instead of modularity.php, they have to match.

And then in your controller the use statement is incorrect too, it should be

use \Concrete\Package\GinoxProduct\Models\Dashboard\Modularity as GinoxModularity;
kloport replied on at Permalink Reply
kloport
Thank you for your message Hutman but I get the exact same error.

C5 is unable to find the class.

I'll give it another try asap but as for now I use the model code inside my controller.

Thanks!