質問

I got a row from database table now I wish to echo only one value from this row in CakePHP. So how to do it?

$help = $this->help->findByControllerAndAction($controller ,$action)

it has four values: id, controller, action and help_text. I want to echo only controller. Any help?

役に立ちましたか?

解決

I suggest reading some of the documentation, more specifically this section.

To answer your question...

I assume your Help model has a unique key controller+action.

In your controller's method you will need:

$help = $this->Help->findByControllerAndAction($controller ,$action);
if ($help) {
    $this->set('help', $help);
}

In your view:

echo $help['Help']['controller'];

will show the content of the Help.controller field.

Use:

debug($help);

If $help is not defined in your view, chances are your find is not returning the results you expect.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top