11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【CakePHP】コントローラからビューに値を渡す

Last updated at Posted at 2014-08-22

コントローラーで以下のようにすることで、ビューに値を渡すことができる。

set(変数名,値)の例
$this->set('price',$price);
$this->set('titel',$title);

以下のように配列で一気にセットすることもできる。
下記は、上と同じ結果になる。

set(array(変数名=>値))の例
$this->set(
  [
    'price'=>$price,
    'titel'=>$title
  ]
)

さらに、compact()を使うと簡潔に記述できる。

set()とcompact()を組み合わせた例
$price = 500;
$title = 'hoge';

$this->set(compact('price','title'));
11
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
14

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?