By default, all of the field value types queried by thinkphp are string, and if you are developing the web, of course, no problem, but the development of the interface, it is troublesome, always can not let the client to go to the type.
Thinkphp Model.class.php, provides the _parsetype method, can be done after the query, do type conversion, but the framework is not so dry, we need to manually adjust.
Write a model base class:
BaseModel.class.php, because I use the correlation query, so inherit from Relationmodel
Use Think\model;use think\model\relationmodel;class Basemodel extends relationmodel{ //After query, convert data type protected function _after_select (& $resultSet, $options) { parent::_after_select ($resultSet, $options); foreach ($resultSet as & $result) { $this->_after_find ($result, $options); } } protected function _after_find (& $result, $options) { parent::_after_find ($result, $options); foreach ($result as $field = + $value) { $this->_parsetype ($result, $field);}}
All model classes inherit from Basemodel.
Originally, this has been done, but found Model.class.php _parsetype method has a low-level bug, look at the picture:
©2016, frozen fish. Please respect the author's labor results, copy reprint reservation site link! Application Development notes