How to generate code for basic operations create update read and delete in symfony


Posted on 20 Sep 16 by Vickey

Like in others php frameworks we can generate basic code automatcally. For example if you have a database table and you want to write the code for  basic operation  ‘create ’, ‘Update’,’Read’ and ‘Delete’ you don not need to write code. We can create code automatically by using commands line. but for this first we need to create an entity and repository we can create this by using command lines.

Generate Entity

php bin/console doctrine:generate:entity

after generate entity we will create tables from entity

Create table into database using entity 

php bin/console doctrine:schema:update –force

this command create tables related to all entities

Now by using the below command we create code for basic operations

Generate Create, update read delete code (CRUD Operation)

php app/console generate:doctrine:crud

when process done you can see auto generated code in your project folder



How to run window based software on ubuntu

Ubuntu Desktop

Posted on 13 Aug 16 by Vickey

Today window is a very popular operating system. It is easy to use and every one can use it. There are many applications that are available only window based. So if you are using ubuntu ( Linux ) and you need to use an application that is not available on ubuntu then you can install that window application on ubuntu system by using “Wine Window Program Loader”. For this you need to install “wine” in your ubuntu system

Install Wine: For install wine go to your “Ubuntu Software Center” and in search box type "wine" and you will see wine installer in the list. By clicking on install button you can install wine and now you can install or execute exe file on ubuntu system. For execute a exe file right click on the file and select “Wine Window Program Loader”.

How to install symfony framework on Ubuntu


Posted on 02 Aug 16 by Vickey

Symfony is a very powerful and popular php framework. Many other php frameworks are based on symfony. In this blog we will learn to install symfony on a ubuntu system. There are two ways to iinstall symfony.

1. Install by using composer

2. Use symfony installer

Install by using composer : For install symfony by using composer first you need to install composer ( if not already installed ). Once you have install composer open your terminal and go to directory where you want to put your projects ( in web root directory)

For example 

vickey@vickey-HP-2000-Notebook-PC:~$ cd /opt/lampp/htdocs


when you are in your web root directory run the below command

vickey@vickey-HP-2000-Notebook-PC:/opt/lampp/htdocs$  composer create-project symfony/framework-standard-edition myblogs "3.1.*"

here 3.1 is symfony version which will be install. One the process complete you can see new symfony projects in your web root directrory. Now run server by using the below command

php bin/console server:run

and now you can access it by url

In other way we can istall it by using symfony installer

Use symfony installer : First need to install symfony installer. You can install it by using 

sudo curl -LsS -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony

Now you can install symfony project by using the below command

symfony new my_project_name




How to use models in a sub folder in yii1.x


Posted on 28 May 16 by Vickey

Some times we have two different types of models in our projects for example we have many models and some have prefis 'student' ( student_users ) and some have 'teacher' (teacher_users). So if you want to put these types of models in a different directory you can create a two subdirectory under your model directory and put your models here





Now you need to do some changes in your main.php file under 'protected/config'.  Open main.php file and seacrh  'import'=>'. you will see something like this



change it to




and now can load your models from different locations

How to use ajax pagination in cakephp


Posted on 12 Apr 16 by Vickey

Cakephp provide inbuilt pagination. By using Paginator component we can apply pagination very easily. For example

public $components = array('Paginator');

