This paper describes the basic function of the Zend Framework implementation of the message book. Share to everyone for your reference, as follows:
A message book ... The basic function is. 1. Leave a message. 2. Reply to the message. 3. Manage messages (modify, delete, etc.).
I just wrote a basic operation, such as add message Verification code. The beautification of the page I have
Did not do. I just give you a thought. A lot of things depend on ourselves to learn.
The other one is my message with Ajax. That's when you publish. The data is displayed on the page. But you need to understand the Ajax usage of jquery. I believe most people will be this JS class library bar.
It doesn't matter if you don't understand. You can change to not Ajax. As long as the delivery of the message from the submission action into our control of an action. Believe this is not a problem. Start work:
Our directory structure is the same as before, roughly unchanged. Here's what to change: Let's not worry about it. I'll teach you how to do it:
First: Set up our template page (View) first.
Follow the table of contents of the previous tutorial. There are some template pages in the Application/views/scripts directory. such as (index.phtml,edit.phtml). We delete them. Now add a message folder.
Add (edit.phtml,index.phtml,message.phtml) three template files to the message. After completion. We add in the application/views/scripts/directory (header.phtml, footer.phtml) two template files.
Because these two files will be re-used later. So put them directly under the application/views/scripts/. Okay, the template is set up. Now it's time to join a HTML.JS.IMAGE. I put them all in the public folder of the Web site root. You can look at my source code. If it's a little messy. Please look at this tutorial according to the source code. (^_^ sorry, that's all I can say. I don't know how to write to make you understand better. Please understand!)
Second: Next, we write our data-layer program (Model).
1. We add the following fields to the original table: PID (whether the flag is a reply, 0 is a message. For 0 is for reply), author (message), HEADIMG (Message person Avatar), email (message person email), IP (message IP address),
Show (whether the message is displayed.) This is to be used in the management of the table. This tutorial is not used here.), Addtime (Message time), UpdateTime (Message modification time). field type settings Please see the source SQL file.
2. We have a message.php in the application/models/directory. Let's first write the model of our message book. The main message is the operation of the data layer. I added the following methods:
Getallmessage (take all the messages), Getallremessage (take all the reply message data), Getmessagebyid (according to the ID to take the message data), Updatemessagebyid (Modify the message), Delmessagebyid (Delete message)
The specific procedures are as follows (the program also has annotations):
class message extends zend_db_table{protected $_name = "Message"; protected $_ Primary = ' id '; /* * Take all messages */Public function getallmessage () {$messageArray = $this->fetchall ("Message.pid=0", "Message.id DESC") ->toarray (); return $messageArray; }/* * Take all reply message data */Public Function getallremessage () {$ReArray = $this->fetchall ("message.pid!=0", "Message.id DE SC ")->toarray (); return $ReArray; }/* * Take message data by ID */Public Function Getmessagebyid ($id) {$messageone = $this->fetchall (' id= '. $id)->toarray (); return $messageone; }/* * Modify message */Public function Updatemessagebyid ($array, $id) {$db = $this->getadapter (); $where = $db->quoteinto (' id = ? ', $id); $this->update ($array, $where); }/* * Delete message */Public function Delmessagebyid ($id) {$where = ' id = '. $id; $this->delete ($where); return true; }}
Third: Complete the above two items. Finally on our control layer (Controller). Open application/controllers/indexcontroller.php this controller. Delete the original thing. I added the following to the top.
A message method (also called an action action). But the other action has been changed. Please participate in the source code to conduct the analysis. I'm just going to stick with my new messageaction. This method (the code has annotations.) Please check it yourself. Thank you):
Public Function messageaction () {if ($this->_request->ispost ()) {Zend_loader::loadclass (' Zend_filter_ Striptags '); $filter =new zend_filter_striptags (); $username = $filter->filter ($this->_request->getpost (' username ')); $email = $filter->filter ($this->_request->getpost (' email ')); $content = $filter->filter ($this->_request->getpost (' content ')); $title = $filter->filter ($this->_request->getpost (' title ')); $messageid = $filter->filter ($this->_request->getpost (' MessageID ')); $headimg = $filter->filter ($this->_request->getpost (' headimg ')); $message =new message (); $db = $message->getadapter (); if ($username! = "&& $email! =" && $messageid! = "&& $content! =") {require_once ' zend/validate /emailaddress.php '; $validator = new Zend_validate_emailaddress (); if ($validator->isvalid ($email)) {//Take IP address: Here is simply take IP $IP =$_server ["REMOTE_ADDR"]; $data =array (' title ' = $title, ' author ' + $username, ' pid ' = ' $messageid, ' headimg ' =>, $headimg, ' email ' + $email, ' show ' + ' 1 ', ' content ' + $content, ' IP ' + $IP, ' Addtime ' =>time (), ' UpdateTime ' =>time ()); $message->insert ($data); $db->lastinsertid (); Unset ($data); Take all messages Getallmessage,getallremessage//two methods defined in model (message.php) $this->view->messages= $message Getallmessage (); Fetch all reply data $this->view->arrreviews= $message->getallremessage (); $this->view->flag= ' 0 '; $this->view->message= ' Your message was published successfully! '; echo $this->view->render (' message/message.phtml '); } else {$this->view->flag= ' 5 '; $this->view->message= ' Sorry! Your email address is incorrect! '; Echo $this->view->render (' message/message.phtml '); }}elseif ($username = = ") {$this->view->flag= ' 1 '; $this->view->message= ' Sorry! Your name cannot be empty! '; echo $this->view->render (' message/message.phtml '); }elseif ($messageid = = ") {$this->view->flag= ' 2 '; $this->view->message= ' Sorry! Reply message number cannot be empty! '; echo $this->view->render (' message/message.phtml '); }elseif ($content== ') {$this->view->flag= ' 3 '; $this->view->message= ' Sorry! The message you filled in cannot be empty! '; echo $this->view->render (' message/message.phtml '); }}else{Echo $this->view->render (' message/index.phtml '); }}
Just no verification code and paging functionality. A tutorial will be further explained in the following article.
Summary: Here to complete a message to write the book. Of course, it's a simple function. Or that sentence. I'm just writing to everyone. Just a thought. That's all I can do. So it's good and bad to write. Please weigh it all by yourself
Full instance code click here to download this site.
More interested in Zend related content readers can view the topic: "Zend framework of the introductory tutorial", "PHP Excellent Development Framework Summary", "Yii framework Introduction and common skills Summary", "thinkphp Introductory Tutorial", "PHP object-oriented Programming introduction tutorial "," Introduction to Php+mysql Database Operation "and" PHP common database Operation Skills Summary "
It is hoped that this article will help you to design PHP based on the Zend Framework framework.