PHP Frameworks

Using UNION syntax in CakePHP 2.4.6

Author - Manju Kashyap

Following UNION syntax works properly in CakePHP 2.4.6 version but it doesn’t work in CakePHP 2.5.2 version:
$unionQuery = $dbo->buildStatement
(
array(
‘fields’ => array( required fields),
‘table’ => $dbo->fullTableName(database_table_name),
‘alias’ => ‘customObject1’,
‘limit’ => null,
‘offset’ => null,
‘joins Read more…

Heroku | An introduction to Procfile and its use

Author - Webner

Introduction: We can make our Heroku app run different type of processes by creating a Procfile in the app.
There is a specific structure and syntax that we need to follow while creating a Procfile. Following are the main points to be considered while creating a Procfile:

The Procfile must Read more…

Zoho | Create Zoho Subscription using the PHP and subscription API

Author - Webner

We can create new Zoho Subscriptions via code by using PHP curl and with the help of Subscription APIs.

Below is the sample code which is required to create a subscription:

$headerArray = array(“Content-Type: application/json;charset=UTF-8”,
“X-com-zoho-subscriptions-organizationid: 00000000”,
“Authorization: Zoho-authtoken ——–Auth Read more…

PHP | Use Of strtr() function

Author - Webner

In PHP if you want to replace multiple variables of the string at one go you could use strtr() instead of using str_replace().

Example :

$vars = array(
‘##session_date##’=>$sessiondate,
‘##session_time##’=>$sessiontime,
‘##conferencelinenumber##’ =>$conferencelinenumber,
‘##pincode##’ =>$pincode,
‘##coachingcommnets##’=>$coachingcomments,
‘##actioncommitmnets##’=>$actioncommitmnets,
‘##reminders##’=> ‘ ‘,
‘##name##’ =>$name,
‘##breakline##’=>'<br><br>’,
);
$BODY=strtr Read more…

CakePHP | How to skip CakePHP authentication for some controller methods

Author - Rita

Description: By default, CakePHP authentication is applied to all application controllers. So it does not allow users to perform any of the action without login.

Solution: Each controller has a beforeFilter method which runs when some action is called from controller. Add below lines to your method:
Public function beforeFilter Read more…

PHP | Header function not working

Author - Webner

Code :
Function getredirect($subcontactid)
{
echo”contactid”.$subcontactid;
header(“location:https://subscriptions.zoho.com/app#/customers/$subcontactid”);
exit;
}

The header function in the above code does not work. But when we remove the echo from the code, it works properly.

Code after removing echo :
Function getredirect($subcontactid)
{
header(“location:https://subscriptions Read more…

Generate getter/setter for PHP Classes in Eclipse

Author - Webner

Using PHPGen Eclipse plug-in one can automatically generate getter /setter methods for instance variables.

Note: This Plugins is not available in Eclipse Marketplace.

Steps For Installation:

Start Eclipse and add “Help> Install New Software” from following URL: http://loge5.de/downloads/Eclipse/:

Click Add, enter http Read more…

How to use SimpleSAMLPhp as a Service Provider for authenticating users?

Author - Ishpreet Kaur

How to use SimpleSAMLPhp as a Service Provider for authenticating users? Some Basic steps to start using simplesamlphp.

1. Download stable version of SimpleSAMLphp from this link:

Click here

2. Go to the directory or your workspace where you want to install simpleSAMLphp, extract the zip file. Give Read more…

CakePHP | Using Elements for common code

Author - Rita

Problem: How to separate redundant piece of code from your view using cakephp 3.0.

Description: Let’s take an example. You have a list of products to display. We show products at many places such as

1. Show all products.

2. Show products of the specific category.

3. Show Read more…

PHP | Rename all the files in zip and then extract zip in PHP

Author - Kiran Preet

Description: In one of our PHP projects, we wanted to rename all the files in zip folder and then extract the zip.

The code for this is written below :

$zip = new ZipArchive;
$res = $zip->open($sourceFolder.’\’.$file);
for ($i = 0; $i < $zip->numFiles; $i++)
{
$filename = $zip->getNameIndex($i);
$newname;
$arr Read more…

Moodle | New lang strings not accessible

Author - Kritika Sood

In Moodle we had declared some new strings in lang file of a plugin like this:

$string[‘LIBRARY_NAME’] = ‘E-Lab’;
$string[‘BOOK_READ_SUCCESS’]=’Congratulations on reading the book’;

We wanted to use it in view.php file of the plugin like this:

$result=Get_String(‘BOOK_READ_SUCCESS’, ‘plugin name’);

But the output was Read more…

PHP | How to merge multiple PDFs into single file using pdftk

Author - Webner

Using PDFtk we can merge multiple files into a single file using a command like this:

Example : pdftk file1 file2 output file3.

Sample code to accomplish the same using PHP is given below:

$arrayOfPDFFiles;
$outputPDFName = “mergeResult.pdf”;
$dir =”Files/GeneratedPDFs/”;
for($i =0;$i<sizeOf($arrayOfPDFFiles);$i++)
{
$multiplePDFs = $multiplePDFs Read more…

Moodle/Totara | Upgrade Moodle database after making changes to a plugin

Author - Webner

In one of our Moodle projects, we modified a plugin’s code to add extra functionality to plugin. The modification in plugin’s code was not reflected and Moodle showed the older version of plugin.

To solve this problem, we upgraded the Moodle database and changes in plugin’s code Read more…

Eclipse | Undo deleted file in Eclipse

Author - Parminder Kaur

Problem: Undo deleted file in Eclipse

Solution: We were working on a project in Eclipse. Accidentally one of the PHP files got deleted in which code was written. Eclipse does not use the Linux ‘Trash’ but keeps local history from where we were able to recover the file.

Follow these Read more…

ACORD Forms autofill

Author - Webner

We get this request from a lot of clients in US insurance industry who want to generate ACORD forms automatically, means they want data of corresponding insurance Policy and other objects filled automatically in the editable ACORD PDF. Most of the clients have their data in a CRM system like Read more…

Zoho Creator or PHP based solution?

Author - Webner

A lot of Zoho users want to extend the capability that Zoho CRM provides out of the box. For example, one of our clients wanted to build a custom Quote Generator. They initially wanted to get the customization done to default Zoho CRM Quote form but their requirements were not Read more…

PHP | Convert date from one format to another in php

Author - Webner

To convert date from one format to another we need to specify to php interpreter the format of our current value. See code below:

/*
In statement below, we are providing date and format to DateTime::createFromFormat function so that function could know day, month and year values separately
*/

$date = DateTime Read more…

PHP | strpos() and result compare

Author - Webner

strpos($wholeText, $findText) in PHP returns position from which the $findText value starts if it is present in $wholeText. If it is not found then this function returns false. Fun starts when text is found at the very beginning (at position 0, as 0 is equivalent to false in PHP Read more…

PHP – Get files modified on a particular date

Author - Kiran Preet

Solution: In following example we have filtered files which are modified on current date (today’s date):
$source= “C:\wamp\www\Files\”;
$files = scandir($source);
$archiveFiles = array();
foreach($files as $file)
{
if (!in_array($file,array(“.”,”..”)))
{
$lastModified = date(‘d/m/y’,filemtime($source . ‘/’ .$file));
IF($lastModified==date(“d/m/y”))
{
array_push Read more…

Using Isset() function in php

Author - Webner

The Isset () Function:

The isset () function is used when we have to check whether a value in the variable is set or not. It returns false when variable contains null values.

For Example, values are stored in a session so that it can have access to another web Read more…