Thinkphp automatically completes the session assignment sample code in the model, thinkphp sample code _ PHP Tutorial

Source: Internet
Author: User
Thinkphp automatically completes the session assignment sample code in the model and thinkphp sample code. Thinkphp automatically completes the session assignment sample code in the model. the thinkphp sample code is believed to be useful to users who have used thinkphp, for example, if thinkphp automatically completes the session assignment sample code in the model, thinkphp Sample code

I believe that users who have used thinkphp know that thinkphp models can complete many auxiliary functions, such as automatic verification and automatic completion, today, during development, we encountered the function of automatically completing the task and obtaining the session value and then assigning values automatically. for details, refer to the code;

Class ArticlelModel extends Model {protected $ _ auto = array ('addtime', 'time', 1, 'Function'), array ('username', 'getname ', 1, 'callback'); // This function gets the name value in the session protected function getName () {return $ _ SESSION ["name"];}

Note the difference between the function and callback of the last parameter;
Function: when a function is used, Common/common. php is automatically used to find the corresponding function;
Callback: use the callback method defined in the current model


Thinkphp's session shopping cart. thanks for the complete code examples.

HasItem ($ id) {// if the item already exists, add its quantity $ this-> incNum ($ id, $ num); return ;} $ item = array (); $ item ['id'] = $ id; $ item ['name'] = $ name; $ item ['price'] = $ price; $ item ['brand'] = $ brand; $ item ['thumb'] = $ thumb; $ item ['num'] = $ num; $ this-> items [$ id] = $ item; return $ this-> items [$ id];} /* modify the number of items in the shopping cart, param int $ id, item primary key, param int $ num, change the quantity of a product to $ num */public function modNum ($ id, $ num = 1) {if (! $ This-> hasItem ($ id) {r ...... remaining full text>

The following is an example of the code in CURD in the thinkphp manual:

1. complete the most functions with the least code
2. excellent ideas and innovative models
3. complete MVC and full built-in implementation
4. ideal performance and complete functions
5. complete Chinese documents and online manuals
6. perfect support for different databases
7. enterprise-level features
8. fast BUG response and repair capabilities
9. After three years of accumulation and detailed improvements
10. community-based teams and open-source forces
11. many third-party derivative open-source projects
12. better than other teams (^_^)
ThinkPHP will be your wise choice! ThinkPHP has many outstanding features, including:
Simple and easy-to-use MVC mode
Unique Core compilation and project compilation mechanisms
Built-in XML template engine, supporting tag library
Rich model support
Highly automated support for CURD and operations
Rich query language support
Automatic Directory structure creation
Distributed Database support
Multi-database connection and switchover support
ActiveRecords mode and ROR features
Flexible and simple project configuration
Automatic model verification and processing
Static page generation and diversified cache mechanisms
Rich database and PDO support
SEO and URL routing support
AJAX support
Scalable System Base Class Library
Automatic transcoding
Support for components and plug-ins
Role-Based permission control system detailed development guide and full Chinese comments
Hope to adopt it.

NLP believes that users who have used thinkphp know that the thinkphp model can complete many auxiliary functions, such as automatic verification...

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.