Cakephp 如何仅使用findBySlug方法获取ID
例如,尝试通过CakePHP中的findBySlug方法获取IDCakephp 如何仅使用findBySlug方法获取ID,cakephp,Cakephp,例如,尝试通过CakePHP中的findBySlug方法获取ID $this->Page->findBySlug(1); 这将返回所有字段,但我只需要返回ID,我已经搜索了很多,但也找不到函数引用,并尝试以下操作,但得到一个错误 $this->Page->findBySlug(15, array('fields'=>array('Page.id'))); 函数中是否有不使用自定义查询的解决方案?cakephp2 $page = $this->Page-&
$this->Page->findBySlug(1);
这将返回所有字段,但我只需要返回ID,我已经搜索了很多,但也找不到函数引用,并尝试以下操作,但得到一个错误
$this->Page->findBySlug(15, array('fields'=>array('Page.id')));
函数中是否有不使用自定义查询的解决方案?cakephp2
$page = $this->Page->findBySlug(1, array('id'));
$id = $page['Page']['id'];
cakephp3
$page = $this->Pages->findBySlug(1)
->select('id');
$id = $page->id;
您使用的是哪个版本的cakephp?
但出现错误
-错误应该在问题中;请注意findBy(字符串$value[,混合$fields