Creating a Bloggin Tool with CodeIgniter.pdf
(
1193 KB
)
Pobierz
512478388 UNPDF
Thomas Myer
a Blogging
Tool with
Codeigniter
®
Wiley Publishing, Inc.
Updates, source code, and Wrox technical support at
www.wrox.com
Creating
Contents
Introducing CodeIgniter
2
What’s Model-View-Controller?
2
Why Bother with MVC?
4
Installing and Configuring CodeIgniter
5
The Root Folder
6
The system/Folder
7
The system/application Folder
7
Tweaking the Configuration
8
Getting Started
10
The Public-Facing Site
12
Creating the Template View
14
Creating the Home Page View
16
Creating the Category View
19
Creating the Blog Details View
20
Creating the Login Form
22
Verifying Logins
23
Creating the MAdmins Model
24
Creating the
verifyUser()
Function
24
A Small Note about Creating Your First User
25
Creating the Admin Dashboard
25
Creating the Dashboard Controller
26
Building the Admin Area
28
Creating the Rest of the Admin Functions
34
Summary
38
About Thomas Myer
39
Wrox Blox0 Creating a Blogging Tool with CodeIgniter By Myer - ISBN0 97804704133881 Prepared for CHRISTOPHER RINGWALD/ email0
callananclare@aol.com Order number0 40397143 Copyright 2009/ Wiley Publishing Inc. This PDF is exclusively for your use in accordance
with the WroxBlox Terms of Service. No part of it may be reproduced or transmitted in any form by any means without prior written
permission from the publisher. Redistribution or other use that violates the Wrox Blox Terms of Service or otherwise violates the U.S.
copyright laws is strictly prohibited.
Creating a Blogging Tool
with Codeigniter
Let’s imagine for a second that you’re working on a team of marketers, writers, and designers, and
that the marketing manager requests that you create a blogging tool from scratch. It doesn’t have
to be complex, but it can’t be any of the off-the-shelf applications available for free on the Web (like
WordPress). It has to be small, efficient, and very fast. Most important, it needs to integrate seam-
lessly with an existing web site.
Oh, and one more thing: “Could we have a working prototype up and running by 5
p
.
m
. today?”
You look at your watch and notice that it is 11:25
a
.
m
. You do a quick calculation — you have just
enough time to grab lunch and start cracking away at the project with CodeIgniter. No problem,
you think. A blog is pretty simple. You’ve seen hundreds (if not thousands) of them in action, and
you’ve integrated all kinds of code with various models. With CodeIgniter by your side, you
should be able to kick out most of what you need in just a few hours.
You say yes, you’ll build it, as long as everyone understands that it’s a working prototype. With
that, you run off to get some lunch and sketch out some basic requirements.
Sound impossible? With CodeIgniter, it isn’t. In this Wrox Blox, you’ll see how to put together a
very simple blogging application in an afternoon. The key here is “simple.” At the end of the
process, you won’t have some kind of WordPress competitor. But you will have a very useful,
portable, and slick little blogging tool that you can add to any existing site (CodeIgniter or not).
Here’s a quick run down of what you’ll end up with:
q
A public-facing home page that shows the last 10 blog posts
q
A way to show posts by category
q
A way to display a single post with comments (and a way for others to comment
on a post)
Wrox Blox0 Creating a Blogging Tool with CodeIgniter By Myer - ISBN0 97804704133881 Prepared for CHRISTOPHER RINGWALD/ email0
callananclare@aol.com Order number0 40397143 Copyright 2009/ Wiley Publishing Inc. This PDF is exclusively for your use in accordance
with the WroxBlox Terms of Service. No part of it may be reproduced or transmitted in any form by any means without prior written
permission from the publisher. Redistribution or other use that violates the Wrox Blox Terms of Service or otherwise violates the U.S.
copyright laws is strictly prohibited.
Creating a Blogging Tool with Codeigniter®
q
An administrative area that requires a username and password for access
q
An administrative area to manage users, posts, and categories
Now that you know what to build, it’s time to download CodeIgniter and get the general overview.
Introducing CodeIgniter
CodeIgniter was created by the good folks over at EllisLab, Inc. It is a Model-View-Controller (MVC)
framework with a very small footprint. In form and function, it is very similar to other MVC
frameworks, like Ruby on Rails. Like Ruby on Rails, it requires very little configuration to get started.
I’ve been able to create prototype applications within hours of talking to a client, and then refined the
prototypes over the course of a few days.
It’s this kind of prototyping power and flexibility, by the way, that will transform the way you work
with clients. It allows you to be responsive and collaborative in ways that you’re probably not used to.
Unlike Ruby on Rails, CodeIgniter doesn’t require you to adhere to a strict set of coding rules.
For example, you don’t have to name your database tables a certain way, and your models another.
You don’t even have to have strictly formatted table fields — which makes CodeIgniter an excellent
platform for recoding legacy applications.
Below are a few more great things about CodeIgniter:
q
There is a growing toolbox of helpers and libraries that help you do your job quickly.
q
You don’t have to learn a complex templating language.
q
You don’t need to work with large-scale monolithic libraries.
q
You can run your applications in PHP 4 or PHP 5 without too much hassle.
q
CodeIgniter applications run with exceptional performance.
This section doesn’t get into too many more details right now. You’ll start seeing the difference once you
start coding. For now, it might be useful to talk a little bit about MVC and why it’s important. Then
you’ll get to work.
What’s Model-View-Controller?
Model-View-Controller is a design pattern that allows developers to separate their code cleanly into
three categories:
q
Models
— help you maintain data.
q
Views
— display data from the model and user interface elements.
q
Controllers
— handle user events that interact with models and views.
Wrox Blox0 Creating a Blogging Tool with CodeIgniter By Myer - ISBN0 97804704133881 Prepared for CHRISTOPHER RINGWALD/ email0
callananclare@aol.com Order number0 40397143 Copyright 2009/ Wiley Publishing Inc. This PDF is exclusively for your use in accordance
with the WroxBlox Terms of Service. No part of it may be reproduced or transmitted in any form by any means without prior written
permission from the publisher. Redistribution or other use that violates the Wrox Blox Terms of Service or otherwise violates the U.S.
copyright laws is strictly prohibited.
Creating a Blogging Tool with Codeigniter®
The important thing to remember is that MVC takes the user into account — it begins with them. It’s the
user who clicks a link, moves the mouse, or submits a form. It’s the controller that monitors this activity
and takes the appropriate action (such as manipulating the model and updating the view).
Because of MVC’s three-part separation, developers can create multiple views and controllers for any
given model without forcing changes in the model design. Similarly, multiple controllers can make use
of any model. This separation allows for easily maintained, portable, and organized applications.
For example, think about an MVC application that allows us to track eCommerce items in an online
store. You would have the following:
q
A model for product information
q
Multiple views to show single products, products in a list, products in search results, and so on
q
At least one controller that would organize those views into destinations, such as index()
(for home page), product_detail(), and search_results()
Drilling down further, an MVC eCommerce application might involve the following flow of events:
1.
The user visits the store’s home page.
.
This simple event requires a controller action for the home page, which makes a quick call to the
model to retrieve the 10 most popular products based on recent sales.
.
The model’s data are then transmitted to the view for the home page.
4.
The view (including the data retrieved by the model) is what the user sees in the browser.
5.
The user clicks a link to see details on a particular product.
6.
The underlying controller captures this user input (clicking the link), uses the model to retrieve
the product in question from the database, and then loads the appropriate view.
7.
The cycle begins anew when the user takes another action, such as running a search or clicking a
link.
Another way of thinking about this breakdown of roles is to map it out as follows (see
Figure 1
):
q
User Input and Traffic Control = Controller
q
Data Interaction and Processing = Model
q
Output = View
Wrox Blox0 Creating a Blogging Tool with CodeIgniter By Myer - ISBN0 97804704133881 Prepared for CHRISTOPHER RINGWALD/ email0
callananclare@aol.com Order number0 40397143 Copyright 2009/ Wiley Publishing Inc. This PDF is exclusively for your use in accordance
with the WroxBlox Terms of Service. No part of it may be reproduced or transmitted in any form by any means without prior written
permission from the publisher. Redistribution or other use that violates the Wrox Blox Terms of Service or otherwise violates the U.S.
copyright laws is strictly prohibited.
Plik z chomika:
hooper
Inne pliki z tego folderu:
Expert One-on-One J2EE Development without EJB.pdf
(8141 KB)
Expert Access 2007 Programming.pdf
(8806 KB)
Excel 2007 VBA Programmer's Reference.pdf
(6948 KB)
Excel 2003 VBA Programmer's Reference.pdf
(18527 KB)
Dreamweaver MX-PHP Web Development.chm
(14003 KB)
Inne foldery tego chomika:
Informatyka
Zgłoś jeśli
naruszono regulamin