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/

Friday, 5 October 2018

Javascript - refresh parent window when closing child window

var win = window.open("URL", '_blank');
var timer = setInterval(function () {
if (win.closed) {
 clearInterval(timer);
window.location.reload();
// Refresh the parent page
 }
 }, 1000);
 }

Wednesday, 22 August 2018

Ckeditor add force download option in dialog

CKEDITOR.on( 'dialogDefinition', function( evt ) {
   var dialog = evt.data;

   if ( dialog.name == 'link' ) {
       // Get dialog definition.
       var def = evt.data.definition;         
       // Add some stuff to definition.
       
       
       
       var infoTab = def.getContents( 'info' );
       
       infoTab.add( {
type: 'checkbox',
id: 'download',
requiredContent: 'a[download]',
label: "Force Download",
setup: function( data ) {
if ( data.download !== undefined )
this.setValue( 'checked', 'checked' );
},
commit: function( data ) {
if ( this.getValue() ) {
data.download = this.getValue();
}
}
});

   }
} );

CKEDITOR.replace( 'editor' );