Framework

PHP framework tutorial step by step

I will show you that how to code with these frameworks :
  1. Smarty
  2. codeigniter
  3. laravel
First of all we must have to know that what is framework and what it does. So, I will say frameworks are a special case of software libraries in that they are reusable abstractions of code wrapped in a well-defined Application programming interface (API), yet they contain some key characteristic skin that separate them from common libraries.

Okay..! lets start with a framework. We will explore Smarty framework. first. and we will learn the basic of smarty framework that what is smarty framework? and how to use smarty framework? 

What is Smarty framework?
Smarty is a template engine for PHP. More spacifically, it facilitates a manageable way to separate application logic and content from its presentation. This is best described in a situation where the application programmer and the template designer play different roles, or in most cases are not the same person.

Download Smarty framework from Here and unzip the compressed smarty package.


intphp.blogspot.com
 you will get directory structure like below.
intphp.blogspot.com
This will be the directory for your smarty engine. You have to give writing rights to cache and templates_c directories. So, files can be written in these directories. Save your app templates in .tpl (dot t p l) extension and save in templates folder.
How to use Smarty framework ?
create a file name Index.php  inside your smarty project.

PHP Code:
  1. <?php
  2. require ('libs/Smarty.class.php');
  3. $smarty = new Smarty;
  4. $smarty->assign("page_title","Hello intphp.blogspost.com");
  5. $smarty->assign("page_content","This is intphp.blogspot.com");
  6. $smarty->display("index.tpl");
  7. ?>


Now create index.tpl inside the template folder this file should have .tpl extension. We have recently assign data to two variables page_title and page_content inside index.php. Now will will access these two variables in our index.tpl file. In this file we can access variable by using the curly braces. like {$page_title} and {$page_content}. See the code given below:


PHP Code:
  1. <html>
  2. <head>
  3. <title>{$page_title}</title>
  4. </head>
  5. <body>
  6.  
  7.  {$page_content}
  8.  
  9. </body>
  10. </html>
Now open web browser and run your script with localhost:

Intphp.blogspot.com