Is there a difference between calling a function in the php model and calling a function directly?

Source: Internet
Author: User
{Code...} first returns a count function to return the number of database entries. Return the correct value when calling this function directly. {Code...} but if it is called in this way, it will be all 0. Why? Are there any differences between the two methods? What should I do if I call it in the model?

  

First, this is a count function that returns the number of database entries. Return the correct value when calling this function directly.

 function index(){ $newsobj=M('news'); $newsnum=$newsobj->count(); //print_r ($newsnum); VIEW::assign(array('newsnum'=>$newsnum)); VIEW::display('admin/index.html'); }

However, if so, all the calls are 0. Why? Are there any differences between the two methods?
What should I do if I call it in the model?

Reply content:

   

First, this is a count function that returns the number of database entries. Return the correct value when calling this function directly.

 function index(){ $newsobj=M('news'); $newsnum=$newsobj->count(); //print_r ($newsnum); VIEW::assign(array('newsnum'=>$newsnum)); VIEW::display('admin/index.html'); }

However, if so, all the calls are 0. Why? Are there any differences between the two methods?
What should I do if I call it in the model?

The mode of the M function must implement the extends Model.

Count has already been implemented in the Model, so you don't have to write it aside. If you have to implement it yourself, you can use

Return $ this-> count ();

The subject can first understand the differences between the M method and the D method, and be familiar with the consistent operations of the tp framework. Avoid repeated methods.

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.