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.
use Cake\Core\Configure;
in your layout file. For a reason why see this questions #5668296 – WicknerConfigure
. – WicknerConfigure
in "every file" sounds like there might be better options, such as sending the data from the controller or using a helper as mentioned above. – Wickner