Calling a custom object in a package

Permalink
Hi,

I am creating a custom Database object in my package named "core_be_tbx". I tried calling it using the Core::make() function. But it always throws this error: Class Concrete\Package\CoreBeTbx\Model\ContentWriterModel does not exist

I have my directory structure in the attached file.

Below is the snippet of code in my custom object:
<?php
namespace Concrete\Package\CoreBeTbx\Models;
use Concrete\Core\Database\Connection\Connection;
class ContentWriterModel {
    protected $conn;
    public function __construct(Connection $connection) {
        $this->conn = $connection;
    }
    public function getContents() {
        $sql = "SELECT * FROM SampleTable";
        return $this->conn->fetchAll($sql);
    }
}


And below is the snippet of code in my controller in calling my custom object.
<?php
namespace Concrete\Package\CoreBeTbx\Controller\SinglePage\Dashboard;
use Core;
use Concrete\Core\Page\Controller\DashboardPageController;
class ContentWriter extends DashboardPageController {
    public function view() {
        $model = Core::make('Concrete\Package\CoreBeTbx\Model\ContentWriterModel');
    }
}


Thanks for your help.

1 Attachment

 
ramonleenders replied on at Permalink Reply
ramonleenders
You have
namespace Concrete\Package\CoreBeTbx\Models;


Shouldn't that be "Model" without the "s", like so?
namespace Concrete\Package\CoreBeTbx\Model;

:)
gerard0710 replied on at Permalink Reply 1 Attachment
Hi ramonleender,

Thank you for your reply but it still doesn't work.

See attached.
hutman replied on at Permalink Reply
hutman
According to the screenshot you do have it in the models folder, so you should change that back in the namespace, however you should also change it to the plural in the controller.