SynapseIndia Technologies

SynapseIndia is working on various technologies through which it help clients in achieving their business goals with innovative solutions


php development company in noida

PHP Web Application Development Benefits

SynapseIndia Technology 3

PHP is one of the popular languages in web application development.
The extensions available in PHP offer a wide range of functionality and enhancement when compared to other web scripting language.
If you are looking for simplicity, speed and economic development then PHP is the best option for web application development.

Video :



SynapseIndia Technologies: Zend Development

SynapseIndia technologies include Zend Development Services. Zend framework in an open source, PHP based and object-oriented framework. It is based on the MVC pattern.

SynapseIndia Technologies

Shamit Khemka, Managing Director of SynapseIndia, says “Zend is a framework that is known for its simplicity. It helps in building PHP web applications with more ease and less trouble.”

We have a team of well trained Zend developers that have helped the company to finish multiple projects on Zend framework. Our all the projects are quality tested before handing them over. We are also a Shopify certified partner.

Get complete details about SynapseIndia Technologies and services that we offer at :

SynapseIndia Technologies and Services: PHP Development

SynapseIndia Technologies like PHP Development are highly popular among clients worldwide. We offer a diverse range of PHP development services. PHP is an open source, server-side, HTML embedded scripting language used to create dynamic web pages.


Shamit Khemka, Founder of SynapseIndia, says “The main benefits of choosing PHP for web development is that it supports all of the leading databases, including MySQL, debase, InterBase, ODBC, PostgreSQL, SQLite and more.”

Our team consists of skilled and well trained PHP developers. We have completed multiple projects on PHP Development.

Know more about SynapseIndia Technologies and services that we offer at:

SynapseIndia Technologies – Joomla Development Services

SynapseIndia Technologies

Synapsendia Technologies like Joomla help to provide world class Content Management Services, to our clients worldwide.

Under the guidance of Shamit Khemka Founder of SynapseIndia, has reached new level of excellence in Joomla Development services.

We have a team of highly experienced and dedicated employees, that help to provide quality services, when it comes to Joomla Development services. To know more about SynapseIndia Technologies and services, visit us at

SynapseIndia Technologies & Services – Magento eCommerce Development

SynapseIndia technologies like Magento help us delivering world-class eCommerce solutions for our clients across the globe. Founded by Shamit Khemka, SynapseIndia brings years long expertise in offering a wide range of web & mobile development services.


Magento, the open source PHP based e-commerce platform, helps build & manage a rich-featured online store. Magento is perfect eCommerce platform because of its features of being extremely flexible and scalable.
For more information about SynapseIndia technologies and services, visit our official website:

SynapseIndia Technologies for PHP development

SynapseIndia technologies like PHP enable our team to transform your ideas into world-class digital solutions.


Founded by Shamit Khemka, SynapseIndia offers a wide array of PHP development services. We have a strong team of PHP developers who bring years long expertise & experience in working on various PHP platforms including Joomla, WordPress, Drupal, CakePHP, Magento and more.
PHP is a robust and widely used server-side programming language for website development.
For more information about SynapseIndia technologies and services, visit our official website:

SynapseIndia Technologies & Services – Laravel (PHP) Development

SynapseIndia technologies like Laravel (PHP) enable our team to deliver world-class & highly effective solutions for our clients globally.
SynapseIndia is a globally recognized IT solution & services provider company in Noida, India. We also specialize in providing Laravel Web Development services to the clients worldwide as per their unique business requirements.
With the help of our team of Laravel Developers who bring profound skills and expertise in developing robust and scalable solutions, we have helped several businesses with top-notch solutions.

SynapseIndia technologies & domain expertise deliver unique and innovative technology solutions that fit to unique requirements & business needs of our clients.

Read more about SynapseIndia Technologies at: 

SynapseIndia Technologies – Zend Development

We use innovative & secure SynapseIndia technologies for development of high quality solutions.
When it comes to Zend web development, we are simply one of the best service providers. Our professionals bring extensive experience & expertise in all PHP based technologies including Zend.
SynapseIndia provides comprehensive range of Zend services & solutions for businesses of all sizes. Highly encompassing framework and a team of experienced Zend developers assure one-of-a-kind & flawless end solution.
To know in detail about SynapseIndia technologies and offerings, you can visit our official website.
Read more about SynapseIndia Technologies at:  

SynapseIndia Technologies – OpenCart Development

SynapseIndia technologies like OpenCart help businesses to setup their online presence. OpenCart PHP based eCommerce lightweight platform, which can easily be downloaded and hosted.

SynapseIndia technologies.jpg

