Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass simple data from controller to view in cakePHP

I get an int value to the controller and I would like to send it to the according view, but i am either passing or accesing it wrong. Here is what I am trying to do:

Controller:

function send($int = NULL) {
    $this->set('integer', $int);

}

View:

echo $integer['int']

Your help is much appreciated!

like image 927
Johhny P Avatar asked Jan 10 '13 09:01

Johhny P


People also ask

How to pass variable from Controller to view in CakePHP?

By this set() function, we can pass a value to the view template, and we can add any variable from the controller by use of set(). This set variables will be available in both the view and the layout of your action renders.

What is element in CakePHP?

Many applications have small blocks of presentation code that need to be repeated from page to page, sometimes in different places in the layout. CakePHP can help you repeat parts of your website that need to be reused. These reusable parts are called Elements.


1 Answers

Change

echo $integer['int']

To:

echo $integer;

The first parameter in $this->set is used as the variable name in your view, the second parameter is the value assigned to that variable.

like image 189
cowls Avatar answered Sep 21 '22 09:09

cowls