Sample code for thinkphp to automatically complete session assignment in the model

  • 2021-07-18 07:17:32
  • OfStack

I believe that users who have used thinkphp know that the model of thinkphp can complete many auxiliary functions, such as automatic verification, automatic completion, etc. Today, in the development, they need to obtain session values and then automatically assign them. See the code for details;


class ArticlelModel extends Model {

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

// This function gets the session In name Value 
protected function getName(){
return $_SESSION["name"];
}
}

Here, we should pay attention to the difference between the last parameter function and callback.
function: If you use a function, you will automatically go to Common/common. php to find the corresponding function;
callback: Use callback methods defined in the current model


Related articles: