Difference between $attributes and $classes in Drupal theming? - drupal-theming

In a panels TPL file I have the following, however this prints the classes out twice.
<div class="<?php print $classes; ?>" <?php print $id; ?> <?php print $attributes; ?>>
Is there a difference between this:
class="<?php print $classes; ?>"
and this?:
<?php print $attributes; ?>

As you can see, class="<?php print $classes; ?>", only prints the classes for the class attribute in the element, while the <?php print $attributes; ?> prints all the attributes for that element: class, style, value, style, custom attrs like "tag" or "visibility", etc...
So you print classes with both functions. Use the print $classes if you only want to print classes, and print $attributes if you want to print all item attributes, including classes.

Related

How to redirect to a particular page when we select any option in the dropdownlist in yii framework

<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo CHtml::activeDropDownList($model,'name',array('desktop'=>'desktop','server'=>'server','device'=>'device'),array('empty'=>'Select Option')); ?>
<?php echo $form->error($model,'name'); ?>
</div>
this is my form,when i select any one,then it should be navigate to particular page(desktop.php or server.php and device.php)
You can add an options key to htmlOptions array. As Yii's official document says:
options: array, specifies additional attributes for each OPTION tag. The array keys must be the option values, and the array values are the extra OPTION tag attributes in the name-value pairs.
Example:
array(
'value1'=>array('disabled'=>true,'label'=>'value 1'),
'value2'=>array('label'=>'value 2'),
);
In your case it could be:
<?php echo CHtml::activeDropDownList($model,'name',array('desktop'=>'desktop','server'=>'server','device'=>'device'),array('empty'=>'Select Option','options'=>array(
'desktop'=>array('onclick'=>'window.location="http://yourUrl.Url"'),
//and so on ...
))); ?>
You can take a look at yii's official documents for more information:
activeDropDownList()

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 -->

How to avoid Yii from Capitalize our labels?

If we call this:
<?php echo $form->label($model,'Hello my friend'); ?>
We get output it on the viewport the following:
"Hello My Friend"
On the CSS I have nothing that says capitalize, anywhere.
How can we change this behavior ?
I've tried to edit the CSS and make:
label {
text-transform: none !important;
}
No luck.
How can we have
Hello my friend
printed exactly as we write it ?
Instead of doing like this on the view file:
<?php echo $form->label($model, 'Hello my friend'); ?>
We have change it to:
<?php echo $form->label($model, 'hello_friend'); ?>
where hello_friend is defined on the respective model method attributeLabels(), like this:
'hello_friend' => 'Hello my friend')
So, as bool.dev properly says, we have to place the attribute name AND NOT a random string.

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);?>