Model and Controle attached.
Add.thtml
--
<label>Materiais:
<?php echo $html->selectTag('Material/Material', $materials, null,
array('multiple' => 'multiple'));?>
<?php echo $html->tagErrorMsg('Material/Material', 'Error!');?>
</label>
<label>Pinturas:
<?php echo $html->selectTag('Pintura/Pintura', $pinturas, null,
array('multiple' => 'multiple'));?>
<?php echo $html->tagErrorMsg('Pintura/Pintura', 'Error.');?>
</label>
--
Using scaffold, the problem does not happen.
SQL:
CREATE TABLE `materiais` (
`id` int(10) unsigned NOT NULL,
`material` varchar(50) NOT NULL,
`is_ativo` tinyint(1) NOT NULL,
`atualizacao_at` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ix_material_unico` (`material`)
) TYPE=InnoDB AUTO_INCREMENT=6 ;
CREATE TABLE `pinturas` (
`id` int(10) unsigned NOT NULL,
`pintura` varchar(50) NOT NULL,
`is_ativo` tinyint(1) NOT NULL,
`atualizacao_at` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ix_pintura_unica` (`pintura`)
) TYPE=InnoDB AUTO_INCREMENT=4 ;
CREATE TABLE `produtos` (
`id` int(10) unsigned NOT NULL,
`grupo_id` int(10) unsigned NOT NULL,
`produto` varchar(50) NOT NULL,
`dimensao` varchar(50) NOT NULL,
`preco` decimal(11,2) NOT NULL,
`foto` varchar(200) NOT NULL,
`observacao` varchar(200) NOT NULL,
`is_novidade` tinyint(1) default NULL,
`is_promocao` tinyint(1) default NULL,
`is_ativo` tinyint(1) default NULL,
`atualizacao_at` timestamp NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `ix_produto_unico` (`produto`),
KEY `ix_grupo_produto` (`grupo_id`)
) TYPE=InnoDB AUTO_INCREMENT=1 ;
CREATE TABLE `produtos_materiais` (
`produto_id` int(10) unsigned NOT NULL,
`material_id` int(10) unsigned NOT NULL,
`atualizacao_at` timestamp NOT NULL,
PRIMARY KEY (`produto_id`,`material_id`),
KEY `material_id` (`material_id`)
) TYPE=InnoDB;
CREATE TABLE `produtos_pinturas` (
`produto_id` int(10) unsigned NOT NULL,
`pintura_id` int(10) unsigned NOT NULL,
`atualizacao_at` timestamp NOT NULL,
PRIMARY KEY (`produto_id`,`pintura_id`),
KEY `pintura_id` (`pintura_id`)
) TYPE=InnoDB;
On 11/29/06, clemos <[EMAIL PROTECTED]> wrote:
>
> hi aldemir
>
> you should probably post your code if you want help.
> we can't have any clue right now
>
> ++++++++
> clemos
>
> On 11/29/06, Aldemir Vieira <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I have problem with relateds (selectTag) HABTM in my (thtml), but when use
> > scaffold, the problem does not happen.
> > :
> >
> > Warning: htmlspecialchars() expects parameter 1 to be string, array given in
> > ..\htdocs\[approot]\cake\basics.php on line 558
> >
> > --
> > []´s,
> > Aldemir Vieira
> >
> >
> > >
> >
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Cake PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
<?php
class Produto extends AppModel
{
var $name = 'Produto';
var $displayField = 'produto';
var $belongsTo = array('Grupo' =>
array('className' => 'Grupo',
'order' => 'grupo ASC',
'foreignKey' => 'grupo_id'));
var $hasAndBelongsToMany = array('Material' =>
array('className' => 'Material',
'joinTable' =>
'produtos_materiais',
'foreignKey' => 'produto_id',
'associationForeignKey'=>
'material_id',
'unique' => true),
'Pintura' =>
array('className' => 'Pintura',
'joinTable' =>
'produtos_pinturas',
'foreignKey' => 'produto_id',
'associationForeignKey'=>
'pintura_id',
'unique' => true));
}
?><?php
class Material extends AppModel
{
var $useTable = 'materiais';
var $name = 'Material';
var $displayField = 'material';
var $hasAndBelongsToMany = array('Produto' =>
array('className' => 'Produto',
'joinTable' => 'produtos_materiais',
'foreignKey' => 'material_id',
'associationForeignKey'=> 'produto_id',
'uniq' => true));
}
?>
<?php
class Pintura extends AppModel
{
var $name = 'Pintura';
var $displayField = 'pintura';
var $hasAndBelongsToMany = array('Produto' =>
array('className' => 'Produto',
'joinTable' => 'pinturas_produtos',
'foreignKey' => 'pintura_id',
'associationForeignKey'=> 'produto_id',
'uniq' => true));
}
?><?php
class MaterialsController extends AppController
{
var $name = 'Materials';
var $scaffold;
}
?><?php
class PinturasController extends AppController
{
var $name = 'Pinturas';
var $scaffold;
}
?><?php
class ProdutosController extends AppController
{
var $name = 'Produtos';
function add()
{
$this->set('grupos', $this->Produto->Grupo->generateList('is_ativo <> 0',
'grupo', null, '{n}.Grupo.id', '{n}.Grupo.grupo'));
$this->set('materials', $this->Produto->Material->generateList('is_ativo
<> 0', 'material', null, '{n}.Material.id', '{n}.Material.material'));
$this->set('pinturas', $this->Produto->Pintura->generateList('is_ativo <>
0', 'pintura', null, '{n}.Pintura.id', '{n}.Pintura.pintura'));
if (!empty ($this->params['data']))
{
if ($this->Produto->save($this->data))
{
$this->Session->setFlash('O produto foi incluído com
sucesso','default',array(),'success');
// $this->redirect('/produtos/view/'.$this->Produto->getLastInsertId());
$this->render();
}
}
}
}
?>
<h2>Incluir um novo Produto</h2>
<?php echo
$html->formTag('/produtos/add/','post',array('enctype'=>'multipart/form-data')
); ?>
<fieldset>
<legend>Add a photo:</legend>
<?php echo $html->hidden('Produto/id'); ?>
<label>Grupo:
<?php echo $html->selectTag('Produto/grupo_id', $grupos,
$html->tagValue('Produto/grupo_id')); ?>
<?php echo $html->tagErrorMsg('Produto/grupo_id', 'O Grupo do
produto é requerido.'); ?>
</label>
<label>Nome do Produto:
<?php echo $html->input('Produto/produto', array('size'
=> '40')); ?>
<?php echo $html->tagErrorMsg('Produto/produto', 'O
nome do produto é requerido.'); ?>
</label>
<label>Dimensões (A x L x P):
<?php echo $html->input('Produto/dimensao',
array('size' => '20')); ?>
<?php echo $html->tagErrorMsg('Produto/dimensao', 'A
dimensão do produto é requerida.'); ?>
</label>
<label>Preço (em R$):
<?php echo $html->input('Produto/preco', array('size'
=> '12')); ?>
<?php echo $html->tagErrorMsg('Produto/preco', 'O preço
é inválido, informe no formato 9.999,99'); ?>
</label>
<label>Foto do produto (.gif .jpg .png):
<?php echo $html->fileTag('photoFile', array('size' =>
'100')); ?>
<?php echo $html->tagErrorMsg('Produto/foto', 'A foto
não foi informada corretamente.'); ?>
</label>
<label>
<?php echo $html->Checkbox('Produto/is_novidade');
?>Novidade?
</label>
<label>
<?php echo $html->Checkbox('Produto/is_promocao');
?>Promoção?
</label>
<label>
<?php echo $html->Checkbox('Produto/is_ativo'); ?>Ativo?
</label>
<label>Materiais:
<?php echo $html->selectTag('Material/Material',
$materials, null, array('multiple' => 'multiple', 'size'=>'5',
'class'=>'selectMultiple'));?>
<?php echo $html->tagErrorMsg('Material/Material',
'Escolha pelo menos um Material.');?>
</label>
<label>Pinturas:
<?php echo $html->selectTag('Pintura/Pintura',
$pinturas, null, array('multiple' => 'multiple', 'size'=>'5',
'class'=>'selectMultiple'));?>
<?php echo $html->tagErrorMsg('Pintura/Pintura',
'Escolha pelo menos uma Pintura.');?>
</label>
<label>Observações:
<?php echo $html->textarea('Produto/observacao',
array('rows'=>'8','cols'=>'50')); ?>
<?php echo $html->tagErrorMsg('Produto/observacao', 'A
observação é requerida.'); ?>
</label>
</label>
</fieldset>
<?php echo $html->submit('Confirmar'); ?>
</form>