I have an AppController that should be loading models that every controller can use, but for some reason I can only access these models when I use LoadModel->(‘Model’);
more info here, I posted this earlier:
class AppController extends Controller {
public $components = array('Acl', 'Auth', 'Security', 'AntiXss', 'Cookie', 'Session');
public $helpers = array('Javascript', 'Html', 'Form', 'Number', 'DateFormat', 'Currency', 'Acl', 'Whitelabel', 'Session');
public $uses = array('Language', 'Administrator', 'Setting');
var $loggedAdministratorId = null;
var $loggedAdministratorData = null;
function beforeFilter(){
//Configure AuthComponent
$this->Auth->userModel = 'Administrator';
$this->Auth->fields = array('username' => 'username', 'password' => 'password');
$this->Auth->loginAction = array('controller' => 'administrators', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'administrators', 'action' => 'login');
$this->Auth->loginRedirect = '/';
$this->Auth->authError = __("Please log in to continue.");
$this->loggedAdministratorId = $this->Auth->user('id');
if ($this->loggedAdministratorId != null) {
$this->Administrator->recursive = 0;
$this->loggedAdministratorData = $this->Administrator->findById($this->loggedAdministratorId);
}
$this->set('administratorId', $this->loggedAdministratorId);
//this is where it breaks
$this->Setting->PrintValue("SiteDown");
echo("<BR>========================<BR>");
// Check if the site is down
if ($this->Setting->GetValue("SiteDown") == 1) {
if ($this->loggedAdministratorId != 1) {
if (($this->params['controller'] != "pages" || $this->params['action'] != "display" || $this->params['pass'][0] != "sitedown") && // Allow showing the sitedown page
($this->params['controller'] != "administrators" || !in_array($this->params['action'], array('login', 'logout')))) { // And the login, so that master CAN login
$this->redirect("/pages/sitedown");
}
}
} else {
// If the site is NOT down, and the customer is in the sitedown page, send him back
if ($this->params['controller'] == "pages" && $this->params['action'] == "display" && $this->params['pass'][0] == "sitedown"){
$this->redirect("/");
}
}
It says “Call to a member function PrintValue() on null”, however this has worked in the past, pre upgrade. For posterity, heres Setting.php
<?php
App::uses('AppModel', 'Model');
class Setting extends AppModel {
public $name = 'Setting';
public $useTable = "settings";
var $validate = array(
'key' => array('rule' => 'notEmpty', 'required' => true),
'value' => array('rule' => 'notEmpty', 'required' => true)
);
function afterFind($results) {
foreach ($results as $key => $val) {
if (is_array($val)) {
if (isset($val['Setting']) && isset($val['Setting']['description'])) {
$results[$key]['Setting']['description'] = __var($results[$key]['Setting']['description']);
}
}
}
return $results;
}
function afterSave($created) {
if (isset($this->data['Setting']['system']) && $this->data['Setting']['system'] == 1) {
return; // Do not clear cache if this is a System setting
}
$this->_ClearAllCache();
}
public function PrintValue($value){ echo $value;}
function GetValue($key) {
$settings = Cache::read("settings");