Array
(
)

Fazer Join de três tabelas no Yii Framework

Edigar
   - 11 abr 2015

Tenho três tabelas em que cada uma possui um custo, e tenho uma tabela 'ORÇAMENTO' em que tenho que " PUXAR " o custo dessas três tabelas.
Como desenvolvo essa situação ?
Obrigado.

Marisiana
   - 15 abr 2015

Posta a estrutura dessas tabelas, com os campos e as Primary Key e Foreign Key...

Edigar
   - 16 abr 2015

Classe buffet

<?php
/* @var $this BuffetController */
/* @var $model Buffet */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'buffet-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>

<p class="note"><span class="required">*</span> Campos Obrigatórios.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,'tipo'); ?>
<?php echo $form->textField($model,'tipo',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'tipo'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'quantidadeconvidados'); ?>
<?php echo $form->textField($model,'quantidadeconvidados'); ?>
<?php echo $form->error($model,'quantidadeconvidados'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'custo'); ?>
<?php
$this->widget('CMaskedTextField', array(
'model' => $model,
'attribute' => 'custo',
'mask' => 'R$ 9.999,99',
'htmlOptions' => array('size' => 10, 'class' => 'input-small')
))
?>
<?php echo $form->error($model,'custo'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'responsavel_evento'); ?>
<?php echo $form->textField($model,'responsavel_evento',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'responsavel_evento'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Cadastrar' : 'Salvar'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

classe decoracao

<?php
/* @var $this DecoracaoController */
/* @var $model Decoracao */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'decoracao-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>

<p class="note"><span class="required">*</span> Campos Obrigatórios.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,'tema'); ?>
<?php echo $form->textField($model,'tema',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'tema'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'cores'); ?>
<?php echo $form->textField($model,'cores',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'cores'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'flores'); ?>
<?php echo $form->textField($model,'flores',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'flores'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'custo'); ?>
<?php echo $form->textField($model,'custo',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'custo'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'responsavel_evento'); ?>
<?php echo $form->textField($model,'responsavel_evento',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'responsavel_evento'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Cadastrar' : 'Salvar'); ?>
</div>

<?php $this->endWidget(); ?>

Classe Orcamento (onde tem que se realizar a soma dessas tabelas anteriormente)

<?php
/* @var $this OrcamentoController */
/* @var $model Orcamento */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'orcamento-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>

<p class="note"><span class="required">*</span> Campos Obrigatórios.</p>

<?php echo $form->errorSummary($model); ?>

<div class="row">
<?php echo $form->labelEx($model,'valor'); ?>
<?php echo $form->textField($model,'valor'); ?>
<?php echo $form->error($model,'valor'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'dataemissao'); ?>
<?php echo $form->dateField($model,'dataemissao'); ?>
<?php echo $form->error($model,'dataemissao'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'numeroconvidados'); ?>
<?php echo $form->textField($model,'numeroconvidados'); ?>
<?php echo $form->error($model,'numeroconvidados'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'dataevento'); ?>
<?php echo $form->dateField($model,'dataevento'); ?>
<?php echo $form->error($model,'dataevento'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'responsavelevento'); ?>
<?php echo $form->textField($model,'responsavelevento',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'responsavelevento'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'cerimonialista'); ?>
<?php echo $form->textField($model,'cerimonialista',array('size'=>3,'maxlength'=>3)); ?>
<?php echo $form->error($model,'cerimonialista'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'dj'); ?>
<?php echo $form->textField($model,'dj',array('size'=>3,'maxlength'=>3)); ?>
<?php echo $form->error($model,'dj'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'fotomaluca'); ?>
<?php echo $form->textField($model,'fotomaluca',array('size'=>3,'maxlength'=>3)); ?>
<?php echo $form->error($model,'fotomaluca'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'fotos'); ?>
<?php echo $form->textField($model,'fotos',array('size'=>3,'maxlength'=>3)); ?>
<?php echo $form->error($model,'fotos'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'bar'); ?>
<?php echo $form->textField($model,'bar',array('size'=>3,'maxlength'=>3)); ?>
<?php echo $form->error($model,'bar'); ?>
</div>

<div class="row">
<?php echo $form->labelEx($model,'brinquedos'); ?>
<?php echo $form->textField($model,'brinquedos',array('size'=>3,'maxlength'=>3)); ?>
<?php echo $form->error($model,'brinquedos'); ?>
</div>
<p> Escolha abaixo os serviços adiconais que o salão oferece a você!</p>
<div class="row">
<?php echo $form->labelEx($model,'adicionais'); ?>
<?php echo $form->textField($model,'adicionais',array('size'=>45,'maxlength'=>45)); ?>
<?php echo $form->error($model,'adicionais'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Cadastrar ' : 'Salavar'); ?>
</div>

<?php $this->endWidget(); ?>

Era isso que queria ? Pois sou novo com essa ferramenta. Obrigado

Randrade
   - 16 abr 2015


Citação:
Posta a estrutura dessas tabelas, com os campos e as Primary Key e Foreign Key...


Creio que ela se referia as tabelas no banco de dados.

P.S: Utilize a tag [ [tagcod] (Inserir código), quando for postar algum código, para ficar mais legível para todos.

Marcos P
   - 16 abr 2015

Edigar,

Sua dúvida é do lado do banco de dados ou do lado do PHP ?

Edigar
   - 16 abr 2015

Classe buffet

primay key id_buffet
custo double
foreign key id_orcamento

Classe decoracao
primary key id_buffet
custo double
foreing key id_orcamento

classe orcamento
id_orcamento
custo total

seria isso ?

Marisiana
   - 16 abr 2015

Sim, são as tabelas do banco..
Não entendi muito bem a lógica da modelagem dos dados, mas talvez assim você consiga obter o resultado:
#Código

select dec.id_buffet,
          dec.id_orcamento,
          dec.custo as custo_decoracao
          b.custo as custo_buffet,
          or.custo_total as custo_orcamento
from decoracao dec
inner join buffet b
on dec.id_buffet = b.id_buffet
inner join orcamento or
on dec.id_orcamento = or.id_orcamento

Marisiana
   - 23 abr 2015

Edigar, você conseguiu fazer o SQL?
A solução que apresentei te ajudou?