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 *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...