At SynapseIndia, the globally recognized IT company in Noida, India, we have separate expert available for OpenCart development process. Our experienced professionals deliver quality solutions for the clients across the globe. We strive to offer superior level of satisfaction to our clients.
Visit our official website to take a closer look at the benefits that come out of employing OpenCart Development as a shopping cart solution. Also, find out about many other SynapseIndia technologies.
Read more about SynapseIndia Technologies at:  

SynapseIndia Technologies – Laravel Development Services

SynapseIndia technologies for development like Laravel offers the breadth for agile software application development which are scalable. SynapseIndia, the globally acknowledged IT company in Noida is the best in creating custom web apps that are consistent & maintainable.

SynapseIndia technologies.jpg

Laravel is modern, elegant, fast, easy to use and highly secure because of its flexibility while comparing with other frameworks.

At SynapseIndia, we have highly skilled laravel developers for developing top notch websites. Our laravel development process is controlled by highly experienced developers. Read more about SynapseIndia Technologies & services on our official website.

Read more about SynapseIndia Technologies at:

SynapseIndia Technologies Used for PHP Website Development

SynapseIndia technologies expertise has been helping businesses reach their full potential over the period of more than 15 years. Premier IT outsourcing company is considered amongst one of the best services providers when it comes to PHP website development.
PHP technologies used for development of websites & web applications include Zend, CakePHP, Magento, CodeIgniter, Joomla, WordPress, Drupal and more.
 SynapseIndia Technologies.jpg
At SynapseIndia, we encourage technology innovation and high quality work. We are committed to provide value to our clients through our solutions. To know more about PHP development services or SynapseIndia technologies expertise in detail, you can visit our official company website.
Read more about SynapseIndia Technologies at:

SynapseIndia Php Development -date function

While PHP’s date() function may seem to have an overwhelming amount of options available, isn’t it always better to have more choices than not enough? With PHP’s date function you format timestamps, so they are more human readable.

This lesson will teach you how to display the current time, formating PHP’s timestamp, and show you all the various date arguments for reference purposes.

php date – the timestamp

The date function always formats a timestamp, whether you supply one or not. What’s a timestamp? Good question!

  • Timestamp: A timestamp is the number of seconds from January 1, 1970 at 00:00. Otherwise known as the Unix Timestamp, this measurement is a widely used standard that PHP has chosen to utilize.

what time is it?

The date function uses letters of the alphabet to represent various parts of a typical date and time format. The letters we will be using in our first example are:

  • d: The day of the month. The type of output you can expect is 01 through 31.
  • m: The current month, as a number. You can expect 01 through 12.
  • y: The current year in two digits ##. You can expect 00 through 99

We’ll tell you the rest of the options later, but for now let’s use those above letters to format a simple date! The letters that PHP uses to represent parts of date and time will automatically be converted by PHP.

However, other characters like a slash “/” can be inserted between the letters to add additional formatting. We have opted to use the slash in our example.

PHP Code:

echo date("m/d/y"); 

If the 2010 Winter Olympics were just finishing up, you would see something like:



Be sure to test this out on your own PHP enabled server, it’s really great to see the instant results available with PHP date!

supplying a timestamp

As our first example shows, the first argument of the date function tells PHP how you would like your date and time displayed. The second argument allows for a timestamp and is optional.

This example uses the mktime function to create a timestamp for tomorrow. To go one day in the future we simply add one to the day argument of mktime. For your future reference, we have the arguments of mktime.

Note: These arguments are all optional. If you do not supply any arguments the current time will be used to create the timestamp.

  • mktime(hour, minute, second, month, day, year, daylight savings time)

PHP Code:

$tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));
echo "Tomorrow is ".date("m/d/y", $tomorrow); 

Notice that we used one letter at a time with the function date to get the month, day and year. For example the date(“m”) will return the month’s number 01-12.

If we were to run our new script just after the 2010 Winter Olympics our display would look like:


Tomorrow is 02/28/10

php date – reference

Now that you know the basics of using PHP’s date function, you can easily plug in any of the following letters to format your timestamp to meet your needs.

Important Full Date and Time:

  • r: Displays the full date, time and timezone offset. It is equivalent to manually entering date(“D, d M Y H:i:s O”)


  • a: am or pm depending on the time
  • A: AM or PM depending on the time
  • g: Hour without leading zeroes. Values are 1 through 12.
  • G: Hour in 24-hour format without leading zeroes. Values are 0 through 23.
  • h: Hour with leading zeroes. Values 01 through 12.
  • H: Hour in 24-hour format with leading zeroes. Values 00 through 23.
  • i: Minute with leading zeroes. Values 00 through 59.
  • s: Seconds with leading zeroes. Values 00 through 59.


  • d: Day of the month with leading zeroes. Values are 01 through 31.
  • j: Day of the month without leading zeroes. Values 1 through 31
  • D: Day of the week abbreviations. Sun through Sat
  • l: Day of the week. Values Sunday through Saturday
  • w: Day of the week without leading zeroes. Values 0 through 6.
  • z: Day of the year without leading zeroes. Values 0 through 365.


  • m: Month number with leading zeroes. Values 01 through 12
  • n: Month number without leading zeroes. Values 1 through 12
  • M: Abbreviation for the month. Values Jan through Dec
  • F: Normal month representation. Values January through December.
  • t: The number of days in the month. Values 28 through 31.


  • L: 1 if it’s a leap year and 0 if it isn’t.
  • Y: A four digit year format
  • y: A two digit year format. Values 00 through 99.

