Tuesday, April 23, 2013

Get started with CodeIgniter Framework

A Fully Baked PHP Framework. CodeIgniter is a proven, agile & open PHP web application framework with a small footprint.

How It Works

CodeIgniter uses the MVC or Model View Controller architectural pattern, if your not familiar with MVC it is a logical object orientated development approach. below we look at a simple example of how we use the MVC.

Controllers

A controller is simply a class file that is named in a way that can be associated with a URI. For example if i have a controller with the filename account.php the URI to reach that page would be something like http://your-domain.com/account/ so you no longer need to fiddle with the .htaccess file and mod_rewrite to enable SEO friendly URI’s. The controller is the top level file for each page that allows you to include database requests in the form of ‘Models’ and templates as ‘Views’. below is an example of a controller, This code would be saved in the file blog.php, it’s important to understand the naming convensions because the name of the file is always the name of the class with the first letter capitalised. Within the Blog class we have an index() function which is always loaded when the page is excecuted. For example if we had another function lets say ‘categories’ the code within that function would only be executed if we visited http://your-domain.com/blog/categories/ this is also the way you can pass url parameters into functions but we’ll leave that for another day. We’re loading our ‘View’ in at the bottom and passing the array $data into it. Within the view file which would be called blogview.php if we wanted to echo the heading we’d simply echo $heading the same with the title. With the to do list we would need to setup a for each loop to cycle through the results in that array.
class Blog extends Controller {
 
    function index()
    {
        $data['todo_list'] = array('Clean House','Run Errands');
        $data['title'] = 'My Real Title';
        $data['heading'] = 'My Real Heading';
 
        $this->load->view('blogview', $data);
    }
}

Models

As yet we’re not using a model, this is because our controller isn’t doing anything complex. If we wanted to connect to a database and get a set of results we would use a model which could look like the below. This is all the code we need to pull 10 results from the database which would be returned to the controller in an array. note that you would need to replace ‘tableName’ with your own database table name.

class Blogmodel extends Model {
 
    function Blogmodel()
    {
        // Call the Model constructor
        parent::Model();
    }
 
    function get_last_ten_entries()
    {
        $query = $this->db->get('tableName', 10);
        return $query->result();
    }
 
}
 
To include the model firstly you need to navigate to system/application/config/database.php and add your database connection details. then below you’ll see that i’ve modified the controller that we used earlier so it now connects to the database and gets our data. This will then be sent through to the ‘view’.

Views

Simply put a ‘View’ is our template, it’s where our data gets rendered and is made pretty, you can have as many views as you like and pass whatever data you like into them it’s probably a good idea to have a header, main content area and footer.

For Download Codeigniter : Click here

Monday, April 22, 2013

Get Facebook Profile Image By Php

Hi Friends,

Today We Learn About How Upload or Get Facebook Profile image to local server or anywhere you wish.
here we use facebook graph api and facebook sdk to do this task.so please first you have to download FACEBOOK SDK from here Click .After downloading sdk create one facebook application for doing this task login to your facebook account after login your facebook account it print your all details.in this detail also contain your profile image link. Here the question is how to get image link? but is easy by json and file function.

Just create link or url like " $img="https://graph.facebook.com/$user/picture?redirect=false; ".
$user variable contain your facebook id then all these data add to the file_get_contents($img) function then it decode by json like $jd=json_decode($images); and get image url from json like $url=$jd->data->url; and then apply image upload code.this code is used to upload image wia url.

Example Code :

//Get file name by json
     $img="https://graph.facebook.com/$user/picture?redirect=false";   
    $images=file_get_contents($img);
    $jd=json_decode($images);
    $url=$jd->data->url;

   
//create file name;
$name = basename($url);
list($txt, $ext) = explode(".", $name);
$name = $txt.time();
$name = $name.".".$ext;

 
//file upload
$upload = file_put_contents("uploads/$name",file_get_contents($url));

Thursday, April 18, 2013

Display Breadcrumbs on Website using PHP Script

Hi Friends,
You have a fully dynamic site it’s useful to show the user where they are by breaking down the URL structure so they can navigate backwards through the site.

Breadcrumbs on website using PHP Script

 Breadcrumbs is used to navigate your dynamic website.
its show where you are. 
just put this below code in your files and see your the magic.
 Example code:
$path_parts = pathinfo($_SERVER['REQUEST_URI']);
$filename=explode("?",$path_parts['basename']);
echo " ".$path_parts['dirname'].'/'.$filename[0];

Check Internet Connection is On or Off using Php

Hello Friends,
Today we learn About how to Check Internet Connection is On or Off using Php script is very interesting.Lets see the php magic.

Check Internet is On or Off Using Php

Here we can use fsockopen php function.
in this function contain below parameter.
1)hostname : provide the hostname like :www.google.com
2)port     : add port number like : 80
3)errno    : error number generate by itself.
4)errstr   : display error message when connection fail.
5)timeout  : The connection timeout, in seconds.
example :
if(!$sock= @fsockopen('www.google.com',80,$num,$error,5))
echo "Off line";
else
echo "ok";