@Conradaek: CRM is the top level of the namespace in this instance. The SPARCS ended up in the code due to a snipet in Sublime.
The models and controller as requested are as follows:
namespace CRM\Controllers;
use common\Models\SystemMenuFrontend;
use CRM\Models\CrmClients as Clients;
class ClientsController extends ControllerBase
{
public function onConstruct()
{
parent::onConstruct();
// Get the Controller Menu:
$this->view->setVar("controller_menu", SystemMenuFrontend::retrieve('clients', array("visible = 'true'"), 0));
$this->view->setVar("breadcrumbs", SystemMenuFrontend::retrieve_breadcrumbs('clients'));
$this->view->setVar('system_current_path', 'crm/clients');
parent::_addJs("public/js/CRM/Clients.js");
}
public function indexAction()
{
// Lets check the access levels:
// if ($this->acl->isAllowed($this->session->get("usergroup"), "CRM_clients", "r") !== true)
if ($this->acl->isAllowed("root", "CRM_clients", "r") !== true)
{
// Insufficient access rights, so lets redirect to the login page:
$this->session->set("redirect", "/crm/clients/index");
return $this->response->redirect('login');
}
$conditions = array(
'columns' => 'id, name, telephone, fax',
'order' => 'name ASC'
);
$this->view->setVar('clients', Clients::find($conditions));
$this->view->setVar('indexes', CLients::index());
}
public function profileAction($id)
{
if ($this->acl->isAllowed("root", "CRM_clients", "r") !== true)
{
// Insufficient access rights, so lets redirect to the login page:
$this->session->set("redirect", "/crm/clients/index");
return $this->response->redirect('login');
}
$profile = Clients::findFirstById($id);
$sites = $profile->sites;
$this->view->setVar('client', $profile);
}
}
namespace CRM\Models;
use Phalcon\Mvc\Model\Resultset\Simple as Resultset;
class CrmClients extends Phalcon\Mvc\Model
{
/**
*
* @var integer
*/
public $id;
/**
*
* @var string
*/
public $name;
/**
*
* @var string
*/
public $url;
/**
*
* @var string
*/
public $logo_url;
/**
*
* @var integer
*/
public $hq_address_id;
/**
*
* @var integer
*/
public $invoice_address_id;
/**
*
* @var string
*/
public $telephone;
/**
*
* @var string
*/
public $fax;
/**
* Independent Column Mapping.
*/
public function columnMap()
{
return array(
'id' => 'id',
'name' => 'name',
'url' => 'url',
'logo_url' => 'logo_url',
'hq_address_id' => 'hq_address_id',
'invoice_address_id' => 'invoice_address_id',
'telephone' => 'telephone',
'fax' => 'fax'
);
}
public function initialize()
{
$this->hasMany("id", 'CRM\Models\CrmSites', "client_id", array("alias" => "sites"));
// $this->hasMany("id", 'CRM\Models\CrmContacts', "client_id", array("alias" => "contacts"));
// $this->belongsTo("hq_address_id", "common\Models\CoreAddresses", "id", array("alias" => "hq_address"));
// $this->belongsTo("invoice_address_id", "common\Models\CoreAddresses", "id", array("alias" => "invoice_address"));
}
}
namespace CRM\Models;
class CrmSites extends \Phalcon\Mvc\Model
{
/**
*
* @var integer
*/
public $id;
/**
*
* @var integer
*/
public $client_id;
/**
*
* @var integer
*/
public $address_id;
/**
*
* @var string
*/
public $telephone;
/**
*
* @var string
*/
public $fax;
/**
* Independent Column Mapping.
*/
public function columnMap()
{
return array(
'id' => 'id',
'client_id' => 'client_id',
'address_id' => 'address_id',
'telephone' => 'telephone',
'fax' => 'fax'
);
}
public function initialize()
{
$this->belongsTo("client_id", 'CRM\Models\CrmClients', "id", array("foreignKey" => true, "alias" => "Clients"));
$this->belongsTo("address_id", 'common\Models\CoreAddresses', "id", array("foreignKey" => true, "alias" => "Address"));
}
}
And just in case it's needed:
Module.php
<?php
namespace CRM;
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Db\Adapter\Pdo\Mysql as DbAdapter;
use Phalcon\Mvc\ModuleDefinitionInterface;
use Phalcon\Events\Manager;
class Module implements ModuleDefinitionInterface
{
/**
* Registers the module auto-loader
*/
public function registerAutoloaders()
{
$loader = new Loader();
$loader->registerNamespaces(array(
'CRM\Controllers' => __DIR__ . '/controllers/',
'CRM\Models' => __DIR__ . '/models/',
'common\Controllers' => __DIR__ . '/../../common/controllers/',
'common\Models' => __DIR__ . '/../../common/models/',
'Phalcon' => __DIR__ . '/../../../../incubator/Library/Phalcon'
));
$loader->register();
}
/**
* Registers the module-only services
*
* @param Phalcon\DI $di
*/
public function registerServices($di)
{
/**
* Read configuration
*/
$config = include __DIR__ . "/config/config.php";
/**
* Setting up the view component
*/
$di['view'] = function () {
// Load the events Manager:
$eventsManager = new Manager();
$eventsManager->attach("view:afterRender", new \common\Controllers\Translator());
$view = new View();
$view->setViewsDir(__DIR__ . '/views/');
$view->setLayoutsDir('../../../common/layouts/');
$view->setTemplateAfter('frontend');
$view->setEventsManager($eventsManager);
$view->registerEngines(array(
".volt" => function ($view, $di) {
$volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
$volt->setOptions(array(
'compiledPath' => __DIR__ . '/../../cache/',
'compiledSeparator' => '_'
));
return $volt;
})
);
return $view;
};
/**
* Database connection is created based in the parameters defined in the configuration file
*/
$di['db'] = function () use ($config) {
return new DbAdapter(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->name
));
};
}
}