下午好,所以我想检查我的数据库中的特定值在 CakePHP 上是否正确。
我的 SQL 表名为 Oral,如下所示
---------------------
|PK|OralPresentation|
---------------------
|1 |1 |
---------------------
所以我想要在我的 Controller 中做的是检查该 Value is OralPresentation 是否为 1。
我在下面的代码中这样做
$OralStatus = $this->Submission->query("SELECT * FROM Oral;");
//If Oral Presentations are activated
if($OralStatus['0']['PK']['OralPresentation']==1)
{
$this->set('Istrue','true'); //Passing this information to the view.
}
else
{
$this->set('Istrue','false');
}
}
现在,当我在我看来 echo isTrue 时,尽管数据库表为 1,它总是返回 false。我尝试过的另一个解决方案是在 IF 语句中
if($OralStatus['0']['PK']['OralPresentation'])
最佳答案
如果您知道要检查的 PK,则一种方便的方法是使用 field
。
$this->Oral->id = 1;
$Istrue = $this->Oral->field('OralPresentation'); // value for pk 1
$this->set(compact('Istrue'));
关于php - CakePHP 检查数据库中的特定值是否为 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39731178/