這裏是我的模型:建立在我的模型中的任意屬性
class Persona extends AppModel {
// This is just some arbitrary property I need to populate in the controller.
public $TipoPersona = '';
}
這裏是我的控制器操作功能:
public function details($id = null) {
// Just a typical load by id.
$this->Persona->id = $id;
$this->set('persona', $this->Persona->read());
// Can I do something like?
$this->Persona->TipoPersona = "Mafa Woogly";
}
我如何可以設置$TipoPersona
屬性中的「模型」這裏?我的意圖是,然後在視圖中使用該屬性,如:
<tr>
<th>Tipo de Persona:</th>
<td><?php echo h($persona->TipoPersona); ?></td> // Or similar?
</tr>
有什麼建議嗎?
這種方式很有效,但感覺不夠好而且沒有強類型。
public function details($id = null) {
$this->Persona->id = $id;
$this->set('persona', $this->Persona->read());
$this->set('tipoPersona', "Mafa woogly");
}
<tr>
<th>Tipo de Persona:</th>
<td><?php echo h($tipoPersona); ?></td>
</tr>