我在我的应用程序中提交了一些文本输入。我想以大写形式保存所有数据。在保存我的数据之前,我如何在蛋糕 php 中使用“strtoupper”函数?
如果您想在保存之前将模型中特定字段的所有数据转换为大写,您应该使用 CakePHP 中的 beforeSave 过滤器
http://book.cakephp.org/2.0/en/models/callback-methods.html#beforesave
public function beforeSave($options = array()) {
if (!empty($this->data['Model']['field']) {
$this->data['Model']['field'] = strtoupper($this->data['Model']['field']);
}
return true;
}
Run Code Online (Sandbox Code Playgroud)