Currently when i click on sort by in CListView generated table, it adds MODEL_NAME_2 to the url
?page=1&sort=MODEL_NAME_2.cat.desc
is there a way to remove it? or maybe rename it to something else? Or is this just how Yii works?
here is my actionIndex() in my controller
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('MODEL_NAME_1', array(
'id'=> '',
'criteria' => array(
'with' => 'MODEL_NAME_2',
'together'=>true, //specifies whether the query should be run using a join
),
'sort'=>array(
'defaultOrder'=>'MODEL_NAME_2.cat ASC',
'attributes'=>array(
'MODEL_NAME_2.cat'=>array(
'asc'=>'MODEL_NAME_2.cat',
'desc'=>'MODEL_NAME_2.cat DESC',
),
'*',
)
),
'pagination'=>array(
'pageVar'=>'page'
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
in my view
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view', // refers to the partial view named '_view'
'enableHistory'=> true,
'sortableAttributes' => array('MODEL_NAME_2.cat'=>'Make'),
'pagerCssClass' => 'pagination',
'loadingCssClass' => '', //remove loading icon
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>',
));
ideally i would like my url to look like this
mysite.com/bla/page/2/sort/cat/desc
basically using alot of / and no ? or &
In ListView definition change:
'sortableAttributes' => array('make'=>'Make'),
In your dataProvider
'sort'=>array(
'defaultOrder'=>'MODEL_NAME_2.cat ASC',
'attributes'=>array(
'make'=>array(
'asc'=>'MODEL_NAME_2.cat',
'desc'=>'MODEL_NAME_2.cat DESC',
),
'*',
)
),
Related
I use like this..
<div class="row">
<?php echo $form->textFieldGroup(
$User,'email_address',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
)
);
?>
</div>
But there is default placeholder 'Email Address'. How I want to set there my own placeholder ?
you can add html options as below:
<?php echo $form->textFieldGroup(
$User,'email_address',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
'widgetOptions' => array(
'htmlOptions' => array(
'placeholder' => 'my placeholder'
)
)
)
);
?>
for more detail have a look at Booster active form
I'm using Zend Framework 2 Form to render my forms, and Bootstrap 3 to style them.
I want to use the Horizontal Form Layout as explained here:
Bootstrap 3 Forms tutorial
To do so, I need to add a div with appropriate classes around the input element; is there any easy way to add such div while adding the new element to the Form class? My element so far:
$this->add(array(
'name' => 'name',
'attributes' => array(
'type' => 'text',
'id' => 'contactName',
'maxlength' => '70',
'placeholder' => 'Your full name.',
'class' => 'form-control'
),
'options' => array(
'label' => 'Name: ',
'label_attributes' => array(
'class' => 'control-label col-xs-12 col-sm-2'
)
),
));
Can I add anything here to easily add <div class="col-xs-12 col-sm-10"></div> around the input element when I render it with <?php echo $this->formRow($this->form->get('name')); ?>?
I finally managed to solve the problem by creating a custom View Helper:
public function __invoke($element) {
echo '<div class="form-group">';
echo $this->view->formLabel($element);
echo '<div class="col-xs-12 col-sm-10">' . $this->view->formElement($element) . '</div>';
echo $this->view->formElementErrors($element);
echo '</div>';
}
Though I still wonder if there was another easier way to do that!
I am trying to load the index view from another model view in a modal window using yiibooster but the dataprovider of this model looks like it is undefined:
<?php $this->beginWidget(
'bootstrap.widgets.TbModal',
array('id' => 'documentacion')
); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Documentación</h4>
</div>
<?php
$doc = new ZfDocumentacionInmueble;
$this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc));
?>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Cerrar',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
ERROR: Undefined variable: dataProvider
thanks!
ERROR:
C:\APP\htdocs\yii\yiitest\protected\views\zfDocumentacionInmueble\index.php(6)
1 <?php
2 /* #var $this ZfDocumentacionInmuebleController */
3 /* #var $dataProvider CActiveDataProvider */
4
5 $this->widget('zii.widgets.CListView', array(
6 'dataProvider'=>$dataProvider,
7 'itemView'=>'_view',
8 )); ?>
CONTROLLER CODE:
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('ZfDocumentacionInmueble');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
If the "real url" works, then the ZfDocumentacionInmueble::actionIndex()-function is creating a $dataProvider and passing it to the view.
In your renderPartial call, you do not pass on a $dataProvider. If you have created it in your controller action, be sure to pass it along (or otherwise you might have to copy the code from the other controller):
$this->renderPartial('//ZfDocumentacionInmueble/index', array('model'=>$doc, 'dataProvider' => $dataProvider));
How to show timepicker based yiibooster, with Jqrelcopy.
I've code like this :
<div class="control-group "><label class="control-label required">Jam Kerja</label>
<div class="controls">
<a id="copylink" href="#" rel=".copy">Tambah Jam Kerja / Shift</a>
<div class="row copy">
<?php echo CHtml::label('',''); ?>
<?php $this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'htmlOptions'=>array('width'=>'50px'),
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
),
)
);
?>
<?php
$this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
)
)
);
?>
</div>
</div>
</div>
When I add new, Timepicker always on field 1. Can't on field changed.
Im trying to close CJuiDialog in Ajax success but its not closing, only iframe contents gets cleared popup not closing,
CJuiDialog Coding:
<?php
$this->beginWidget('zii.Widgets.jui.CJuiDialog',array(
'id'=>'Document-Edit',
'options'=>array(
'title'=>'Manage Documents',
'autoOpen'=>false,
'modal'=>true,
'width'=>800,
'height'=>600,
// 'close'=>'js:function(e,o){location.reload();}' ,
),
));
?>
<iframe id="cru-frame-doc" width="100%" height="100%" frameBorder="0" scrolling="no" >
<?php $this->renderPartial('ManageDocuments_Update', array('model'=>$model)); ?>
</iframe>
<?php $this->endWidget();?>
CGridView Code:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'document-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'class' => 'CButtonColumn',
'template' => '{DocumentEdit}',
'buttons' => array(
'DocumentEdit' => array(
'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png',
'url'=>'$this->grid->controller->createUrl("DocumentEdit", array("id"=>$data->crm_document_id,"asDialog"=>1))',
'click'=>'function(){
$("#cru-frame-doc").attr("src",$(this).attr("href")); $("#Document-Edit").dialog("open"); return false;}',
),
),),
'crm_document_id',
'name',
'doc_type',
'delivery_method',
'content_subject',
'content_body',
'is_active',
),
)); ?>
Ajax Submit Button Code:
<?php
echo CHtml::ajaxSubmitButton( 'Save',
'js:document.location.href='.'"'.Yii::app()->createUrl("baseContact/SaveManageDocuments_Update",array("id" => $model->crm_document_id)).'"',
array(
'type'=>'POST',
"dataType" => "json",
'success' => 'function(data){
if(data.result=="success"){
window.parent.$("#Document-Edit").dialog("close");
window.parent.$("#cru-frame-doc").attr("src","");
}
}',
));
?>
Can anyone point out where im making error...
Use the below code in SaveManageDocuments_Update Controller action to close the dialog,
echo CHtml::script("window.parent.$('#Document-Edit').dialog('close');window.parent.$('#cru-frame-doc').attr('src',''); window.parent.$.fn.yiiGridView.update('document-grid');");
Yii::app()->end();