Ok, very new to Yii - awesome framework and learning fast! A bit unsure how to do the following; this is what I have so far…
I have two tables in MySQL (client & job), both innoDB and a relational link one:many like so: client:id - job:clientid. It is set from within mysql using the foreign key.
(I also have a jobdet table linked to job table and holds 1:many enties as well - outside the scope of this question but here for more info)
I have modelled & crud’d both client and job, and have modified the client/admin’s gridview to have an additional button to allow a new job to be created;
In client/admin.php,
array(
'class'=>'CButtonColumn',
'template'=>'{view} {update} {delete} {newjob}',
'header'=>'Actions',
'buttons'=>array('newjob' => array(
'label'=>'New Job',
'url'=>'Yii::app()->createUrl("job/create",array("clientid"=>$data->id))',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/job.png',
),
),
'htmlOptions'=>array('width'=>75),
),
The idea is there has to be an existing client record in order for a new job to be created for it. I figured the best way was to harness the existing client model to find or create a new client and then click the button to create the new job. Clicking this button jumps me to the job model where we start entering in the new job details - my issue is how we pass clientid to the job form and subsequent table…
I have tried the following (which does pass clientid & populates the form’s field) but I think is not very elegant and also I want the job form to show the client’s name (client:firstname & client:lastname), while at the same time placing clientid value to the table.
Also, if I am having issues hiding the field clientid because validation fails saying it cannot be empty.
In job/_form.php,
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'job-form',
'enableAjaxValidation'=>false,
)); ?>
<?php
if(!empty($_GET['clientid'])) {
$cid = $_GET['clientid'];
echo 'DEBUG:cid = '.$cid; // my debug - just to see if it works...
$model->clientid=$cid; // set the value here
} else {
echo "DEBUG:cid not set!";
}
?>
etc...
My gutfeeling says there is a much more simpler or standard way of doing this…
Any ideas or a better way? Many many thanks in advance guys!