I am trying to build a small cms to test CakePHP 2.x

In my PagesController (for displaying single sites), I use this code:

$page = $this->Page->findByNavtitle($name, array(
    'conditions' => array(
        'Page.visible' => '1',
        ),
    )
);

The result should only set when the record is marked as visible. But this codeblock throws an error.

The API describes, that just one parameter is allowed in these findBy magic methods.

How can I get the result with conditions?

有帮助吗?

解决方案

You cannot add conditions to findBy method. Instead use find:


$page = $this->Page->find('first', array(
  'conditions' => array(
    'Page.nav_title'     => $name,
    'Page.visible' => 1
  )
));

Hope it helps

其他提示

$this->Model->findAllBy(string $value, array $fields, array $order, int $limit, int $page, int $recursive);

Findbyid in cake php

$result = $this->Modelname->findById($id, array('Alpha.name'));

where $id is an id of record you're searching for and Alpha.name is a field you need (e.g. name from model Alpha)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top