public function index() {

	$this->Blog->recursive = 0;
	$this->set('users', $this->Paginator->paginate());


and in view

<div class="pagination">

echo $this->Paginator->prev('< ' . __('previous'), array(), null, array('class' => 'prev disabled'));
echo $this->Paginator->numbers(array('separator' => ''));
echo $this->Paginator->next(__('next') . ' >', array(), null, array('class' => 'next disabled'));


But when we click on any page number the whole page will be refresh again with new records.  If you dont want to reload page you can fetch all record by using ajax. There is no need to change any code. For load pages by ajax add the below javascript code.

   $(".pagination a").click(function(){
         return false;


How to install PHP Syntax Checker package in sublime


Posted on 31 Mar 16 by Vickey

Sublime is a light weight and popular text editor. Sublime support many programming languages. In sublime we have highlighted code for each language but by default sublime can not catch the error in your code. If you want to make sure that your code is error free in development process then you need to use Sublime Linter. By using Sublime Linter you can install a package for check any error in your code. You can install this package by following these below steps.

1. Open your sublime text and go to menu >> View >> Show console and paste the below code in sublime console and press Enter

import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88';pf = 'Package Control.sublime-package';ipp = sublime.installed_packages_path();urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) );by = urllib.request.urlopen( '' + pf.replace(' ', '%20')).read();dh = hashlib.sha256(by).hexdigest();print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

After complete this process a pop up will come. Press OK on pop up.

2. Now Press ctrl + shift + p and you will see a popup

3. In this pop up search 'install package' and click on it and again a popup open

4. Now search 'sublimeLinter-php'  and click on it. After complete process restart sublime Text and now you can catch your error in editor when you type.

How to use queries in pdo way with laravel


Posted on 21 Mar 16 by Vickey

Laravel provide us powerful interface for building SQL queries. We can use a query by using table method.

$myRowQuery = DB::table('users');

Laravel provide other method also 

$userData = DB::first('select * from users where id = 1199');

But in some cases we need to use our row query in pdo way. In laravel we can do this very easily. By getting pdo database connection we can use mysql queries in pdo way. Here are some example

Get pdo database conection

$databaseConection 	= 	DB::connection()->getPdo();
$queryStatement = 	$databaseConection->prepare("SHOW TABLES");
$tables 	= $queryStatement->fetchAll();

For fetch data from a table

$tables = 	$queryStatement->fetchAll();
$queryStatement = $databaseConection->prepare("select * from users where email = :email");
$queryStatement->execute(array(':email' => ""));
$row = $queryStatement->fetch();

Insert record in a table

$queryStatement = $databaseConection->prepare("insert into users (email) values (:email)");
$queryStatement->execute(array(':email' => ''));


How to use nexmo sms gateway in cakephp


Posted on 09 Mar 16 by Vickey

SMS gateway is used to send text messages from web page to mobile. Many SMS Gateway company provide this functionality by their apis. By using these apis we can send sms from our web pages on a single click. We use this service for send otp and notify our users. There are many SMS Gateway in the market. One of them is nexmo. For using the nexmo apis we need to create an account on nexmo and it provide us api_key and api_secret which used in apis for Authentication. Before start  you need to add and verify your mobile number and a test mobile number. you can add your test mobile number by using this url

Here i am using nexmo api with cakephp

First of all we need to download nexmo api SDK from its website. After download  put it in to  'app/vendor' directory and import it in 'AppController'

App::import('Vendor', 'Nexmo', array('file' => 'Nexmo/NexmoMessage.php'));

Now write a function in AppController

protected function _nexmoSendMessage($from = null, $to = null, $text = null)
	try {
		$url = '';
		$queryParam = array(
			'api_key' => 'api_key',
			'api_secret' => 'api_secret',
			'from' => $from,
			'to' => $to,
			'text' => $text
		$urlQueryString = $url . http_build_query($queryParam);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $urlQueryString);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // Receive server response
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);
		$responseData = curl_exec($ch);
		if (curl_error($ch)) {
			throw new Exception(curl_error($ch));
		curl_close ($ch);
		$data = json_decode($responseData, true);
		if (!isset($data['messages'])) {
			throw new Exception('Unknown API Response.');
		foreach ($data['messages'] as $message) {
			if ($message['status'] != 0) {
				throw new Exception($message['error-text']);
	} catch(Exception $e) {
		CakeLog::write('nexmo_sms_gateway_error_log', $e->getMessage());

add your api_key and api_secret

Now use this function in your app where you want send message

public function send(){

	$this->_nexmoSendMessage($from, $to, $text);


How to use Auth login in cakephp


Posted on 25 Feb 16 by Vickey

Cakephp make our project development very fast. There are many inbuilt functionalities or components. By using these functionalities or functions we can do more in less code if we know about those functionalities very well. Some times we know about the functions or components  but don't know how to use it. For example 'Auth' component. Many new comers in Cakephp don't know how to use it. They make a little mistake and auth login not work properly. Here I will explain and create a simple Auth login in Cakephp.

First of all we need add 'Auth' component in component list. Here I am using it in 'AppController' so that it will work in whole application.

class AppController extends Controller {

	public $components = array('Session','Auth');


By default it will use 'User' Model and login fields 'username' and 'password'. But if we are doing some different we can use

public $components = array('Session','Auth' => array(

	'authenticate' => array(

		'Form' => array( 

			'userModel' => 'User',

        	'fields' => array(

                'username' => 'email',
                'password' => 'password'
			#'scope' => array('is_active' => '1')

By using 'Auth' component we can not access any method with out login. But we need to access login and register actions without logged in. So we can access these by using below code in our controller

public function beforeFilter() {



Second step Encrypt your password by using AuthComponent. We will save encrypted password in our database table. So we will encrypt it before save in database by using the below code in our Model.

public function beforeSave($options = array()) {
    if (isset($this->data[$this->alias]['password'])) {
        $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
    return true;

Now when any user will be register, his password will be save in encrypted form. After register a user we will try to login by using 'Auth' component. For login add the below code in your controller

public function login() {
			$this->redirect(array('controller'=>'pages','action' => 'home'));
			$this->Session->setFlash(__('Invalid username or password, Please try again.', null),  'default', 
			array('class' => 'errorDisplay'),'login');

For logout

public function logout() {
	$this->redirect(array('controller'=>'users', 'action'=>'login'));

Now create a login form for login action in 'app/users/login.ctp

<div class="users form">
<?php echo $this->Form->create('User'); ?>
		<legend><?php echo __('Login'); ?></legend>
		<?php echo $this->Session->flash('login'); ?>
		echo $this->Form->input('email');
		echo $this->Form->input('password');
<?php echo $this->Form->end(__('Submit')); ?>

Now you can access login page and login by using URL "your base url"/users/login'

How to install and upload source code on Github


Posted on 12 Feb 16 by Vickey

GitHub is the best place where we can share our code with friends and others programmers. It provide us best code management functionality. On GitHub  every developer can share code. Here you can show your skills. On GitHub by using we can control over code version by committing code on Git. GitHub is a web based Git repository hosting service. GitHub is a largest code hosting service. In this tutorial we will install Git and commit code on GitHub step by step. Here I am using Ubuntu operating system.

1. First of all open your terminal and locate in a directory where you want to crate local repository

vickey@vickey-System:~$ cd /home/Desktop


2. Now use the following command to create local repository

vickey@vickey-System:~/Desktop$ git init PHP

when repository created you will see the below line in your terminal

Initialized empty Git repository in /home/vickey/Desktop/PHP/.git/

It will create a new directory with name "PHP"

3. Now change your directory

vickey@vickey-System:~/Desktop$ cd PHP

4. Here with the below command  create a README file where you will describe about the repository

vickey@vickey-System:~/Desktop/PHP$ gedit README

I used gedit editor you can use other editor. Write your content in the file and save the file

5. This is the important part of this tutorial here we will add our code and files which we will push on GitHub. For now here I am creating a file name as info.php with the below code.


Now we have two files in "PHP" directory 'README' and 'info.php'

6. Now index these files by using the below commands

vickey@vickey-System:~/Desktop/PHP$ git add README
vickey@vickey-System:~/Desktop/PHP$ git add info.php

This git add command will be used for every file which you have in your directory

7. After files added we will commit these on server

vickey@vickey-System:~/Desktop/PHP$ git commit -m "your message here"

8. Now login your GitHub account and create repository with the name same as you have on your local system. Once you have done run the below command in your terminal. Note that 'vickey' is the GitHub account username please change it first.

vickey@vickey-System:~/Desktop/PHP$ git remote add origin

9. And in last push your code on server

vickey@vickey-System:~/Desktop/PHP$ git push origin master

Username for '': vickey
Password for '': 
 * [new branch]      master -> master