How to use log() in Model/Entity/Bookmark.php CakePHP 3

Written by James McDonald

March 2, 2016

In CakePHP 2.x I could insert $this->log() just about anywhere and it worked.

Was just trying to do the same in CakePHP 3 from inside the file src/Model/Entity/Bookmark.php I received an error message

“Call to undefined method App\Model\Entity\Bookmark::log()”

To fix this you need to add 2 use statements one at the top of the file and one inside the class declaration

<?php

namespace App\Model\Entity;

use Cake\ORM\Entity;
use Cake\Collection\Collection;

// add use statement for LogTrait
use Cake\Log\LogTrait;

class Bookmark extends Entity {

    // add the use LogTrait
    use LogTrait;

    protected function _getTagString() {
        // now you can use $this->log()
        $this->log(["old" => "macdonald"]);
        
    }

}

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

How to Research a CPU Upgrade

How to Research a CPU Upgrade

Upgrade Time! Doing a lot of VMWare Workstation virtualization to create labs for self-study and training. Finding...