I have one table where I am saving field name.
Now I want to use those fields in another model. So, How can I give name to that field?
e.g.
I have table named as Config with fields(id,key).
Data can be
1, Blog url
2, Site url
Now, I have 1 form where admin will add those value to database.
In Yii2 we create input field like
<?= $form->field($model, 'name')->textInput() ?>
But I want to create two textboxes with name blog url and site url.
So, How can I create it? What I have to write in place of name?
run this code on your command prompt
php composer.phar require --prefer-dist wbraganca/yii2-dynamicform "*"
after completion of above code.
add the following code in your form.
_form.php
<div class="panel panel-default">
<div class="panel-heading"><h4><i class="glyphicon glyphicon-envelope"></i> Addresses</h4></div>
<div class="panel-body">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $modelsAddress[0],
'formId' => 'dynamic-form',
'formFields' => [
'name',
],
]); ?>
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelsAddress as $i => $modelAddress): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Address</h3>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelAddress->isNewRecord) {
echo Html::activeHiddenInput($modelAddress, "[{$i}]id");
}
?>
<?= $form->field($model, "[{$i}]name")->textInput(['maxlength' => true]) ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
</div>
Related
I've got a following code:
<?php if(UserModel::getInstance()->isLoggedIn()) { ?>
<a class="modal-trigger waves-effect waves-light red btn right" href="#modalNewTopic">+ Add New Topic</a>
<?php } ?>
<?php if(UserModel::getInstance()->isLoggedIn()) { ?>
<div id="modalNewTopic" data-ignore="true" class="modal">
<div class="modal-content">
<h4>Add New Topic</h4>
</div>
<div class="modal-footer">
asdf
</div>
</div>
When I click on a button nothing is showed up. No errors were triggered in javascript console. What could be the problem?
You need to initialise the modal plugin before you can use it. Add this to your JS file:
$(document).ready(function() {
$('.modal').modal();
});
Can you format the style of the DropDownList in yii2 I have the following code that generates a list from a table and I wanted to change the text size and color of the items to choose from.
<div class="form-group search-form">
<?php
echo $form->field($model, 'spec')
->dropDownList(
$specialities,
['prompt'=>'Any Speciality']
)->label('');
?>
</div><!--end of form-group-->
should be the options
<div class="form-group search-form">
<?php
echo $form->field($model, 'spec')
->dropDownList(
$specialities,
['prompt'=>'Any Speciality',
'options' => ['style' => 'color: #FA4577; font-size: 18px;'],]
)->label('');
?>
</div><!--end of form-group-->
I am facing a problem with showing the recently viewed products in my product page.
Here is my local.xml code:
<catalog_product_view translate="label"> reference name="root"> <action method="setTemplate">page/1column.phtml <block type="reports/product_viewed" name="product.recently.viewed" as="product_recently_viewed" template="reports/product_viewed.phtml"/></block></reference>
Here is my footer.phtml code:
<div class="footer-container">
<div class="footer">
<?php $maniPage = $this->getUrl('');
$currentUrl = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($currentUrl);
if ($maniPage == $currentUrl){
echo $this->takeCategory(12,1) /*12 = brands category 1 = show images*/ ;
}
?>
<div class="block-content">
<?php echo $this->getChildHtml('product_recently_viewed') ?>
</div>.....
Here is my product_viewed.phtml (standard file from core)
<?php if ($_products = $this->getRecentlyViewedProducts()): ?>
<div class="block block-list block-viewed">
<div class="block-title">
<strong><span><?php echo $this->__('Recently Viewed Products') ?></span></strong>
</div>
<div class="block-content">
<ol id="recently-viewed-items">
<?php foreach ($_products as $_item): ?>
<li class="item">
<p class="product-name"><?php echo $this->helper('catalog/output')->productAttribute($_item, $_item->getName() , 'name') ?></p>
</li>
<?php endforeach; ?>
</ol>
<script type="text/javascript">decorateList('recently-viewed-items');</script>
</div>
</div>
<?php endif; ?>
When I inspect the elements, the from the footer is empty. All files posted are in my theme. I have my own css so may be it won't be shown as expected, but at least the div should have any data inside, right? Could you please help me with this one. Thank you in advance.
I am new to Yii, I have two tables. master_customer,master_client. In the client model, in the view I have a search box, If I enter a few letters in the search box, it must automatically get the data and give results from master_customers(like google suggestions). I have made relations in the client model with the master_customer.
please help me with the code. Thanks in advance
CONTROLLER action:
public function actionIndex()
{
$criteria = new CDbCriteria();
if(isset($_GET['q']))
{
$q = "%".$_GET['q']."%";
$criteria->condition = 'cust_name='.$q;
$arrTier3 = MasterCustomers::model()->findAll($criteria);
//$criteria->compare(MasterCustomers::model()->cust_name,$q, true);
//$criteria->compare('$data->customers->cust_name', $q, true, 'OR');
print_r($arrTier3);
die();
}
$dataProvider=new CActiveDataProvider('Host', array('criteria'=>$criteria));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
view :
<!--Content-->
<div id="content">
<div style="padding: 10px;">
<a href="<?php echo $this->createUrl('/Controller/create');?>" title="Create New Host" class="btn btn-primary circle_ok" style="text-decoration: none;" >Add New Host to Customer</a>
<div style="float:right">
<?php
echo CHtml::link('Upload Customer CSV', array('/Controller/uploadCustomers'), array(
'onclick'=>'return hs.htmlExpand(this, { objectType: "iframe", wrapperClassName: "full-size", align: "center" } )',
'class'=>'btn btn-primary',
'id'=>'upload_link',
));
?>
</div>
</div>
<h3><?php echo $title; ?></h3>
<div class="innerLR">
<div class="row-fluid">
<?php
$obj=$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
//'afterAjaxUpdate'=>'\'changeTRColor()\'',
//'itemView'=>'_view',
'columns'=>array(
array( // display 'create_time' using an expression
'name'=>'name',
'value'=>'$data->host_name',
),
array(
'name'=>'serviceId',
'value'=>'$data->host_serviceid',
),
array(
'name'=>'customer',
'value'=>'$data->customers->cust_name',
),
array(
'class'=>'CButtonColumn',
'template'=>'{delete}{update}',)
),
));
?>
<form method="get">
<input type="search" placeholder="search" name="q" value="<?=isset($_GET['q']) ? CHtml::encode($_GET['q']) : '' ; ?>" />
<input type="submit" value="search" />
</form>
</div>
<div class="separator bottom"></div>
</div>
</div>
<!-- // Content END -->
<div class="clearfix"></div>
<!-- // Sidebar menu & content wrapper END -->
<div id="footer" class="hidden-print">
<?php $this->renderPartial('application.views.layouts._footer_inc'); ?>
</div>
If you need a search like google that searches on each key press and update GridView then you can try like this. In your javascript write
<script type="text/javascript">
$(document).ready(function () {
$('#id of your search box').keyup(function () {
$.fn.yiiGridView.update('id of your grid to be updated', {
data: $(this).serialize()
});
});
});
</script>
In your controller check the $_POST variable that what value it has, so you can grab that value and search in master_customers for that specific value and render the view again.
I'm new to Yii framework. I'm using two radiobuttonlist in my advanced search form. I'm using the below lines to create radiobuttonlist.
<div class="row">
<?php #echo $form->label($model,'ReviewedDate'); ?>
<?php echo $form->radioButtonList($model, 'ReviewedDate',
array('1' => 'Reviewed', '' => 'Not Reviewed')
); ?>
</div>
<div class="row">
<?php echo $form->radioButtonList($model, 'Approved',
array('0' => 'Rejected', '1' => 'Approved')
); ?>
</div>
Now, I want to create a seperate radiobutton(4 buttons - Approved, Rejected, Reviewed, Not Reviewed) from the radiobuttonlist and Not reviewed has to be the selected by default when I go to that page.At a time only one button can be selected. How can I do this
Try:
<div class="row">
<?php #echo $form->label($model,'ReviewedDate'); ?>
<?php echo $form->radioButtonList($model, 'ReviewedDate',
array('1' => 'Reviewed', '' => 'Not Reviewed','2'=>'Approved','3'=>'Reviewed','4'=>'rejected'
); ?>
</div>
<script> $( document ).ready(function() {
$('your id /selector radio button').prop('checked',true);
}); </script>