I got a insert form. I would like to insert the below code into the form.
<?php
echo $html->image("slide_03.jpg", array(
"alt" => "Event Banner",
'class' => '',
));
?>
In my view layer I want the the image to be display. However, the image did not display and got this code in my view layer instead
image("slide_03.jpg", array( "alt" => "Event Banner", 'class' => '', )); ?>
In CakePHP 2.x you have to use $this->Html->image(). $html->image() was used in previous CakePHP versions and no longer works in CakePHP 2.x.
In general (not just for images) you can set option after or before if you want additional html elements near of your input element.
As you see from sample below you can combine input options with $this->Html->image().
<?php
echo $this->Form->input('field', array(
'before' => $this->Html->image(),
'after' => $this->Html->image(),
));
More details about options on documentation.
Related
I am dealing with the CGridView widget in Yii. I've customized most of it, but can't seem to customize the icons that appear when you click on the column headers to sort the data. (little arrows that point either up or down depending on the sort order) Also, the icons are completely gone after adding in the 'columns' option. A portion of the code in my view is below:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'pager' => array('cssFile' => '/css/myCss.css'),
'cssFile' => '/css/myCss.css',
'summaryText' => 'Showing {start} - {end} of {count} data rows.',
'htmlOptions' => array('id' => 'grid'),
'columns' => array(
array(
'name' => 'name',
'value' => '$data->name',
),
array(
'name' => 'description',
'value' => '$data->description',
),
array(
'name' => 'date',
'value' => '$data->date',
),
),
));
?>
Yii's documentation isn't clear at all on this and there doesn't seem to be anyone (that I could find) that also has this issue.
->Also, a related question:
How would I make each row an anchor link? I need each row to be a link to view the details about the clicked row. I know that cgridview provides view, edit, and delete links at the end of the row if told to, but is it possible to get the entire row to be a single anchor link? I know how to do this manually in html, but don't know how to do this inside cgridview.
If you want to change the icon in the header of the table, you will need to override styles for classes (.grid-view table.items th a.desc and .grid-view table.items th a.asc). You can also disable visual styles for the table by specifying an option: 'cssFile'=>false and set custom styles for grid.
In order to make the entire string anchor link is likely you will need to insert into each cell of the table with the necessary link url. To do this, add the following description of an array of strings:
'columns'=>array(
...
array(
'name'=>'name',
'value'=>'CHtml::link($data->name, "#myAnchor")',
'type'=>'html'
),
...
)
I am not sure what version of Yii you're working on, but let's try this code
<?php
'columns' => array(
array(
...
'type' => 'html',
'value'=>'CHtml::tag("a",array("class"=>"your-icon-class", "href"=>"#"))',
),
CHtml::form();
echo CHtml::activeDropDownList($model,'imei', $model->getCategories(),
array('prompt' => 'Select Employe',
'submit'=>'/mobitracker/index.php?r=details/pathmap',
'params'=>array('imei'=>'js: $(this).val()'),
));
CHtml::endForm();
When a user selects a item am submitting it to another page and processing there.
but now I need another data also to be sent, i.e date am using DJui datepicker widget
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => 'date_from',
'value' => $fromDateValue,
'htmlOptions' => array(
'size' => '10', // textField size
'maxlength' => '10', // textField maxlength
),
));
So once a user selects a employee and then selects a date I need data to be submitted.
How can I accomplish this using yii?
Thanks in advance.
Note: Am using PHP yii framework
<inputid="date_from" type="text" name="date_from" class="hasDatepicker">
The widget just simply generates a text box with the given settings including the name. You can totally take the name and process with it as usually by $_POST. Of cause you have to put that field into your form
...
$model->attributes=$_POST['Employee']; // access your form as you should have to do already
$model->date_from = $_POST['date_from']; // access date value
I am using Cakephp 2.2.3 version. When I create form using Cake form helpers, it automatically appends a div and label to the input type field. How to avoid it?
Following is the code:
<?php echo $this->Form->input('username', array('id' => 'username', 'class' => 'login-inp', 'type' => 'text')); ?>
You can use options array of input to avoid form appending div and label automatically. Set div and label of options array to false.
echo $this->Form->input('username',
array('id' => 'username', 'class' => 'login-inp',
'div' => false, 'label' => false
)
);
That's what FormHelper::input() is supposed to do. If you don't want the label and wrapping div just use the functions to generate specific input elements only like FormHelper::text(), FormHelper::select(), FormHelper::radio(), etc.
echo $this->Form->create('AmazonMatches', array('action' => 'selectMatches'));
echo $this->Form->input('option_id', array('options' => $allAmazonMatches, 'type' => 'radio'));
echo $this->Form->end(__('Submit', true));
Now I see a box around my radio buttons with a large red text saying "Option Id".
How can i get rid of it? Sorry I am a total Cake noob.
You need to set the 'legend' option to false if you don't want to show it, or to a string if you want to customize the message:
echo $this->Form->input('option_id', array(
'options' => $allAmazonMatches,
'type' => 'radio',
'legend' => false
));
$this->Form->input
Creates one input field with the id provided. You'll have to create multiple inputs inorder to make your checkboxes work separately.
There could be better methods, but doing it something likethis will work.
foreach($allAmazonMatches as $amazonMatch)
{
$this->Form->input...
}
How do i use the inputDefaults to add a common class to all the input elements in my form. also pls give a brief description of the inputDefaults.
isn't it:
echo $this->Form->create('User', array(
'inputDefaults' => array(
'class' => 'someclass'
)
);
`
You should read the cookbook. theres a good example: http://book.cakephp.org/view/1639/options-inputDefaults
When you create a form you add inputdefaults key in options:
echo $this->Form->create('User', array(
'inputDefaults' => array(
'div' => array('class' => 'someclass')
)
);
After browsing the source file i didn't find anything either. So the only way is to use it explicitly for every call to the input function.