tp5.0 query data

tp and get all the query data are used to query data in the form of an array, if a new object instance, it is used where, for better coding characteristics, with all arrays, additional string parsing the template double quotes, mixing the single quotes like, the operator does not take the point, data can be obtained in the form of an array

 

So what good is it, tp5.0 model must be instantiated class model, where the model is used, not the method of each controller in another a new model object, the direct use of static class on it

 

Static methods are both queries and get all

Category :: get (6) -> toArray (); // get the data id 6

Category :: get ([ 'name' => 'blog']) -> toArray (); // get the data for the blog name

all usage is similar

 

Both get and all, find and select need to use toArray turn about an array format

 

You need to be set in the model

protected $resultSetType = "collection"

Or write the configuration file database.php

'resultset_type'=>'think\collection'

 

 

Guess you like

Origin blog.csdn.net/phpergod/article/details/92609808