{PT} - 3.5.3.1.1 set

set(string $var, mixed $value)

O método set() é a principal forma de enviar dados do seu controller para sua view. Um vez que você usou set(), a variável pode ser acessada na sua view.

<?php
    
// Primeiro você passa os dados do controller:

$this->set('cor', 'pink');

// Então, na view, você pode utilizar os dados:

Você selecionou a cor <?php echo $cor; ?> para colorizar o cake.

?>
  1. <?php
  2. // Primeiro você passa os dados do controller:
  3. $this->set('cor', 'pink');
  4. // Então, na view, você pode utilizar os dados:
  5. Você selecionou a cor <?php echo $cor; ?> para colorizar o cake.
  6. ?>

O método set() também pega um array associativo como seu primeiro parâmetro. Esse pode ser geralmente uma caminho rápido para atribuir um grupo de informações para a view. Perceba que os índices de seu array sofrerão inflection antes de serem atribuídos à view ('indice_com_underline' se torna 'indiceComUnderline', etc.):

<?php
    
$dados = array(
    'cor' => 'pink',
    'tipo' => 'açucar'’,
    'preco_base' => 23.95
);

// fazem $cor, $tipo, e $precoBase
// disponíveis na view:

$this->set($data);  

?>
  1. <?php
  2. $dados = array(
  3. 'cor' => 'pink',
  4. 'tipo' => 'açucar',
  5. 'preco_base' => 23.95
  6. );
  7. // fazem $cor, $tipo, e $precoBase
  8. // disponíveis na view:
  9. $this->set($data);
  10. ?>

{EN} - 3.5.3.1.1 set

set(string $var, mixed $value)

The set() method is the main way to send data from your controller to your view. Once you've used set(), the variable can be accessed in your view.

<?php
    
//First you pass data from the controller:

$this->set('color', 'pink');

//Then, in the view, you can utilize the data:
?>

You have selected <?php echo $color; ?> icing for the cake.
  1. <?php
  2. //First you pass data from the controller:
  3. $this->set('color', 'pink');
  4. //Then, in the view, you can utilize the data:
  5. ?>
  6.  
  7. You have selected <?php echo $color; ?> icing for the cake.

The set() method also takes an associative array as its first parameter. This can often be a quick way to assign a set of information to the view.

Array keys will be inflected before they are assigned to the view ('underscored_key' becomes 'underscoredKey', etc.):

<?php
    
$data = array(
    'color' => 'pink',
    'type' => 'sugar',
    'base_price' => 23.95
);

//make $color, $type, and $basePrice 
//available to the view:

$this->set($data);  

?>
  1. <?php
  2. $data = array(
  3. 'color' => 'pink',
  4. 'type' => 'sugar',
  5. 'base_price' => 23.95
  6. );
  7. //make $color, $type, and $basePrice
  8. //available to the view:
  9. $this->set($data);
  10. ?>

Diferenças

Lines: 1-33Lines: 1-32
 <title>set</title> <title>set</title>
 <p class="method"><code>set(string $var, mixed $value)</code></p> <p class="method"><code>set(string $var, mixed $value)</code></p>
-<p>The &lt;code>set()</code> method is the main way to send data from your controller to your view. Once you've used <code>set()</code>, the variable can be accessed in your view.</p> +<p>O todo set() é a principal forma de enviar dados do seu controller para sua view. Um vez que você usou set(), a variável pode ser acessada na sua view.</p>
 <pre> <pre>
 &lt;?php &lt;?php
   
-//First you pass data from the controller: +// Primeiro vo passa os dados do controller:
-$this-&gt;set('color', 'pink'); +$this-&gt;set('cor', 'pink');
-//Then, in the view, you can utilize the data:
?&gt;
+// Então, na view, você pode utilizar os dados:
-You have selected &lt;?php echo $color; ?&gt; icing for the cake. /></pre>
<p>The <
code>set()&lt;/code> method also takes an associative array as its first parameter. This can often be a quick way to assign a set of information to the view.</p>
+Vo selecionou a cor &lt;?php echo $cor; ?&gt; para colorizar o cake.
-&lt;p class=&quot;note&quot;>Array keys will be inflected before they are assigned to the view ('underscored_key' becomes 'underscoredKey', etc.):</p> +?&amp;gt; />&lt;/pre&gt;
<p
>O método set() também pega um array associativo como seu primeiro parâmetro. Esse pode ser geralmente uma caminho rápido para atribuir um grupo de informações para a view. Perceba que os índices de seu array sofrerão inflection antes de serem atribuídos à view ('indice_com_underline' se torna 'indiceComUnderline', etc.):</p>
 <pre> <pre>
 &lt;?php &lt;?php
   
-$data = array(
'color' =&gt; 'pink',
'type' =&gt; 'sugar',
'base_price' =&gt; 23.95
+$dados = array(
'cor' =&gt; 'pink',
'tipo' =&gt; 'ucar',
'preco_base' =&gt; 23.95
 ); );
-//make $color, $type, and $basePrice
//available to the view:
+// fazem $cor, $tipo, e $precoBase
// disponíveis na view:
 $this-&gt;set($data);  $this-&gt;set($data);
 ?&gt; ?&gt;