PHP code example of robwilkerson / cakephp-audit-log-plugin

1. Go to this page and download the library: Download robwilkerson/cakephp-audit-log-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

robwilkerson / cakephp-audit-log-plugin example snippets


/**
 * A model that uses the AuditLog default settings
 */
class SomeModel extends AppModel {

	/**
	 * Loading the AuditLog behavior without explicit settings.
	 * 
	 * @var array
	 */
	public $actsAs = array('AuditLog.Auditable');

	// More model code here.
}

/**
 * A model that sets explicit AuditLog settings
 */
class AnotherModel extends AppModel {

	/**
	 * Loading the AuditLog behavior with explicit settings.
	 * 
	 * @var array
	 */
	public $actsAs = array(
		'AuditLog.Auditable' => array(
			'ignore' => array('active', 'name', 'updated'),
			'habtm' => array('Type', 'Project'),
		)
	);

	// More model code here.
}
` php
CakePlugin::load('AuditLog');
` php
    if (!empty($this->request->data) && empty($this->request->data[$this->Auth->userModel])) {
    	$user['User']['id'] = $this->Auth->user('id');
    	$this->request->data[$this->Auth->userModel] = $user;
    }
    
` php
    /**
     * Get the current user
     *
     * Necessary for logging the "owner" of a change set,
     * when using the AuditLog behavior.
     *
     * @return mixed|null User record. or null if no user is logged in.
     */
    public function currentUser() {
        App::uses('AuthComponent', 'Controller/Component');
        return array(
            'id' => AuthComponent::user('id'),
            'description' => AuthComponent::user('username'),
        );
    }