I'm using Yii 1.1.15. I got to my CListView to populate the table correctly on page load. but when i try to sort the table by store name the ajax response is the html for the whole page. and the table is empty.
but when i refresh the page &sort=store or &sort=store.desc the page works fine and sorts proper too. Any ideas what i'm doing wrong?
In my Controller
$dataProvider=new CActiveDataProvider('Store',
array(
'criteria' => array(
'condition'=>$_search_conditions,
'params'=>$search_params,
),
'sort'=>array(
'defaultOrder'=>'store DESC',
'attributes'=>array(
'store'=>array(
'asc'=>'store',
'desc'=>'store DESC',
),
'*',
)
),
)
);
$model = new Store;
$model->unsetAttributes(); // clear any default values
//render page
$this->render('index',array(
'dataProvider'=>$dataProvider,
'model'=>$model
));
In my View
$this->widget('zii.widgets.CListView', array(
'id' => 'store-list',
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'enableHistory'=> true,
'pagerCssClass' => 'pagination',
'ajaxUpdate'=>'store-list',
'loadingCssClass' => '', //remove loading icon
'sortableAttributes'=>array(
'store',
//'state' => 'State',
//'distance' => 'Distance'
),
'emptyText' => '<div class="alert alert-info">No data found</div>',
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left visible-lg visible-md visible-sm">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>
<div class="row">
<div class="col-md-12">
{pager}
</div>
</div>',
'pager' => array('id'=>'_pagination',
'class' => 'LinkPager',
'header' => '', //remove pagination header
'htmlOptions'=>array('class'=>'pagination') //add bootstrap pagination class
),
));
also in my function parseUrl() i have this code which does echo the correct value for $_GET['Store_sort'] the code below is used in my custom url manager class
if (!empty($_GET['sort']))
{
echo $_GET['Store_sort'] = $_GET['sort'];
}
UPDATE: even with friendly url disabled it does not sort. here is the URL of the ajax post. The pagination doesnt work either
http://localhost/dev/frontend/www/store/store/index/?Store_sort=store.desc&ajax=store-list
Related
I need help here. I have a system developed with Yii framework. I used Yii Bootstrap and Yii Booster for the extensions. However, the booster widgets that I have implemented inside the system is not appearing when I uploaded the files into the LINUX server. It works fine in my laptop (development environment). The textarea, modal, tbselect2 all works well. However, it's not appear on the server side.
example:
//booster for tbckeditor
$this->widget('booster.widgets.TbCKEditor',array(
'model'=>$model, # Data-Model (form model)
'attribute'=>'content', # Attribute in the Data-Model
'editorOptions' => array(
'plugins' => 'basicstyles,toolbar,enterkey,entities,floatingspace,wysiwygarea,indentlist,list,dialog,dialogui,button,indent,fakeobjects',
)
) );
//booster for tbselect2
$this->widget('booster.widgets.TbSelect2',array(
'model' => $model,
'attribute' => 'job_cat_id',
'data' => CHtml::listData(AdmJobCat::model()->findAll(array('order'=>'jc_title ASC')), 'jc_id', 'jc_title'),
'options' => array('placeholder' => '--Please Select--','width' => '100%', 'allowClear'=>true,),
'htmlOptions' => array('multiple' => 'multiple'),
)
);
<?php $this->beginWidget('booster.widgets.TbModal', array('id' => 'withdrawModal')); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Withdraw Application(s)</h4>
</div>
<div class="container-modal">
<?php
$this->renderPartial('form/_withdraw_form'); //calling external form
?>
</div>
<?php
$this->endWidget(); //end modal widget
?>
I am new to drupal.
I need to customize a registration form by adding fields like id,mobile etc.
Can I accomplish this by creating a custom module?
If yes could anyone please help me with a brief idea on creating and overriding the default user registration submit function. I have to insert these details to another table and also have to pass the data as a service request.
Ive created a custom module with function
module_form_alter(&$form,&$form_state,$form_id){
$form['#submit'] = 'module_form_submit';
if($form_id == 'user_register_form'){
//print_r($form_id);
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('id'),
'#default_value' => '',
'#size' => 60,
'#maxlength' => 15,
'#required' => TRUE,
);
}
}
function module_form_submit($form, &$form_state){
echo "test";
exit();
}
module_form_alter is being called and I can see the new field on the registration screen but the submit function is still not called. I need to override the default drupal register submit.
I already have the following function in my theme template.php
function templatename_theme() {
$items = array();
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'portal_preprocess_user_login'
),
);
$items['user_register_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-register-form',
'preprocess functions' => array(
'portal_preprocess_user_register_form'
),
);
$items['user_pass'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'portal') . '/templates',
'template' => 'user-pass',
'preprocess functions' => array(
'portal_preprocess_user_pass'
),
);
return $items;
}
user-register-form.tpl.php
<div class="form-group">
<?php print drupal_render_children($form); ?>
</div>
And page--user--register.tpl.php with the html
<div id="login-page">
<div class="container">
<div class="form-login" >
<h2 class="form-login-heading"><img src="<?php echo drupal_get_path('theme', 'portal') . '/images/logo.png'; ?>" width="100"><?php echo $createaccount; ?></h2>
<div class="login-wrap">
<?php
$elements = drupal_get_form("user_register_form");
$form = drupal_render($elements);
echo $form ?>
<?php if ($messages):?>
<div id="messages-console" class="clearfix">
<div class="grid_12">
<div class="mt-grid-fix">
<?php print $messages; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
Is this approach fine or should I change this approach inorder to make my custom module functional?
You can go to:
admin/config/people/accounts/fields
and add the fields that you need.
In the fieldset "User settings" don't forget check "Display on user registration form."
How would i get the current pagesize in my View? I want to be able to add a banner when half the pagesize is reached.
If the page size is 10, insert a banner at position 5
i tried adding this in my view.php
if ($index == ($dataProvider->pagination->pageSize / 2)) { ... }
and this my index.php
$this->widget ( 'site.common.extensions.EListView.EListView', array (
'dataProvider' => $dataProvider,
'itemView' => '_view_gallery',
'pagerCssClass' => 'pagination',
'template' => '
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-12">
<div class="pull-right">{sorter}</div>
<div class="pull-left"></div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>
<div class="row padding-top-20px">
<div class="col-md-12">
{pager}
</div>
</div>
</div></div>',
'pager' => array (
'id' => '_pagination',
'class' => 'LinkPager',
'header' => '',
'htmlOptions' => array (
'class' => 'pagination'
)
),
'emptyText' => '<div class="alert alert-info">No result found.</div>'
)
);
but nothing happens.
I'm currently using this extension to create a perpage page size.
http://www.yiiframework.com/extension/elistview
also tried without using this extension, but still no luck. I'm using Yii 1.1.16.
any ideas?
In your _view_gallery.php you can use special variables available for CListView and CGridView (http://www.yiiframework.com/wiki/252/special-variables-in-cgridview-and-clistview/) in order to get the pageSize.
That could look like this:
if($widget->dataProvider->pagination->pageSize == 10){
//do something here
}
Accessing $dataProvider directly won't result in anything because that variable means nothing to the view.
I want to pass a php variable to modal window , what i am doing is opening a modal window using this link , but i want to pass a variable to this link and get same variable in modal window , i try to to do this to append a text in some div but it return html that i am unable to get in query
echo CHtml::link(
'Set Recipe', '', array(
'class' => 'testclass',
'id' => $finalDate,
'data-toggle' => 'modal',
'data-target' => '#myModal',
'fahadVar' => $finalDate
));
and when i click this button i got modal window how to get variable set in button
Here is simple modal code of yiibooster
<div class="modal-body">
<p>One fine body...</p>
</div>
<div class="modal-footer">
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'type' => 'primary',
'label' => 'Save changes',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
<?php $this->widget(
'bootstrap.widgets.TbButton',
array(
'label' => 'Close',
'url' => '#',
'htmlOptions' => array('data-dismiss' => 'modal'),
)
); ?>
</div>
<?php $this->endWidget(); ?>
thanks in advance
You should create a Widget.
Note: I copied below from another post. It works like charm.
First Create a new widget. Let say the name is CategoryWidget. Put this widget under components directory protected/components.
class CategoryWidget extends CWidget {
public function run() {
$models = Category::model()->findAll();
$this->render('category', array(
'models'=>$models
));
}
}
Then create a view for this widget. The file name is category.php. Put it under protected/components/views
category.php
<?php if($models != null): ?>
<ul>
<?php foreach($models as $model): ?>
<li><?php echo $model->name; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Then call this widget from your main layout.
main.php
// your code ...
<?php $this->widget('CategoryWidget') ?>
I am trying to include a Datepicker inside the CGridView as follows, the datepicker widget is used within the Grid View.
this->widget('zii.widgets.grid.CGridView', array(
'id'=>'order-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'order_id',
'customer.address.firstname',
'customer.address.lastname',
/*array('name' => 'ordering_date',
'value' => 'date("M j, Y", $data->ordering_date)'),
*/
array('name'=>'ordering_date',
'value'=>'$data->ordering_date',
'filter'=>$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'ordering_date',
'options'=>array(
'showButtonPanel'=>true,
'changeYear'=>true,
)
),
true),
'htmlOptions'=>array('width'=>'80','style'=>'text-align:center'),
),
array(
'class'=>'CButtonColumn',
'template' => '{view} {rollback} {receive}{pack} {dispatch}{delivered}',
'htmlOptions'=>array('width'=>'250px'),
'buttons'=>array(
'receive'=>array(
'id'=>'receive',
'name'=>'receive',
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&received=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'type'=>'submit',
'imageUrl'=>'/mdg/images/Receive1.png',
'visible'=>'($data->status=="pending")?true:false;'
),
'pack'=>array(
'id'=>'pack',
'name'=>'pack',
'type'=>'submit',
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&packed=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'click'=>'',
'imageUrl'=>'/mdg/images/pack1.png',
'visible'=>'($data->status=="received")?true:false;'
),
'dispatch'=>array(
'id'=>'dispatch',
'name'=>'dispatch',
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&dispatched=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'click'=>'',
'imageUrl'=>'/mdg/images/dispatch.png',
'visible'=>'($data->status=="packed")?true:false;'
),
'delivered'=>array(
'id'=>'delivered',
'name'=>'delivered',
'url'=>'',
'click'=>'',
'imageUrl'=>'/mdg/images/delivered1.png',
'visible'=>'($data->status=="dispatched")?true:false;'
),
'rollback'=>array(
'id'=>'rollback',
'name'=>'rollback',
'url'=>'$this->grid->controller->createUrl("/shop/order/admin&rollback=true", array("id"=>$data->order_id,"asDialog"=>1,"gridId"=>$this->grid->id))',
'click'=>'',
'imageUrl'=>'/mdg/images/rollback.jpg',
'visible'=>'($data->status=="pending")?false:true;'
),
),
),
'status',
),
'afterAjaxUpdate'=>'function(){
jQuery("#'.CHtml::activeId($model, 'ordering_date').'").datepicker({showButtonPanel:true, changeYear:true});
}',
)); ?>
This Code was taken from a suggestion given in the yiiframework forum. But it doesnt do anything.
Any idea why that is?
Thanks!
In this case I would put the date picker in the _search view. If you used Gii to generate your CRUD, it should already be there, available from the admin view:
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->