PHP framework tutorial step by step
I will show you that how to code with these frameworks :
- Smarty
- codeigniter
- 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?
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.
you will get directory structure like below.
Download Smarty framework from Here and unzip the compressed smarty package.
intphp.blogspot.com |
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:
- <?php
- require ('libs/Smarty.class.php');
- $smarty = new Smarty;
- $smarty->assign("page_title","Hello intphp.blogspost.com");
- $smarty->assign("page_content","This is intphp.blogspot.com");
- $smarty->display("index.tpl");
- ?>
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:
- <html>
- <head>
- <title>{$page_title}</title>
- </head>
- <body>
- {$page_content}
- </body>
- </html>