Class-thinkphp 3.2.3, I have a class, where should I put it?

Source: Internet
Author: User

I have a class,class name called Get_user_info, this class has a lot of function, I should put this class where, in order to invoke the controller in this class function? For example, in the list controller.

In fact, there is only one problem, can you put it under the common folder ?

Reply content:

I have a class,class name called Get_user_info, this class has a lot of function, I should put this class where, in order to invoke the controller in this class function? For example, in the list controller.

In fact, there is only one problem, can you put it under the common folder ?

/thinkphp/library/org to build a directory of their own, throw the inside to write a good name space can be;
Well, I'll take an example of the project.
In the case of pagination;
Example Project: Http://git.oschina.net/shuaibai123/thinkbjy
Pagination class: Http://git.oschina.net/shuaibai123/thinkbjy/blob/master/ThinkPHP/Library/Org/Bjy/Page.class.php
Call the page 159th line of the paging class: http://git.oschina.net/shuaibai123/thinkbjy/blob/master/Application/Common/Model/ArticleModel.class.php

The first is to define the namespace of the paging class: namespace Orgbjy;
The paging class is then called: $page =new orgbjypage ($count, $limit);

You have to use the same way; You can define a directory, define a namespace, use it, and have a good namespace instantiation.

Or in the official String class:/thinkphp/library/org/util/string.class.php
There are some methods for handling strings, such as obtaining random numbers, string interception, etc.; you can view the official source code to understand;

The class name is a bit strange, look like a model, is the first model class, and then some thinkphp project?

If it's the same as I said, there are 3 ways

    1. Refactor code once to conform to thinkphp model specification

    2. Look at the official library extensions to see if you can integrate, because you might also be involved in database operations, depending on how you debug

    3. The worst-case scenario is as Kingzchenung says include can

Get_user_info This is the name of the class or the name of the method, the current look like the name of the method, if it is a class can be distinguished from a namespace based on a utils such a namespace to hold this class, specifically to see your namespace root directory is how

You can create a new custom directory in the controller sibling directory, and the class changes to a namespace, which can then be referenced. In fact, in other places are casually you, not big own include, at most do not conform to the framework specifications.

Introduced as a third-party plugin.

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