What is the data pattern in the Segmentfault framework?

Source: Internet
Author: User
Tags php foreach
What is the data pattern in the Segmentfault framework?

In the http://www.infoq.com/cn/news/2012/09/... Mentioned in the.

Reply content:

What is the data pattern in the Segmentfault framework?

In the http://www.infoq.com/cn/news/2012/09/... Mentioned in the.

In the Segmentfault framework, we Data define a data management object, which is mainly convenient to display in the template. It can represent a single data, or can show multiple data, which is mainly through Iterator the inheritance interface to implement the iterator function. For example, we show the effect of extracting data from the database to the page display.

We're going to write that in action.

Remove data from model $questions = $this->questionmodel->listquestions ();//put array in iterator $this->questions = new Data_ Question ($questions);//Presentation template $this->view->render (' questions.php ');

We can manipulate the object in the view Data_Question .

 
  

URL ();?> "> title ();?>

Summary (' ... ');?>

It can be seen that its usage is greatly simplified and intuitive, you do not need to echo , because we in the Data base class to help you with the function of the __call field name as the method name of the direct output of the work, of course you can echo $q->title , because we also have to deal with the __get function, You can call the current field directly.

More importantly, with the use of caching technology, we can achieve a very fantastic method, such as the problem author $q->user , it can directly return to an Data_User object, then we can use the time to query, what data we want to write what data, such as we output the author of each problem related information

User->url ();?> ">
 
   user->name ();?>. 
 
   User->rank ();?>

This is just the most basic usage, and there are many more complex usages that are not introduced, such as the output field can take parameters and so on

  • 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.