Thursday 6 October 2011

How to install CakePHP in XAMPP

How to install CakePHP in XAMPP
Cake is a PHP web development framework which employs the MVC model. I will describe how to set it up on a win32-based machine.

First install xampp which consists of Apache, PHP, and MySQL. The install process just copies some files to a specified folder.

Next, run “setup_xampp.bat” located on the root xampp folder.

After that open “httpd.conf” located on “apacheconf” folder. Then uncomment the line that contains “mod_rewrite”. This is needed to enable Cake’s pretty URL such as “http://localhost/cake/users/view” instead of “http://localhost/cake/index.php/users/view”.

Afterwards, extract Cake somewhere in the “htdocs” folder. I usually put it in “htdocscake”.

The last step is to copy “database.php.default” in “appconfig” of Cake’s folder to “database.php”. Then change the “$default” variable to suit your database settings. An example is:

class DATABASE_CONFIG

{

var $default = array('driver' => 'mysql',

'connect' => 'mysql_connect',

'host' => 'localhost',

'login' => 'root',

'password' => '',

'database' => 'test',

'prefix' => '');

}

Which works with the default MySQL in xampp.

To see if things are working properly, run “xampp-control.exe” in xampp’s root folder and then start Apache and MySQL from there:
After that point your browser to “http://localhost/[cake's root folder]” for example “http://localhost/cake”. and enjoy CAKE

Sunday 13 March 2011

Songs that inspired me


Eagle Hotel California

Dire Straits - Sultans Of Swing

Guns N' Roses - Sweet Child OMine

mettallica one


Black Magic Woman by Santana


Regular expressions basics


Regular expression types 
There are 2 types of  regular expressions:
  • POSIX Extended
  • Perl Compatible
The ereg, eregi, ... are the POSIX versions and preg_match, preg_replace, ... are the Perl version. It is important that using Perl compatible regular expressions the expression should be enclosed in the delimiters, a forward slash (/), for example. However this version is more powerful and faster as well than the POSIX one.
The regular expressions basic syntax
To use regular expressions first you need to learn the syntax of the patterns. We can group the characters inside a pattern like this:
  • Normal characters which match themselves like hello
  • Start and end indicators as ^ and $
  • Count indicators like +,*,?
  • Logical operator like |
  • Grouping with {},(),[]
An example pattern to check valid emails looks like this:
Code:
^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$
The code to check the email using Perl compatible regular expression looks like this:

//code1
$pattern = "/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/";
$email = "jaison@demo.com";
if (preg_match($pattern,$email)) echo "Match";
else echo "Not match";

//code2
$pattern = "^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$";
$email = "jaison@demo.com";
if (eregi($pattern,$email)) echo "Match";
else echo "Not match";

Regular expression (pattern)
Match (subject)
Not match (subject)
Comment
worldHello worldHello JimMatch if the pattern is present anywhere in the subject
^worldworld classHello worldMatch if the pattern is present at the beginning of the subject
world$Hello worldworld classMatch if the pattern is present at the end of the subject
world/iThis WoRLdHello JimMakes a search in case insensitive mode
^world$worldHello worldThe string contains only the "world"
world*worl, world, worldddworThere is 0 or more "d" after "worl"
world+world, worldddworlThere is at least 1 "d" after "worl"
world?worl, world, worlywor, woryThere is 0 or 1 "d" after "worl"
world{1}worldworlyThere is 1 "d" after "worl"
world{1,}world, worldddworlyThere is 1 ore more "d" after "worl"
world{2,3}worldd, worldddworldThere are 2 or 3 "d" after "worl"
wo(rld)*wo, world, worldoldwaThere is 0 or more "rld" after "wo"
earth|worldearth, worldsunThe string contains the "earth" or the "world"
w.rldworld, wwrldwrldAny character in place of the dot.
^.{5}$world, earthsunA string with exactly 5 characters
[abc]abc, bbacccsunThere is an "a" or "b" or "c" in the string
[a-z]worldWORLDThere are any lowercase letter in the string
[a-zA-Z]world, WORLD, Worl12123There are any lower- or uppercase letter in the string
[^wW]earthw, WThe actual character can not be a "w" or "W"



Friday 25 February 2011

One of my favorite song


Elvis Presley -"Can’t Help Falling In Love"



Wise men say only fools rush in
But I can't help falling in love with you
Shall I stay
Would it be a sin
If I can't help falling in love with you

