CakePHP和tinyint作为布尔值
问题描述:
如何强制CakePHP 2.x检索tinyint数据库列不是布尔值,而是tinyint?
How can I force CakePHP 2.x to retrieve tinyint database column not as boolean but as tinyint?
MySQL:
Column | type
-------------------------------
... | ...
category_id | tinyint(1)
... | ...
CakePHP:
$this->request->data = $this->Question->read();
var_dump($this->request->data['Question']['category']);
该值始终为0(如果我将提取的问题归类为类别ID 0)或1 (如果问题有任何其他类别ID)。
The value is always 0 (if the question I'm fetching as the category id 0) or 1 (if the question has any other category id).
答
使用 TINYINT c $ c>。如果长度为1,Cake将其视为布尔值。
Use TINYINT(2)
instead. If the length is 1, Cake sees it as a boolean.