CodeIgniter controller-business logic instance analysis

Source: Internet
Author: User
This article mainly introduces how to use the business logic of CodeIgniter controller, and analyzes the related concepts and specific usage of the business logic in the form of instances, for more information about the business logic of CodeIgniter controller, see the following example. We will share this with you for your reference. The details are as follows:

We have analyzed the distribution of public controllers by module to facilitate control over specific modules. the specific implementation classes are placed in the library. Is it appropriate to put it in the library? And where should we put more business logic in the controller?

First, let's talk about the understanding of several folders in CI.

The code is as follows:

$ This-> load-> service ('User _ service ');

.
However, many business logic needs to obtain the CI instance. here we can refer to the model method. The core creates a MY_Service, and all other services inherit this class, so that the usage of the service is the same as that in the controller.

Class MY_Service {public function _ construct () {log_message ('debug', "Service Class Initialized");} function _ get ($ key) {$ CI = & get_instance (); return $ CI-> $ key ;}}

In fact, the main idea is to have a layer to process the business logic, and both java have this layer. As I became familiar with CI, I found that this layer is needed to free up controllers and models. There are still many similar practices. if there are many places in the system that need to use web services or cache, you can also put them in a folder to facilitate management.

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.