Like a river flows surely to the sea
Darling so it goes
Some things are meant to be
Take my hand, take my whole life too
For I can't help falling in love with you

Like a river flows surely to the sea
Darling so it goes
Some things are meant to be
Take my hand, take my whole life too
For I can't help falling in love with you
For I can't help falling in love with you

(words & music by george weiss - hugo peretti - luigi creatore)

Thursday 24 February 2011

Be careful while connecting a pen drive to your system !


It is easy to spread virus through pendrive ,
Precautions .
Press shift key when u connect pendive to your system. This will kill the autorun action.
Then open mycomputer and rightclick on the drive icon and select explore.
copy or paste the content and remove it
And there are other ways:
1) disable autorun globally,
2) use other than windows, operating system. 

Wednesday 23 February 2011

Sarabhai Institute of Science and Technology : This is my college

The High-tech engineering college named "SARABHAI INSTITUTE OF SCIENCE & TECHNOLOGY" is a self- financing institution established by the Space Engineers Welfare Society (SEWELS) with the approval from the Government of Kerala and affiliated to Cochin University of Science and Technology (CUSAT) .

Tuesday 22 February 2011

Generating PDF using Codeigniter


Hello friends , I have stated using codeigniter framework for php. I would recommended codeigniter for all PHP developers.
Recently i had a task to generate PDF file in my codeigniter project ,there are many libraries like FPDF, Panda, DOM-pdf, R&OS to generate PDF documents with PHP.
I found a method to integrate R&OS pdf class file with codeigniter. I am sharing you the same.
Step 1
Download latest version of Codeigniter framework.
Step 2
Download the class files for pdf integration from here. The rar folder contains 2 folders.
1. library class files
2. fonts
Extract files under class files folder to application/libraries/
Extract fonts directory to root folder of your CI application.
Step 3
Now into final stage . Create a controller named home.php and paste the following code.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {

 function __construct()
 {
 parent::__construct();
 }

 function index()
 {
 $this->hello_world();
 }

 function hello_world()
 {
 $this->load->library('cezpdf');

 $this->cezpdf->ezText('Hello World', 12, array('justification' => 'center'));
 $this->cezpdf->ezSetDy(-10);

 $content = 'The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog.
 Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs.';

 $this->cezpdf->ezText($content, 10);

 $this->cezpdf->ezStream();
 }

 function tables()
 {
 $this->load->library('cezpdf');

 $db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
 $db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
 $db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');

 $col_names = array(
 'name' => 'Name',
 'phone' => 'Phone Number',
 'email' => 'E-mail Address'
 );

 $this->cezpdf->ezTable($db_data, $col_names, 'Contact List', array('width'=>550));
 $this->cezpdf->ezStream();
 }

}

/* End of file welcome.php */
/* Location: ./application/controllers/home.php */



You are done .
Execute the code :
http://localhost/pdf/index.php/home/index – for basic pdf creation.
http://localhost/pdf/index.php/home/tables – for table creation.
Note: In Order to write the output as a .pdf file just change $this->cezpdf->ezStream(); to $this->cezpdf->ezOutput();
Complete Code :
create a folder named pdf in root directory of codeigniter project and replace the tables function in the above controller
[ home.php ] with the following.

function tables()
{
$this->load->helper('path');
$this->load->library('cezpdf');
 
$this->cezpdf->ezText('Hello World', 12, array('justification' => 'center'));
$this->cezpdf->ezSetDy(-10);
 
$db_data[] = array('name' => 'Jon Doe', 'phone' => '111-222-3333', 'email' => 'jdoe@someplace.com');
$db_data[] = array('name' => 'Jane Doe', 'phone' => '222-333-4444', 'email' => 'jane.doe@something.com');
$db_data[] = array('name' => 'Jon Smith', 'phone' => '333-444-5555', 'email' => 'jsmith@someplacepsecial.com');
 
$col_names = array(
'name' => 'Name',
'phone' => 'Phone Number',
'email' => 'E-mail Address'
);
 
$this->cezpdf->ezTable($db_data, $col_names, 'Contact List', array('width'=>550));
 
$directory = './pdf/';
set_realpath($directory);
 
$file = $directory.date('d-m-Y h:i:s').'.pdf';
 
$pdfcode = $this->cezpdf->ezOutput();
$fp = fopen($file,'wb');
fwrite($fp,$pdfcode);
fclose($fp);
}

You are done !