Cakephp Radio Buttons from Database Entries - radio-button

Good day!
I have a database table called Complaints which has the following fields
id and description. Is it possible that the values in the complaints table be used as radio button input fields? Such as if the table contains 10 entries there will be 10 radio buttons.

<?php foreach($data as $key=>$value){?>
<input type="radio" name="name" id="<?php echo $value['id']; ?>" onclick=""/>
<?php echo $value['id']; ?>
<?php }
?>

Related

readonly textfield using scenarios yii

How can I disable textfield using scenarios in yii? I have 3 classes of accounts superadmin, admin and normal users. All 3 classes of users have access to update information about them but one of the field accountId can be updated by superadmin and admin only but that field should be displayed to users also. Currently I am doing it in the following way.
<div class="row">
<?php echo $form->labelEx($user,'accountID'); ?>
<?php
if(Yii::app()->user->checkAccess('admin'))
echo $form->textField($user,'accountID',array('size'=>32,'maxlength'=>32));
else
echo $form->textField($user,'accountID',array('size'=>32,'maxlength'=>32, 'disabled'=>'true'));?>
<?php echo $form->error($user,'accountID'); ?>
</div>
This method has solved my problem but it is not a good method and better method is using scenarios. How can I implement same using scenarios?
what i do is i create a function that checks if the user has access. This will lessen my code to make it easier to maintain.
echo $form->textField($user,'accountID',array('size'=>32,'maxlength'=>32,checkAccess($userId)));?>
// my function
function checkHTMLUserAccess($userId){
// Some codes
if ($hasAccess) return array('disabled'=>true);
else return array();
}
something like that :)
<div class="row">
<?php echo $form->labelEx($user,'accountID'); ?>
<?php echo $form->textField($user,'accountID',array('size'=>32,'maxlength'=>32, 'disabled'=>Yii::app()->user->checkAccess('admin'))); ?>
<?php echo $form->error($user,'accountID'); ?>
</div>

Showing a specific attribute when generating CRUD in Yii web framwork using giix extenstion

I am generating Models and CRUD for my database tables using giix in YII web framework, the thing is I want to change some of the attributes that showed to me but I dont know how ? I get into the code _FORM.php of the generated CRUD to one of the table and I knew the piece of code that I must change it to get a different attribute instead of one that shown to me without knowing why ?
<div class="row">
<?php echo $form->labelEx($model,'idEmployee'); ?>
<?php echo $form->dropDownList($model, 'idEmployee', GxHtml::listDataEx(Employee::model()->findAllAttributes(null, true))); ?>
<?php echo $form->error($model,'idEmployee'); ?>
</div><!-- row -->
in the previous code the form showed a drop-down list from another table jointed with the current table according to idEmployee, he's showing an attribute that I dont want, I want to know how to render the FirstName and the LastName in the drop-down list, any help please ?
I believe it is easier when you just create your own dropdown list provider
in the Employee.php you add these two functions:
public function getFullName()
{
return $this->first_name.' '.$this->last_name; // or what ever you want to be shown on the drop list
}
public static function getNamesList() {
return CHtml::listData(self::model()->findAll(), 'idEmployee', 'fullName');
}
in the _FORM.php write:
<div class="row">
<?php echo $form->labelEx($model,'idEmployee'); ?>
<?php echo $form->dropDownList($model, 'idEmployee', Employee::getNamesList()); ?>
<?php echo $form->error($model,'idEmployee'); ?>
</div><!-- row -->

yii framework: how to i put a label to a radio button? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Yii CHtml::radioButtonList - CSS to align horizontally
Am new to yii framework and the doubt might be silly!
I want to write a radio button code with its label next to it!
My code is as follows
<div class="column">
<?php echo $form->radioButton($model,'radio',false); ?>
<?php echo $form->error($model,'radio'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'I need a room'); ?>
</div>
But it doesnt look nice! Is there any better way of doing this?
I got the code online! Sharing it of that it can be useful for someone in future
<?php echo $form->radioButtonList($model,'radio',array('m'=>'male','f'=>'female'),array('separator'=>'', 'labelOptions'=>array('style'=>'display:inline'))); ?>
The following code will create a label for the radiobutton created with the 'radio' attribute. Place this code after the 'echo $form->radiob.....'
<?php echo CHtml::activeLabel($model, 'radio', array('label' => 'My Label', 'style'=>'display:inline')); ?>
Use the display:inline or add a css class to get the label exactly where you want.

Multiplying values from a textbox in Yii

I'm new to Yii, and I'm trying to compute values from textboxes. I want the computation codes to be on the same form where the textbox is being displayed (since the product will also be shown on a textbox of the same form where they will input the factors). I've tried this guess, but it didn't work. How do I fix this problem?
<div class="row">
<?php echo $form->labelEx($model,'Quantity_In_Pieces'); ?>
<?php echo $form->textField($model,'Quantity_In_Pieces',array('Quantity_In_Pieces' => ('Quantity').val() * ('Hold').val());?>
<?php echo $form->error($model,'Quantity_In_Pieces'); ?>
</div>
seems like you are trying to write jQuery where there should be php code.
<?php echo $form->textField($model,'Quantity_In_Pieces',array('Quantity_In_Pieces' => $model->quantity * $model->hold);?>

Multiplying values from a textbox in Yii Framework

i'm new to Yii and I'm trying to compute values from textboxes. I want the computation codes to be on the same form where the textbox is being displayed (since the product will also be shown on a textbox of the same form where they will input the factors). I've tried this guess, but it didn't work. How do I fix this problem?
<div class="row">
<?php echo $form->labelEx($model,'Quantity_In_Pieces'); ?>
<?php echo $form->textField($model,'Quantity_In_Pieces',array('Quantity_In_Pieces' => ('Quantity').val() * ('Hold').val());?>
<?php echo $form->error($model,'Quantity_In_Pieces'); ?>
</div>
As i understood, you need to add the textField on your ActiveForm and to set its value calculated from two another textfields. In this case you should use Chtml::textfield(...) with value = ($model->Quantity) * ($model->Hold). I mean smth like
echo Chtml::textField('Quantity_In_Pieces', ($model->Quantity) * ($model->Hold));