Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bo noite
Estou apreendendo o cakephp e estou com uma duvida com relação a relacionamento
Exemplo:
<?php
class Anunciante extends AppModel {
var $name = 'Anunciante';
var $primaryKey = 'anunciante_codigo';
var $belongsTo = array('Categoria'=>array( 'className'=>'Categoria','foreignKey'=>'categoria_codigo'));
}
?>
<?php var $name = 'Categoria';
var $primaryKey = 'categoria_codigo';
var $hasMany =array('Anunciante'=> array('className'=>'Anunciante','foreignKey'=>'categoria_codigo'));
}
?>
Agora no controle fiz assim:
$this->set('anunciantes', $this->Categoria->find('all', array('conditions' => array('categoria_codigo' => $codigo))));
As minhas duvida e:
Esta certo eu preciso fazer a declaração nos dois model para efetuar um relacionamento mesmo?
E para exibir no view, qual e a forma correta de pecorre?
esta me retonando o seguinte array:
Array ( [0] => Array ( [Categoria] => Array ( [categoria_codigo] => 1 [categoria_titulo] => teste [categoria_ordem] => 1 ) [Anunciante] => Array ( [0] => Array ( [anunciante_codigo] => 1 [categoria_codigo] => 1 [anunciante_titulo] => nome da empresa [anunciante_descricao] => descrição [anunciante_atividades] => [anunciante_cep] => 000000 [anunciante_endereco] => hgfhgfhgf [anunciante_bairro] => ghgdghdghf [anunciante_cidade] => bvvhjvhjhvj [anunciante_estado] => df [anunciante_pais] => [anunciante_mapa] => [anunciante_website] => [anunciante_email] => teste@ig.com.br [anunciante_telefones] => (12) 3316-0000 [anunciante_situacao] => 1 [anunciante_palavras_chave] => ) [1] => Array ( [anunciante_codigo] => 2 [categoria_codigo] => 1 [anunciante_titulo] => teste teste [anunciante_descricao] => teste... [anunciante_atividades] => [anunciante_cep] => [anunciante_endereco] => sgfgsfgfgfgd [anunciante_bairro] => gfdgfgdfgdfg [anunciante_cidade] => dfgfdgfdgfdg [anunciante_estado] => df [anunciante_pais] => [anunciante_mapa] => [anunciante_website] => [anunciante_email] => ggff@ig.com.br [anunciante_telefones] => (27) 3316-0000 [anunciante_situacao] => 0 [anunciante_palavras_chave] => ) ) ) )
Desde já agradeço
Carregando comentários...