Home > Backend Development > PHP Tutorial > thinkphp automatically completes session assignment sample code in the model, thinkphp sample code_PHP tutorial

thinkphp automatically completes session assignment sample code in the model, thinkphp sample code_PHP tutorial

WBOY
Release: 2016-07-13 10:19:10
Original
927 people have browsed it

thinkphp automatically completes session assignment sample code in the model, thinkphp sample code

I believe that users who have used thinkphp know that thinkphp’s model can complete many auxiliary functions, such as automatic verification, automatic completion, etc. Today, during development, I encountered the function of obtaining the session value and then automatically assigning the value in the automatic completion. See the code for details. ;

class ArticlelModel extends Model {

protected $_auto = array (
array('addtime','time',1,'function'),
array('username','getName',1,'callback')
);

//这个函数获取session里的name值
protected function getName(){
return $_SESSION["name"];
}
}
Copy after login

Here you need to pay attention to the difference between the last parameter function and callback;
function: When using a function, it will automatically go to Common/common.php to find the corresponding function;
callback: Use the callback method defined in the current model

A session shopping cart made by thinkphp. If you have a complete example of the detailed code, you can send it. Thank you very much

hasItem($id)) { // If the item already exists, add its quantity directly $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 quantity of goods in the shopping cart param int $id Product primary key param int $num Modified quantity of a certain product, that is, directly change the quantity of a certain product to $num */ public function modNum($id,$num=1) { if(!$this->hasItem($id)) { r...The rest of the text>>

A sample code in CURD in thinkphp manual is as follows. In fact, there is no need to read the code. The specific questions are as follows

1. Complete the most functions with the least code
2. Excellent concepts and innovative models
3. Have complete MVC and fully built-in implementation
4. Ideal performance and complete functions
5. Complete Chinese documentation and online manuals
6. Perfectly supports different databases
7. Has many enterprise-level features
8. Has fast BUG response and repair capabilities
9. Walked through After three years of accumulation and improvement of details
10. Have a community-based team and open source power
11. Have numerous third-party derivative open source projects
12. Allow you to stand out from other teams (^_^ )
Then ThinkPHP will be your wise choice! ThinkPHP has many excellent features, including:
Easy-to-use MVC mode
Original core compilation and project compilation mechanism
Built-in XML template engine, supporting tag library
Rich model support
CURD and operation highly automated support
Rich query language support
Automatic creation of directory structure
Distributed database support
Multi-database connection and switching support
ActiveRecords mode and ROR features
Flexible and simple Project configuration
Automatic model verification and processing
Static page generation and diversified caching mechanism
Rich database and PDO support
SEO and URL routing support
AJAX support
Easy-to-expand system Base class library
Automatic encoding conversion
Component and plug-in support
Role-based permission control system, detailed development guide and full Chinese comments
Hope to adopt it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/876530.htmlTechArticlethinkphp automatically completes the session assignment sample code in the model. Thinkphp sample code. I believe users who have used thinkphp know thinkphp. The model can complete many auxiliary functions, such as automatic verification...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template