I have followed the example here Yii Wiki but the result i am getting is an empty page followed by the Application Log.
I have two tables users and businesses, users contains personal info and businesses contains the username/password data.
My FK is set in the database where the PK user_id is a FK in businesses.
My code is as follows
UsersController.php
public function actionCreate()
{
$users = new Users;
$businesses = new Businesses;
if(isset($_POST['Users'], $_POST['Businesses']))
{
// populate input data to $users and $businesses
$users->attributes=$_POST['Users'];
$businesses->attributes=$_POST['Businesses'];
// validate both $users and $businesses
$valid=$users->validate();
$valid=$businesses->validate() && $valid;
if($valid)
{
$users->save();
$businesses->save();
}
else
{
// redirect user to form
$this->redirect(array('create'));
}
// sign new user in and redirect to private area
$this->render('private/index', array(
'users'=>$users,
'businesses'=>$businesses,
));
}
}
Users.php to show my relationships
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'accounts' => array(self::HAS_MANY, 'Accounts', 'user_id'),
'businesses' => array(self::HAS_MANY, 'Businesses', 'user_id'),
'country' => array(self::BELONGS_TO, 'Countries', 'country_id'),
);
}
users/_form.php
<?php echo CHtml::beginForm() ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo CHtml::errorSummary(array($users, $businesses)); ?>
<div class="row">
<?php echo $form->labelEx($users,'sponsor_id'); ?>
<?php echo $form->textField($users, 'sponsor_id'); ?>
<?php echo $form->error($users,'sponsor_id'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($businesses, 'username'); ?>
<?php echo $form->textField($businesses, 'username'); ?>
<?php echo $form->error($businesses, 'username'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($businesses, 'password'); ?>
<?php echo $form->textField($businesses, 'password'); ?>
<?php echo $form->error($businesses, 'password'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($users,'email'); ?>
<?php echo $form->textField($users,'email',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($users,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($users,'first_name'); ?>
<?php echo $form->textField($users,'first_name',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($users,'first_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($users,'last_name'); ?>
<?php echo $form->textField($users,'last_name',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($users,'last_name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($users,'phone'); ?>
<?php echo $form->textField($users,'phone'); ?>
<?php echo $form->error($users,'phone'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'street'); ?>
<?php echo $form->textField($model,'street',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'street'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($users,'city'); ?>
<?php echo $form->textField($users,'city',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($users,'city'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($users,'zip'); ?>
<?php echo $form->textField($users,'zip',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($users,'zip'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($users,'country_id'); ?>
<?php echo $form->dropDownList($users,'country_id', CHtml::listData(Countries::model()->findAll(), 'country_id', 'country_name'), array('empty'=>'Please Select a Country')); ?>
<?php echo $form->error($users,'country_id'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($users->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php echo CHtml::endForm(); ?>
and finally users/create.php
<?php echo $this->renderPartial('_form', array('users'=>$users, 'businesses'=>$businesses)); ?>
Because I’m not getting any PHP errors I can only conclude it has to do with the Html render part of the example.
Could someone help me with this issue please…