سؤال

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