Learn Codeigniter
A. Installtion of Codeigniter
1. Download Codeigniter
2. Unzip , copy it htdocs folder
3. start apache and mysql
4. run index.php you will get be
B. Advantage of codeignighter
1. CodeIgniter is Light Weight
2. CodeIgniter is Fast
3. CodeIgniter Uses M-V-C
4. CodeIgniter Generates Clean URLs
5. CodeIgniter comes with full-range of libraries
6. CodeIgniter is Extensible
7. CodeIgniter Does Not Require a Template Engine
others..
1. Model-View-Controller Based System
2. Extremely Light Weight
3 Full Featured database classes with support for several platforms.
4. Active Record Database Support
5. Form and Data Validation
6. Security and XSS Filtering
7. Session Management
8. Email Sending Class. Supports Attachments, HTML/Text email, multiple protocols (sendmail, SMTP, and Mail) and more.
9. Image Manipulation Library (cropping, resizing, rotating, etc.). Supports GD, ImageMagick, and NetPBM
10. File Uploading Class
11. FTP Class
12. Localization
13. Pagination
14. Data Encryption
15. Benchmarking
16. Full Page Caching
17. Error Logging
18 Application Profiling
19. Calendaring Class
20 User Agent Class
21 Zip Encoding Class
22. Template Engine Class
23 Trackback Class
24. XML-RPC Library
25 Unit Testing Class
26 Search-engine Friendly URLs
C. Make a first Program
Create a file at application/controllers/pages.php with the following code.
class Pages extends CI_Controller {
public function view($page = 'home')
{
}
}
Now you've created your first method, it's time to make some basic page templates. We will be creating two "views" (page templates) that act as our page footer and header.
Create the header at application/views/templates/header.php and add the following code.
header.php
<html>
<head>
<title><?php echo $title ?> Hello World</title>
</head>
<body>
<h1>Testings</h1>
footer.php
<strong>© 2011</strong>
</body>
</html>
D. Adding logic to the controller
class Pages extends CI_Controller {
public function view($page = 'home')
{
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
http://example.com/[controller-class]/[controller-method]/[arguments]
E. What is a Model?
Models are PHP classes that are designed to work with information in your database. For example, let's say you use CodeIgniter to manage a blog. You might have a model class that contains functions to insert, update, and retrieve your blog data. Here is an example of what such a model class might look like:
class Blogmodel extends CI_Model {
var $title = '';
var $content = '';
var $date = '';
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function get_last_ten_entries()
{
$query = $this->db->get('entries', 10);
return $query->result();
}
function insert_entry()
{
$this->title = $_POST['title']; // please read the below note
$this->content = $_POST['content'];
$this->date = time();
$this->db->insert('entries', $this);
}
function update_entry()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->update('entries', $this, array('id' => $_POST['id']));
}
}
F .Loading a Helper
$this->load->helper('name');
No comments:
Post a Comment