Other Formatting:

  • U: The number of seconds since the Unix Epoch (January 1, 1970)
  • O: This represents the Timezone offset, which is the difference from Greenwich Meridian Time (GMT). 100 = 1 hour, -600 = -6 hours

We suggest that you take a few minutes to create several timestamps using PHP’s mktime function and just try out all these different letters to get your feet wet with PHP’s date function.

SynapseIndia Php Development – Functions

A function is just a name we give to a block of code that can be executed whenever we need it. This might not seem like that big of an idea, but believe me, when you understand and use functions you will be able to save a ton of time and write code that is much more readable!

For example, you might have a company motto that you have to display at least once on every webpage. If you don’t, then you get fired! Well, being the savvy PHP programmer you are, you think to yourself, “this sounds like a situation where I might need functions.”

Tip: Although functions are often thought of as an advanced topic for beginning programmers to learn, if you take it slow and stick with it, functions can be just minor speedbump in your programming career. So don’t give up if functions confuse you at first!

creating your first php function

When you create a function, you first need to give it a name, likemyCompanyMotto. It’s with this function name that you will be able to call upon your function, so make it easy to type and understand.

The actual syntax for creating a function is pretty self-explanatory, but you can be the judge of that. First, you must tell PHP that you want to create a function. You do this by typing the keyword function followed by your function name and some other stuff (which we’ll talk about later).

Here is how you would make a function called myCompanyMotto. Note: We still have to fill in the code for myCompanyMotto.

PHP Code:

