Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 3: Class 'Configure' Not Found

I just started with CakePHP v3.1.3 yesterday and I'm migrating teeny tiny bits of my CakePHP 2.4.2 site over at a time. Mostly just trying to get an understanding of the changes. I'm having an issue with Configure::read().

A little background info: I have SettingsSite, SettingsSiteHeaders, and SettingsSitesOptions tables in my db, I also made corresponding table objects for those. In my SettingsSiteTable class I have a method that retrieves the settings stored in the database. All is well and the following code works in my AppController no problem.

<?php
namespace App\Controller;

use Cake\Controller\Controller;
use Cake\Event\Event;
use Cake\Core\Configure;

class AppController extends Controller{

    public function beforeFilter(Event $event){
        debug(Configure::read('SettingsSite.title'));
    }

I'm having an issue getting the value to display properly in my view.

I have the following code in my theme default layout located in plugins/Default/src/Template/Layout/default.ctp

<title>
    <?php
        echo $this->fetch('title') . ' | ' .
        Configure::read('SettingsSite.title');
    ?>
</title>

I was receiving a "Class 'Configure' not found in plugins/Default/src/Template/Layout/default.ctp" error message.

So I then went to the AppView.php file and added the following line under the namespace declaration:

use Cake\Core\Configure;

Error is still there.

like image 816
bowlerae Avatar asked Oct 30 '15 19:10

bowlerae


1 Answers

Just use

use Cake\Core\Configure;

on top of your controller

Also If you have custom config file in app folder. You can load it in Bootstrap file and load the Config like this;

$config = Configure::read('App.namespace');
debug($config);
like image 125
Fury Avatar answered Sep 22 '22 18:09

Fury