Categories
jQuery

How to Generate PDF in jQuery! Make it Simple

Web developers have to deal with generating PDFs (invoices, money receipts, bills, etc) as part of web development. And most cases it is not tough to do but it is quite irritating. In a few cases, it may really difficult.

Developers have to spend a lot of time and effort to generate PDFs similar to the web interface. Like, PHP developers use DOMpdf, FPDF, TCPDF, MPDF, or other libraries for generating PDFs, but they have to deal with a lot of complexity to match the PDF design similar to the web interface.

Isn’t boring! So here I come with the handy and easy solution to Generate PDF using jQuery.

Generate PDF in jQuery
Generate PDF in jQuery

Generate PDF in jQuery

To generate a PDF of your website just pick a DOM element name (identifier ID) of your website and pass that, just it. jQuery will handle the rest of that things. that’s it! Please see the code block for more details.

Code Sample:

https://gist.github.com/sohelrana820/5b545e005f683ae29011e73e1bae91b6.js

Want to read more? please click here

Categories
Code Area PHP Tips and Tricks Tools and Technologies

Using CakePHP Logging Scope

Undoubtedly logging is most important part of an application to debugging, analyzing, measuring performance. So often times we want to handle different logging behavior for different components of our application. Assume that you are developing an e-commerce website and you want to handle logging cart & payment component differently.

So in that way, each log of the different component will store into a different file. So debugging will be easier than generic logging. To do that open config/bootstrap.php file and copy pastes this snippet.

Then you can implement this scope like this way (From controller & model).

Log::error('Product is not added into cart due to internal error', ['scope' => ['cart']]);
Log::emergency('Payment is not received', ['scope' => ['payments']]);

 

Categories
Code Area PHP Programming Tips and Tricks Tools and Technologies

Array Chunk based on Key Value in PHP

Sometimes programmer needs to chunk or grouping array based on the array key value. Look at the below code snippet, here I have a multidimensional array, and I want to group all same elements of each category.

OUTPUT:

array (
  'php' => 
  array (
    0 => 
    array (
      'category' => 'php',
      'post_id' => 100,
    ),
    1 => 
    array (
      'category' => 'php',
      'post_id' => 102,
    ),
    2 => 
    array (
      'category' => 'php',
      'post_id' => 104,
    ),
  ),
  'html' => 
  array (
    0 => 
    array (
      'category' => 'html',
      'post_id' => 101,
    ),
    1 => 
    array (
      'category' => 'html',
      'post_id' => 104,
    ),
  ),
  'js' => 
  array (
    0 => 
    array (
      'category' => 'js',
      'post_id' => 103,
    ),
  ),
)
Categories
Code Area PHP Tips and Tricks Tools and Technologies Ubuntu

Depreciation Notice Error in Phpmyadmin With Ubuntu16.04

If you see the error notice properly you can understand what does it means. This error notice means some of your PHP has old constructors. So if you replace these old constructors with new constructor then the problem will be solved.

Depreciation Notice Error in Phpmyadmin With Ubuntu16.04

 

To do this, open streems.php file by this command.

sudo gedit /usr/share/php/php-gettext/streams.php

 StringReader Error: To find it go to line number 52 then

//Replace this line
function StringReader ($str='') {

//with
function __construct($str='') {

 

FileReader Error: To find it go to line number 90 then

//Change this
function FileReader ($str='') {

//To
function __construct($str='') {

 

CacheFileReader Error: To find it go to line number 146 then

//Change this
function CacheFileReader ($str='') {

//To
function __construct($str='') {

Then save & close the file. After that open gettext.php file by this command.

sudo gedit /usr/share/php/php-gettext/gettext.php

Go to line number 101 then

// Replace this line
function gettext_reader($Reader, $enable_cache = true) {

//With
function __construct($Reader, $enable_cache = true) {

Categories
Career PHP Tips and Tricks Tools and Technologies

How to Recursively Delete a Directory and its Entire Contents Using PHP

Here is a script for recursively delete a directory and its entire contents using PHP

Categories
CakePHP Career Code Area PHP Programming Tips and Tricks Tools and Technologies

CakePHP Auth Allow to Specific Actions of Specific Controllers

It’s a common problem to CakePHP developer to auth allow to specific actions of a specific controller. Especially to newbies developer of CakePHP. Honestly, it’s really easy but little tricky. So this article is for whom, who looking for CakePHP auth allow to specific actions of specific controllers.

Assume you have three controllers ClientsController.php, JobsController.php and HomeController.php. Now you want to access:

  • index() action from all controller
  • lists() action of  ClientsController.php controller
  • jobs() action of JobsController.php controller
  • home() action of HomeController.php controller

To accomplish this goal open AuthController.php file and add these following line.

public function beforeFilter(Event $event)
{
   $this->Auth->allow(array('index'));
}

 

Then open ClientsController.php file and add these following line.

public function beforeFilter(Event $event)
{
   parent::beforeFilter($event);
   $this->Auth->allow(array('lists'));
}

 

Then open JobsController.php file and add these following line.

public function beforeFilter(Event $event)
{
   parent::beforeFilter($event);
   $this->Auth->allow(array('jobs'));
}

 

Then open HomeController.php file and add these following line.

public function beforeFilter(Event $event)
{
   parent::beforeFilter($event);
   $this->Auth->allow(array('home'));
}

In this way, you can auth allow to specific actions of specific controllers.

Categories
Career Code Area PHP Tips and Tricks Tools and Technologies

Catch PHP Output Buffering Data Over jQuery AJAX

From last few day’s I was deeply engaged with Output Buffering. I had to catch PHP output buffering responsive over AJAX request. And now I am here to sharing a sample script to catch PHP output buffering data over jQuery AJAX.

Live Demo

 

Categories
Career Code Area PHP Tips and Tricks Tools and Technologies

Upload File Using cPanel API

cPanel is a web hosting control panel which is using for various aspects of website and server administration with a nice graphical interface. cPanel also has well-documented APIs to manage all kinds cPanel activities through API. Here I have shared a code snipped to uploading files using cPanel API. (Fileman::upload_files)

Categories
Career Code Area PHP Tips and Tricks Tools and Technologies Uncategorized

Parsing XML With Multiple Namespaces Using PHP

Yesterday, I had a very ugly XML data which had to parse. It has multiple namespaces and namespaces are irrelevant with DOM – I just wasn’t getting the nodeValue from the Element. It was parsing partially not all nodeValues due to namespaces are irrelevant with DOM. Then I applied little tricks onto it through XML children options. And I thought I need to share this code so other developers can save his time to get out this annoying issue.

Categories
Career Code Area Tips and Tricks Tools and Technologies

Remove Default Search Box and Add Custom Box in DataTable

DataTable displaying a default search box while initializing it. So by default DataTable has a search box. But sometimes you might have to remove that default search box and add a custom search box. And place that somewhere in the page. This article will help you to do that.

$('#example').DataTable();

See the above snippet, If your DataTable initializing it like that, then default search box will display. You might think, I can just use “bFilter: false” option to remove that search box. Yes you can! but the problem is if you do that, then DataTable will disable/turn off the search functionality. But you have to only remove the search box not search functionality.

In this case, you can use "dom: 't'" option. This will keep the default functionality of DataTable and just remove the search box, pagination (just hide it). It will just show the table elements.

Here I have shared a code snippet, you can get the idea to accomplish it.

$(document).ready(function() {
  var users = $('#users').DataTable({
    "dom": "t"
  });

  $('#customSearchBox').keyup(function() {
    users.search($(this).val()).draw();
  })
});

See the full jsFiddle