In the Yii2 framework, the model is basically a static method.

Source: Internet
Author: User
It feels strange. Is the model layer static? In fact, these methods can also be written as class methods, but NEW methods must be added before calling. So it is changed to static. The disadvantage is that if the static method needs to abstract public logic processing, it must also be written as static...

It feels strange. Is the model layer static?

In fact, these methods can also be written as class methods, but NEW methods must be added before calling. So it is changed to static.

The disadvantage is that if the static method needs to abstract public logic processing, it must also be written as static.

I don't feel right. ask someone to help me.


Reply content:

It feels strange. Is the model layer static?

In fact, these methods can also be written as class methods, but NEW methods must be added before calling. So it is changed to static.

The disadvantage is that if the static method needs to abstract public logic processing, it must also be written as static.

I don't feel right. ask someone to help me.


I am also like the landlord, sometimes writing is a static method. In fact, it may be better to create a service layer to encapsulate these operations, rather than writing them in the Model.

NO is not necessarily static.
For example, I have a table (school_user_check) that has a field (uid) associated with the user table (user) to obtain the corresponding user table data:

Write models first

Then call

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.