function myCompanyMotto(){

Note: Your function name can start with a letter or underscore “_”, but not a number!

With a properly formatted function in place, we can now fill in the code that we want our function to execute. Do you see the curly braces in the above example “{ }”? These braces define where our function’s code goes. The opening curly brace “{” tells php that the function’s code is starting and a closing curly brace “}” tells PHP that our function is done!

We want our function to print out the company motto each time it’s called, so that sounds like it’s a job for the echo command!

PHP Code:

function myCompanyMotto(){
    echo "We deliver quantity, not quality!<br />";

That’s it! You have written your first PHP function from scratch! Notice that the code that appears within a function is just the same as any other PHP code.

using your php function

Now that you have completed coding your PHP function, it’s time to put it through a test run. Below is a simple PHP script. Let’s do two things: add the function code to it and use the function twice.

PHP Code:

echo "Welcome to <br />";
echo "Well, thanks for stopping by! <br />";
echo "and remember... <br />";

PHP Code with Function:

function myCompanyMotto(){
    echo "We deliver quantity, not quality!<br />";
echo "Welcome to <br />";
echo "Well, thanks for stopping by! <br />";
echo "and remember... <br />";


Welcome to
We deliver quantity, not quality!
Well, thanks for stopping by!
and remember…
We deliver quantity, not quality!

Although this was a simple example, it’s important to understand that there is a lot going on and there are a lot of areas to make errors. When you are creating a function, follow these simple guidelines:

  • Always start your function with the keyword function
  • Remember that your function’s code must be between the “{” and the “}”
  • When you are using your function, be sure you spell the function name correctly
  • Don’t give up!

php functions – parameters

Another useful thing about functions is that you can send them information that the function can then use. Our first function myCompanyMotto isn’t all that useful because all it does, and ever will do, is print out a single, unchanging string.

However, if we were to use parameters, then we would be able to add some extra functionality! A parameter appears with the parentheses “( )” and looks just like a normal PHP variable. Let’s create a new function that creates a custom greeting based off of a person’s name.

Our parameter will be the person’s name and our function will concatenate this name onto a greeting string. Here’s what the code would look like.

PHP Code with Function:

function myGreeting($firstName){
    echo "Hello there ". $firstName . "!<br />";

When we use our myGreeting function we have to send it a string containing someone’s name, otherwise it will break. When you add parameters, you also add more responsibility to you, the programmer! Let’s call our new function a few times with some common first names.

PHP Code:

function myGreeting($firstName){
    echo "Hello there ". $firstName . "!<br />";


Hello there Jack!
Hello there Ahmed!
Hello there Julie!
Hello there Charles!

It is also possible to have multiple parameters in a function. To separate multiple parameters PHP uses a comma “,”. Let’s modify our function to also include last names.

PHP Code:

function myGreeting($firstName, $lastName){
    echo "Hello there ". $firstName ." ". $lastName ."!<br />";
myGreeting("Jack", "Black");
myGreeting("Ahmed", "Zewail");
myGreeting("Julie", "Roberts");
myGreeting("Charles", "Schwab");


Hello there Jack Black!
Hello there Ahmed Zewail!
Hello there Julie Roberts!
Hello there Charles Schwab!

php functions – returning values

Besides being able to pass functions information, you can also have them return a value. However, a function can only return one thing, although that thing can be any integer, float, array, string, etc. that you choose!

How does it return a value though? Well, when the function is used and finishes executing, it sort of changes from being a function name into being a value. To capture this value you can set a variable equal to the function. Something like:

  • $myVar = somefunction();

Let’s demonstrate this returning of a value by using a simple function that returns the sum of two integers.

PHP Code:

function mySum($numX, $numY){
    $total = $numX + $numY;
    return $total; 
$myNumber = 0;
echo "Before the function, myNumber = ". $myNumber ."<br />";
$myNumber = mySum(3, 4); // Store the result of mySum in $myNumber
echo "After the function, myNumber = " . $myNumber ."<br />";


Before the function, myNumber = 0
After the function, myNumber = 7

When we first print out the value of $myNumber it is still set to the original value of 0. However, when we set $myNumber equal to the function mySum, $myNumber is set equal to mySum’s result. In this case, the result was 3 + 4 = 7, which was successfully stored into $myNumber and displayed in the second echo statement!

php functions – practice makes perfect

If you are new to programming, then this lesson might or might not seem like overkill. If you are having a hard time understanding lessons, the best piece of advice would be to do your best the first time, then be sure to come back tomorrow and next week and see if it makes anymore sense. Chances are, after going through this tutorial more than once, with breaks in between, this topic will be mastered.

SynapseIndia Php Development String Concatenation

Another important point is string concatenation. Often times you’ll need to concatenate strings together, and the easiest way of doing it is with a dot. For instance:

echo "Hello" . "World\n";


$x = 10;
$y = 20;
echo $x + $y . "\n";

The above code first adds x with y, then converts the result into a string, and then concatenate it with the “\n” string, effectively printing out 30 with a newline after it.

PHP comes with a huge amount of built-in string functions. You can check all them on the official PHP manual. For instance, there are functions to find the length of a string, to search for specific characters inside it, and pretty much anything else you might need.

SynapseIndia Sending Email from your PHP Development Applications

Communicating with website users via email is crucial to the success of any online service. The ability to deliver registration confirmations and newsletters, provide a convenient and relatively secure password recovery tool, and keep clients updated with shipping status reports are just a few of the reasons for incorporating email-based features into your website infrastructure. In this tutorial, I’ll show you how to incorporate email delivery capabilities into your PHP applications via both its native mail command and a great third-party extension called HTML Mime Mail. I’ll conclude the article with a few pointers regarding how to most efficiently carry out bulk email delivery.

The mail() Function

Sending email via a PHP script is easy because PHP offers a native function called mail(). It accepts five parameters, three of which are required and the other two optional. The required parameters include the intended recipient, subject, and message. The optional parameters include additional mail headers and execution options for the mail delivery service. On Unix-based systems this service is by default Sendmail, although you can use other email services such as postfix or qmail, provided that you use sendmail wrappers available to each package. You can specify the location of this service by modifying the configuration directivesendmail_path. On Windows-based systems PHP requires the address of an SMTP server, specified with the SMTP configuration directive. The mail() function looks like this:
   $to = "";
   $from = "";
   $title = "Support subscription confirmation";
$body = <<< emailbody
Dear subscriber,

This email confirms your purchase of a 30 day
email support subscription. Please direct all 
requests to

Thank you,
The support staff

   $success = mail($to,$from,$title,$body,
When taking advantage of the addl_headers parameter, keep in mind you’ll need to Note that if you neglect to include the From header, the email will be sent by the Web server daemon owner. When using the Apache Web server, it’s standard practice to use the user nobody or create a new user named apache or www for specifically this purpose. Therefore the above email sender address might look something like or Therefore, be sure to set this header value to lessen the possibility of confusion or accidental spam filtering.
The mail() function works great when you want to send just a simple email. However what about sending to multiple recipients? Sending HTML mail? Also, what about sending attachments? While you could use mail(), additional headers, and some additional programming to perform such tasks, there’s another readily available solution that I’d like to introduce.

HTML Mime Mail

HTML Mime Mail is a very useful PHP class created and maintained by Richard Heyes ( Available for free download and use under the BSD license, it’s a fantastic class for sending MIME-based email. Offering an intuitive OOP syntax for managing email submissions, it’s capable of executing all of the email-specific tasks discussed thus far, in addition to features such as handling attachments, sending plain-text emails, and sending HTML emails with embedded images. In this article I’ll show you how to take advantage of this great tool.

SynapseIndia ExpressionEngine Enhances PHP Development Content Management with Framework Flexibility

ExpressionEngine Defined

Although ExpressionEngine is considered the latest significant entry to the crowded PHP content management system market, the company behind ExpressionEngine is anything but inexperienced when it comes to developing powerful software. In fact, EllisLab is the creator of pMachine, which was one of the first PHP-driven content management systems and was the precursor to ExpressionEngine. They also created and lead the CodeIgniter project, one of the world’s most popular open source web frameworks. However, you don’t need any prior knowledge of CodeIgniter in order to begin using ExpressionEngine, or even of PHP for that matter. You can build a fairly powerful web site using the content management tools made available through its web-based interface.
ExpressionEngine does differ significantly from other leading PHP content management systems in its licensing. Although a free version is available (known as the Core License), you can use it only in conjunction with “personal, non-commercial, and non-profit activities.” For commercial purposes, you’ll need to purchase a commercial license, which currently runs $249.95. Frankly, I found this a small price to pay given the significant time that key ExpressionEngine features saved me. These features are discussed in detail next.

Key ExpressionEngine Features

Hundreds of features are bundled into ExpressionEngine (itemized here), however I found a few particularly striking as compared with what other solutions offer.

Intuitive Content Management

ExpressionEngine treats all content as a Weblog, pure and simple. Therefore, if you were tasked with creating a site that cataloged information about books, DVDs, and video games, you would probably create three Weblogs, one for each product type. Of course, each Weblog would consist of custom fields specific to the content it tracks. For instance, each book entry would probably contain fields used to represent the book’s title, ISBN, author, page count, publication date, price, and table of contents. ExpressionEngine allows you to easily customize these fields for each Weblog, defining not only the field title but also the type of form control that should be used to manage the data. Figure 1 depicts just such a set of fields for a book-related Weblog.

ExpressionEngine Enhances PHP Content Management with Framework Flexibility
Click here for larger image

Figure 1. Customizing Weblog Fields

A Flexible Templating Engine

When you’ve defined the Weblog fields and added a few entries, you can create the templates, which will format each Weblog entry within the web site. This is accomplished using a highly intuitive template engine, which allows you to refer to the Weblog field names (see Figure 1) within your templates, as demonstrated below:


By: {authors}
Publication Date: {entry_date format=”%F %d, %Y”}
{if isbn != “”} ISBN: {isbn}
{/if} {if pages != “”} Pages: {pages} {/if}


Rendering this template to the browser produces output similar to Figure 2.

ExpressionEngine Enhances PHP Content Management with Framework Flexibility
Click here for larger image

Figure 2. Rendering an ExpressionEngine Template
These templates are managed within a web-based console (see Figure 3), and can be easily configured to rely upon a unified page header, footer, and context-specific sub-templates, such as sidebars.

ExpressionEngine Enhances PHP Content Management with Framework Flexibility
Click here for larger image

Figure 3. Managing ExpressionEngine Templates Through the Web-based Management Console
Finally, if the native template tag capabilities don’t suffice, you are free to integrate both PHP and custom SQL queries into your templates, stretching the boundaries of content management as far as you’d like them to go.

SynapseIndia Php Development- Yii2

Programming with Yii2: Getting Started

This tutorial will walk you through installing Yii 2.0, setting up your local development environment, building a simple Hello World application, setting up your remote production environment for hosting and deploying your code from a GitHub repository.

You can find detailed installation instructions here; I’ll walk you through the basics for a typical Mac OS X development environment. Yii 2.0 has a Definitive Guide (PDF) and a Class Reference which cover every detail of Yii. ca

Yii2 requires Composer, a popular dependency manager for PHP. If you don’t already have Composer installed, do the following:

Then, use Composer to install Yii2. The installation request requires that you use your own Github account credentials; sign up if you don’t have an account.

Let’s call this first project, “hello”:

Yii2 provides two different installation templates depending on the type of application you’re developing: basic and advanced. For this tutorial, we’ll use the basic application which is installed by default. The advanced application template provides a front-end, back end and console access points for a more advanced web application, like a WordPress blog, it’s administrative dashboard and background cron tasks.

I’m using free, open source MAMP for OS X for my LAMP development. Make sure MAMP is running and its web and database servers are active. Then, create a symlink for MAMP to your Sites app directory:

Then, visit http://localhost:8888/hello/web. You should see the Yii2 basic application template running with Bootstrap 3.x.

Yii2 Newly Installed Basic Application Template

That page will likely excite Yii 1.1 developers who’ve not had pre-configured support for the latest version of Bootstrap, the outstanding open source responsive CSS framework that’s taken over quite a bit of the web.

One of the most important features of the Yii Framework is that it provides a Model View Controller for PHP. Not only does this provide a more structured programming environment and easier to understand code, it simplifies a number of things that are difficult to do in PHP, like security and automated code generation. It also makes our code easier to extend and more reusable.

With a Yii application, we direct all traffic to a single file: /web/index.php file. This built-in file loads Yii, any dependencies, and then runs your application.

By default, this is the Index method in /controllers/SiteController.php:

Generally, controllers are full of methods, but with minimal code like above. Controllers manage access, leverage models and render views. The bulk of intelligence should be built into your models and the views should generally produce relatively simple template operations.

By default, Yii will render /views/layouts/main.php around your index view in/views/site/index.php. The main.php layout provides the HTML and CSS structure to the page, e.g. the toolbar and content area. Inside main.php, you’ll see a brief call out to the content:

That $content variable will be replaced with the generated code from/views/site/index.php, which currently is static HTML code that generates theCongratulations! page shown above.

First, let’s enable Yii2’s pretty URLs with mod_rewrite. On the Yii home page, if you click on the About menu option, the URL will be something like http://localhost:8888/hello/web/index.php?r=site%2Fabout. We’d like to change that to http://localhost:8888/hello/web/site/about.

The config subdirectory includes environment configurations for your web and console applications as well as the future database settings. Edit /config/web.php to add urlManagement to the current web application. Add the following urlManagersection within the components array:

Then, create an .htaccess file within /web where the primary index.php file exists:

Make sure mod_rewrite is running locally on MAMP; if not, check out this Stack Overflow guide.

In your browser, visit this URL: http://localhost:8888/hello/web/site/about. You should see the Yii application About page and clicking on other menu options should bring up pretty URLs.

Next, we’ll add a controller action called Say to repeat a target message of our choosing. In /controllers/SiteController.php, add the following action:

This will look for a URL parameter called target to echo to the screen. If there is no target parameter, it will say repeat “World”. In Yii, actions are defined as a method named with the prefix “action” followed by the action name. In this SiteControllerclass, we use public function actionSay. Yii uses the prefix “action” to differentiate action methods from other methods.

The default behavior of the render method will look for a file in views/ControllerID/ViewName.php. So, in /views/site/, create a say.phpview file:

This is the template view file to repeat static HTML tag h1 with Hello followed by the target variable. Note: We encode the target variable to secure the URL parameter argument from malicious code.

If you visit the url, http://localhost:8888/hello/web/site/say?target=Tuts%20Readers, you should see this:

Hello Tuts Readers

That’s a very basic example of the Yii2 Model View Controller. You can read through a more thorough description of the Hello World demonstration and Yii2 MVC here.

Now, let’s set up our application with GitHub and deploy it to a production server.

The basic Yii application should run fine out of the box with Apache or an Nginx, I’ll provide instructions for Apache and you can find instructions for Nginx here.

Once I set up a Yii application template, I create a repository at Github:

Create a New Repository at Github

Note: It’s a bit simpler initially to copy and paste the Yii2 .gitignore from GitHub to your local ~/Sites/hello/.gitignore file rather than create the site with it remotely and have to merge it locally, but either approach is fine.

I’ve been using the Mac OS X GitHub app more frequently but you can also use the command line to initialize the repository. Below, I’m following the instructions for adding an existing project to GitHub using the command line (replace “youraccount” with your GitHub account name):

If you don’t already have a LAMP server or cloud instance, follow my generic Ubuntu installation instructions to get started. Once you have your IP address, modify your DNS records to have an A record point to your server.

Then, log in to your server either via IP address or domain name:

Update the configuration, install Git, enable mod_rewrite for Apache and mcrypt for PHP:

Now, we’ll set up a user for pulling code from Github that can be served by Apache. First, install git on your server.

Then, we’ll create a group for www, add www-data and GitHub users to it and grant it ownership of our web directories.

Next, we create a key for the user that we share with GitHub for keeping code in sync:

You’ll see something like this, which you need to copy and paste to

Your Github Key

Visit the Settings page for your GitH soundub repository under keys, and add this key to your repository:

Once you add it, you’ll see it listed here:

Finally, you can clone the tree to your production server:

If you’re GitHub access is properly configured, it should look like this (if not, review this):

Git Clone

As you extend the codebase with this tutorial series and push updates from your local machine, you’ll be able to sync them on your remote production server with git pull. This is simpler than pulling down a tarball or syncing code manually – and will become more useful as this tutorial series continues with later modules.

Create an Apache site configuration file:

Customize this configuration for your domain name:

Enable your site:

Visit! and you should see your application running on your domain without the Yii2 debug toolbar at the bottom like this:

Production Server Hello World Application

SynapseIndia Php Development- Dribbble API

Using the Dribbble API with PHP

The GitHub Project

It might have taken a while, but two weeks ago I finally got into GitHub. For those not familiar, GitHub is a site focused on the version control system Git, and allows. It’s not the only place that you can get hosted Git repositories from (e.g. Beanstalk), but it does have a much more open-source friendly environment. It’s no coincidence that their tagline is “Social Coding”.

As part of my orientation to GitHub, I wanted to contribute something to an existing project. As it turned out, Martin Bean’s Dribbble PHP wrapper was a brilliant candidate. Martin had already done a substantial amount of work in getting the raw JSON data into a workable format. I decided to help out and add in support for comments, rebounds, and some updated examples. This tutorial is the finishing touch.

Github Octocat

Dribble API in PHP

Dribbble has a nicely documented API. Unfortunately for some, it only documents the API’s output, which means that you’d have to do some work on your own to get it to working on a project. On the bright side, finding a library for your language is not hard. In this tutorial, we’ll walk through a couple examples using the Dribbble PHP project hosted on GitHub.

As part of my GitHub update, I included formatted example pages that cover most of the regular API activity. This includes displaying rebounds, comments, and a number of the preset feeds given by Dribbble. If you download the source files and look at the examples, getting started should be straightforward. For the average person, displaying their account’s last five shots is perfectly fine.

Preset Dribbble Feeds

General Installation

Note: All of these instructions are based on the version available as of November 1, 2010. If you’re reading this in the future, things may look different. That’s technology for you.

To start off, make sure that you’ve downloaded the most recent version from the project page. Once you’ve unzipped the project folder you’ll see a couple folders. The first is “examples/” and has a few sample pages that you can play with and see how things work. The second is “src” and contains all the files you need to integrate it into your own project.

Assuming you leave these files in the “src/” folder, you’ll load the class using the following code at the top of your page. This code must be present in order for any of the examples below to work.

This will create a new dribbble object stored in $dribbble. Everything below branches from this.


This is probably what 90% of you are interested in. A Dribbble feed makes an excellent addition to any portfolio/personal site. The following code will pull in the latest 3 shots made by the specified account.

Shots can be called in two sizes: teaser and full. The example above uses the full 400×300 default, but if you wanted to display teasers instead, you can replace the $shot->image_url with $shot->image_teaser_url.

For those unfamiliar with PHP’s sprintf() function, here’s a quick primer: The “%s” acts as a placeholder for the arguments provided after the first comma. In the example above, the $shot->url result will be placed into the href attribute, etc. You don’t have to use this method, but I find it to be much neater than a series of PHP blocks for one-liners.


Here’s how you could use the API to get the three latest shots from Dribbble’s popular section:

Notice that you’re also able to display information about each shot’s author as well as link to their respective profiles.


Comments on a Shot

This last one would be useful if you wanted to make a Dribbble-powered testimonial system. The loop below will display comments for the shot specified by ID.

If you have any confusion with these (or other) examples, I recommend you take a look at the demo pages packaged with the source code. I tried to make sure that they were as clear-cut as possible, and should make it easy to figure out most issues.


SynapseIndia Php Development – A Blog Entry

Creating A PHP Application 


With the categories now available, the real work of CRUD can begin. Of course, the beginning is the creation of a blog entry. Once again a form will be used to enter the data but this form will not be as simple as the previous. A little forward thinking is needed as a blog entry may need to be edited to correct some aspect of the entry. The form fields will be identical, and it would be poor practice to duplicate the form and use separate forms for both add and editing a blog entry.

Like any other piece of reusable code, the form can be included in a php script. The main difference with a reusable piece of HTML code is that any PHP variables within the code must be available to it. Also, the form action will be directed to two different scripts, so this too must be a variable set in the parent script, that is, the script that includes the form.

The includes/blog_form.php file, which contains the form, will look like this

<h3><?php echo $blog_heading; ?></h3>
<form action=”<?php echo $blog_form_action; ?>” method=”post”>
<input type=”hidden” name=”blog_content_id” value=”<?php echo isset($blog_content_id) ? $blog_content_id : ”; ?>” />
<dd><input type=”text” name=”blog_content_headline” value=”<?php echo isset($blog_content_headline) ? $blog_content_headline : ”; ?>”/></dd><dt>Category</dt>
<select name=”blog_category_id”>
foreach($categories as $id=>$cat)
echo “<option value=\”$id\””;
/*** mark as selected ***/
echo (isset($selected) && $id==$selected) ? ‘ selected’ : ”;
echo “>$cat</option>\n”;

<textarea name=”blog_content_text” rows=”5″ cols=”45″><?php echo isset($blog_content_text) ? $blog_content_text : ”; ?></textarea>

<dd><input type=”submit” value=”<?php echo $blog_form_submit_value; ?>” /></dd>

The form is much the same as the add_category form from used earlier, with the exception that this form has more fields. The category drop-down menu is identical to that of the add category form and a text input field is supplied for the heading along with a textarea for the blog_content_text. Once again the field names are identical to those in the database table that the form is designed for.

The form also contains several pieces of PHP code in the inputs to echo the value of form field if they are set. The form action is set with a variable along with the value of the submit button. These variables make the form re-usable later when updating blog data.

The add_blog.php file that will include the form performs several functions. Like the add category form a session is started at the top of the script and then the session token is set. The header.php file is included as is the conn.php file to connect to the database. Once again, a check is made that a valid connection has been made to the database, and if this is ok, a further check is made to be sure a category is available. If all is well, the categories are put into an array named $categories with the category_id as the index. I is this array that is passed to the form to produce the category drop-down menu.

Following from there, the variables that are in the form are set. If one of them is omitted, an error will be produced, so it is important to make sure all variables have a value, even if the value is an empty string.

The add_blog.php file will look like this.

/*** begin output buffering ***/
ob_start();/*** include the header file ***/
include ‘includes/header.php’;

/*** check access level ***/
if(!isset($_SESSION[‘access_level’]) || $_SESSION[‘access_level’] < 1)
/*** if not logged in, forward to login page ***/
header(“Location: login.php”);

/*** set the token to prevent multiple posts ***/
$form_token = uniqid();
$_SESSION[‘form_token’] = $form_token;

/*** get the categories from the database ***/
include ‘includes/conn.php’;

/*** check for database connection ***/
$sql = “SELECT
$result = mysql_query($sql);
echo ‘Unable to find any categories’;
/*** check for a result ***/
if(mysql_num_rows($result) != 0)
/*** put the categories in an array ***/
$categories = array();
while($row = mysql_fetch_array($result))
$categories[$row[‘blog_category_id’]] = $row[‘blog_category_name’];

/*** set the form values ***/
$blog_form_action = ‘add_blog_submit.php’;
$blog_heading = “Add A Blog Entry”;
$blog_content_headline = ”;
$blog_content_text = ”;
$blog_form_submit_value = ‘Add Blog’;

/*** include the blog form ***/
include ‘includes/blog_form.php’;
echo ‘No categories found’;
/*** if we are here the database connection has failed ***/
echo ‘Unable to complete request’;

/*** include the footer ***/
include ‘includes/footer.php’;

The final part of adding a blog entry is to create the add_blog_submit.php file. Like the add_category_submit.php file, the task of INSERTing the data into the database is quite simple. The same process is repeated with a new SQL query for the blog table. The session token is destroyed in the same way to prevent multiple posting by hitting the refresh button.

The add_blog_submit.php file will look like this.

/*** begin output buffering ***/
ob_start();/*** include the header file ***/
include ‘includes/header.php’;

/*** check access level ***/
if(!isset($_SESSION[‘access_level’]) || $_SESSION[‘access_level’] < 1)
/*** if not logged in, forward to login page ***/
header(“Location: login.php”);
/*** check the form has been posted and the session variable is set ***/
if(isset($_SESSION[‘form_token’], $_POST[‘blog_category_id’], $_POST[‘blog_content_headline’], $_POST[‘blog_content_text’]))
/*** first check all POST variables for type and length ***/
if(!is_numeric($_POST[‘blog_category_id’]) || $_POST[‘blog_category_id’]==0)
echo ‘Blog Category Name is Invalid’;
elseif(!is_string($_POST[‘blog_content_headline’]) || strlen($_POST[‘blog_content_headline’])<3 || strlen($_POST[‘blog_content_headline’])>50)
echo ‘Blog Headline is invalid’;
elseif(!is_string($_POST[‘blog_content_text’]) || strlen($_POST[‘blog_content_text’])<3 || strlen($_POST[‘blog_content_text’])>4096)
echo ‘Blog Text is Invalid’;
/*** if we are here, include the db connection ***/
include ‘includes/conn.php’;

/*** test for db connection ***/
/*** escape the strings ***/
$blog_user_id = $_SESSION[‘blog_user_id’];
$blog_category_id = mysql_real_escape_string($_POST[‘blog_category_id’]);
$blog_content_headline = mysql_real_escape_string($_POST[‘blog_content_headline’]);
$blog_content_text = mysql_real_escape_string($_POST[‘blog_content_text’]);

/*** the sql query ***/
$sql = “INSERT

/*** run the query ***/
/*** unset the session token ***/

echo ‘Blog Entry Added’;
echo ‘Blog Entry Not Added’ .mysql_error();
echo ‘Unable to process form’;
echo ‘Invalid Submission’;

Create a free website or blog at

Up ↑