Zend Framework implementation of basic functions of the message book (with demo source download), zenddemo_php tutorial

Source: Internet
Author: User
Tags zend framework

Zend Framework implementation of basic functions of the message book (with the demo source download), Zenddemo


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 funct Ion 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 DESC ")->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 (there are annotations on the code.), 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 ' =&gt, $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.

Articles you may be interested in:

    • Zend Framework Framework Tutorial Zend_db_table_rowset Usage Example Analysis
    • Zend Framework Tutorial Zend_db_table_row Usage Example Analysis
    • Zend Framework Tutorial Zend_db_table Usage
    • Zend Framework Tutorial Zend_form component implement form submission and display Error prompt method
    • Introduction to Zend Framework Development Classic Tutorial
    • Zend Framework Smarty Extension Implementation method
    • Code analysis of routing mechanism of Zend framework framework
    • The Zend framework implements the method of storing the session in Memcache
    • Zend Framework Paging Class usage
    • Zend Framework implements multi-file upload function instances
    • Zend Framework Introduction Environment configuration and the first Hello World example (with demo source download)
    • Zend Framework Tutorial to connect the database and perform additions and deletions of the method (attached to the demo source download)
    • Zend Framework Tutorial Zend_db_table Table Association Instance detailed

http://www.bkjia.com/PHPjc/1113722.html www.bkjia.com true http://www.bkjia.com/PHPjc/1113722.html techarticle Zend Framework to implement a basic function of the message book (with the demo source download), Zenddemo This example describes the Zend framework to achieve basic functions of the message book. Share for everyone to join us ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.