Showing posts with label cakephp. Show all posts
Showing posts with label cakephp. Show all posts

Friday 3 January 2020

Cakephp write custom log


Code:

CakeLog::config('customlog', array(

 'engine' => 'File',

 'path' => WWW_ROOT.'files/log/'

));


customlog - Logname


path - Yourself to set customize whatever you need



Code:


CakeLog::write('customlog', 'Log data');

Thursday 18 July 2019

How to get complete current URL for Cakephp 3.x , 2.x

Below are few steps described to get URL inside Cakephp 3.x controller as well as view file. You can get full URL and base URL and current URL inside Controller.

The very first thing is to include Router in your Controller as below:

use Cake\Routing\Router;

public function urls()
{
    echo "<div style=''>";
    echo "Current URL=" . Router::url(null, true);
    echo "<BR>Current URL=" . Router::url(null, false);
    echo "<BR>Current URL=" . $this->request->getUri();
    echo "<BR>Current URL=" . $this->request->getUri()->getPath();
    echo "<BR>Current URL=" . $this->request->getRequestTarget();
    echo "<BR>Full URL=" . Router::url("/", true);
    echo "<BR>Base URL=" . Router::url("/", false);
    die("</div>");
}
And output would like this:

Current URL=http://localhost/cake/pages/urls
Current URL=/cake/pages/urls
Current URL=http://localhost/pages/urls?id=20&name=Pritom
Current URL=/pages/urls
Current URL=/pages/urls?id=20&name=Pritom
Full URL=http://localhost/cake/
Base URL=/cake/

Wednesday 25 July 2018

Cake php 64bit encrypt and decrypt

/*
 * Encrypt and base64 encode
 */
$encryptKey = "TESDEMO";
$secret = Security::cipher('1', $encryptKey);
$secret64Enc = base64_encode($secret);

// Decrypt your text
$secret64Dec = base64_decode($secret64Enc);
$nosecret = Security::cipher($secret64Dec,$encryptKey);
echo "$secret64Enc--------------$nosecret" ;
echo "<br>";

Wednesday 23 May 2018

How to create custom log in cakephp?

1. Add bootstrap for this in below

CakeLog::config('customlog', array('engine' => 'File'));

2. Create log message in custom logfile

CakeLog::write('customlog', 'myArray');

Check now you log directory once created