1
In my application there are 2 related models and Shortcut and Role, where Role has several Shortcuts, the link between the two occurs normally, except when trying to create an input in the "save" view of the Shortcut controller to select an existing Role.
Model Shortcut
<?php
class Shortcut extends AppModel
{
public $name = 'Shortcut';
public $diplayField = 'title';
public $useTable = 'shortcuts';
public $belongsTo = array( 'Role' => array('className' => 'Role','foreignKey' => 'role_id' ) );
}
?>
Model Role
class Role extends AppModel
{
public $name ='Role';
public $useTable = 'roles';
public $displayField = 'title';
public function getAdminRole()
{
return 3;
}
public function getUserRole()
{
return 2;
}
public function getPublicRole()
{
return 1;
}
}
View/Shortcuts/Save
<?php echo $this -> Form -> create('Shortcut'); ?>
<table>
<tr>
<td>
<label>TÍTULO</label>
</td>
<td>
<?php echo $this -> Form -> input('title',array('label'=>null));?>
</td>
</tr>
<tr>
<td>
<label>LINK</label>
</td>
<td>
<?php echo $this -> Form -> input('link',array('label'=>null));?>
</td>
</tr>
<tr>
<td>
<label>PERMISSÃO</label>
</td>
<td>
<?php echo $this -> Form -> input('role_id',array('label'=>null));? >
</td>
</tr>
<tr>
<td>
<?php echo $this -> Form -> submit('Enviar',array('controller'=>'shortcuts','action'=>'save'));?>
</td>
</tr>
</table>
<?php echo $this -> Form -> end();?>
then, but in a previous project I just input the field referencing the other table, and it was already included in the options box, all the records of that table
– user5020
I found a business I didn’t know on manual, and edited the answer. See if this resolves.
– bfavaretto