I've following custom template for pagination links
<li class="prev">prev</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>...</li>
<li>30</li>
<li class="next">next</li>
I've tried it by using following code(cakephp 2.3 version) but not getting the result as required.
<?php
echo $this->Paginator->prev('<', array( 'class' => '', 'tag' => 'li' ), null, array('class' => 'prev', 'tag' => 'li'));
echo $this->Paginator->numbers(array('tag' => 'li', 'separator' => '', 'currentClass' => 'active', 'currentTag' => 'a' ));
echo $this->Paginator->next('>', array('class' => 'next', 'tag' => 'li' ), null, array( 'class' => 'next', 'tag' => 'li'));
?>
Please help me out to get it done.. Thanks in advance.
This is just a sample of my custom template for pagination links, that I made for use with bootstrap. You can modify it accordingly to your needs
<ul>
<?php
echo $this->Paginator->first('‹', array('tag' => 'li', 'title' => __('First page'), 'escape' => false));
echo $this->Paginator->prev('«', array('tag' => 'li', 'title' => __('Previous page'), 'disabledTag' => 'span', 'escape' => false), null, array('tag' => 'li', 'disabledTag' => 'span', 'escape' => false, 'class' => 'disabled'));
echo $this->Paginator->numbers(array('separator' => false, 'tag' => 'li', 'currentTag' => 'span', 'currentClass' => 'active'));
echo $this->Paginator->next('»', array('tag' => 'li', 'disabledTag' => 'span', 'title' => __('Next page'), 'escape' => false), null, array('tag' => 'li', 'disabledTag' => 'span', 'escape' => false, 'class' => 'disabled'));
echo $this->Paginator->last('›', array('tag' => 'li', 'title' => __('First page'), 'escape' => false));
?>
</ul>
The ellipsis ... is created automatically by Paginator::numbers() according to the CakeBook, but you can change it to whatever you want.
I hope it works out for you
Related
Im new to omines/datatables-bundle and I have problem displaying search.
I was studying documentation and was not able to get it working.
Ive created a table like this
$table = $dataTable->create()
->add('street', TextColumn::class, ["label" => "Street", "searchable" => true, "globalSearchable" => true])
->add('houseNumber', TextColumn::class, ["label" => "House number", "searchable" => true])
->add('postal', TextColumn::class, ["label" => "Postal Code", "searchable" => true])
->add('city', TextColumn::class, ["label" => "City", "searchable" => true])
->add('country', TextColumn::class, ["label" => "Country", "searchable" => true])
->createAdapter(ORMAdapter::class, [
'entity' => CustomAddress::class,
])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('sales_request/add_custom_address.html.twig', ['datatable' => $table]);
Also, in my twig template
<div id="addresses">Loading...</div>
<script src="{{ asset('bundles/datatables/js/datatables.js') }}"></script>
<script>
$(function() {
$('#addresses').initDataTables({{ datatable_settings(datatable) }}, { searching: true });
});
</script>
The datatable works fine, sorting is working etc, but I dont see the search input field.How should I configure it to display it?
For anyone finding this issue by searching - it's actually a configuration issue we didn't document well enough.
The default Symfony recipe sets the DataTables native dom option to a sane default, but it omits the search field as it's not universally required. In general one should configure the dom value correctly for the intended result.
For more information see https://github.com/omines/datatables-bundle/issues/57#issuecomment-453529328
You can just add option dom : 'Bfrtip'
<div id="addresses">Loading...</div>
<script src="{{ asset('bundles/datatables/js/datatables.js') }}"></script>
<script>
$(function() {
$('#addresses').initDataTables({{ datatable_settings(datatable) }}, { searching: true, dom: 'Bfrtip' });
});
</script>
I'm looking to use a template for my checkboxList.
That's the properties i want to apply
class="switch" checked data-on-text="ON" data-off-text="OFF" data-on-color="teal"
<?php $form = ActiveForm::begin(); ?>
<ul class="list-unstyled">
<li>
<?= $form->field($modelUserPermission, 'id_permission')->checkboxList(ArrayHelper::map(Permission::find()->all(),'id', 'code')) ?>
</li><br>
</ul>
<div class="form-group">
<?= Html::submitButton($modelUserPermission->isNewRecord ? 'Create' : 'Update', ['class' => $modelUserPermission->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'value'=>'Create', 'name'=>'submit']) ?>
</div>
<?php ActiveForm::end(); ?>
<?= $form->field($model, 'recomended_by_user', ['template'=>'<div class="control-group">
<label class="control control--checkbox checkbox-small-text">Recomended by user
{input}
<div class="control__indicator"></div>
</label>
</div>'])->textInput(['class'=>"",'type'=>'checkbox'])?>
Use like this for custom Checkbox template
Answer provided by Bizley is correct, but here is one more alternate way you can try if you want.
<?php
$items_array = ArrayHelper::map(Permission::find()->all(),'id', 'code');
echo $form->field($model, 'id_permission')->checkboxList($items_array, [
'items' =>
function ($index, $label, $name, $checked, $value) {
return Html::checkbox($name, $checked, [
'value' => $value,
'label' => '<label for="' . $label . '">' . $label . '</label>',
'labelOptions' => [
// you can set label options here ],
],
]);
}, 'itemOptions' => ['class' => 'switch',
'data-on-text' => 'ON', 'data-off-text' => 'OFF', 'data-on-color' => 'teal'],
'separator' => false,]);
?>
If you want these properties in every checkbox (like Insane Skull asked) use itemOptions option.
<?= $form->field($modelUserPermission, 'id_permission')->checkboxList(
ArrayHelper::map(Permission::find()->all(),'id', 'code'),
[
'itemOptions' => [
'class' => 'switch',
'data' => [
'on-text' => 'ON',
'off-text' => 'OFF',
'on-color' => 'teal'
],
],
]
) ?>
Since it's ActiveField widget in order to get all checkboxes checked you have to pass array to $modelUserPermission->id_permission with all the IDs.
I'm Working on a project in which i have implemented Kendo Grid and when i click the edit button a popup for editing is displayed. But what i want is a separate panel alongside of kendo grid which i have made using [bootstrap][1] and i want to populate it with the editing detail of particular row clicked in the Kendo grid. I have attached the image below to give you an idea what i want. the help bordered area is where i want to populate it showing editable detail of selected row. Any Help??
#(Html.Kendo().Grid<UserItem>()
.Name("usergrid")
.HtmlAttributes(new { style = "width:100%" })
.Columns(columns =>
{
columns.Bound(o => o.FirstName);
columns.Bound(o => o.LastName);
columns.Bound(o => o.EmailAddress);
columns.ForeignKey(o => o.RoleId, (System.Collections.IEnumerable)ViewData["Roles"], "Id", "Description")
.Title("Role");
columns.ForeignKey(o => o.SystemRoleId, (System.Collections.IEnumerable)ViewData["SystemRoles"], "Id", "Description")
.Title("Sys Role");
columns.ForeignKey(o => o.TimeZoneId, (System.Collections.IEnumerable)ViewData["TimeZones"], "Id", "Description")
.Title("Time Zone");
columns.Bound(e => e.DefaultPageSize).Title("Default Page Size");
columns.Bound(o => o.IsActive).Title("Is Active");
columns.Bound(o => o.LastLoginDate).Format("{0:d}").Title("Last Login");
columns.Command(command => { command.Edit().Text("Edit"); });
})
.ToolBar(toolbar =>
{
toolbar.Template(#<text>
<div class="toolbar">
<span id="divCompany" style='#(roleName == Constants.SystemRoles.FifthMethod?"":"display:none;")'>
<label class="category-label" for="ddlCompany">Companies :</label>
#(Html.Kendo().DropDownList()
.Name("ddlCompany")
.DataTextField("Name")
.DataValueField("Id")
.AutoBind(true)
.Events(e => e.Change("CompanyChange"))
.HtmlAttributes(new { style = "width: 150px;" })
.BindTo(ViewBag.Companies)
.Value(Convert.ToString(ViewBag.CurrentCompanyID))
)
</span>
#Html.Kendo().Button().Name("btnNewUser").Content("New User").HtmlAttributes(new { #class = "k-button k-button-icontext k-grid-add pull-right" })
<button type="button" data-toggle="modal" data-target="#importUser-pop" class="k-button k-button-icontext pull-right">Import Users</button>
</div>
</text>);
})
.Editable(editable =>
{
editable.Mode(GridEditMode.PopUp);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model =>
{
model.Id(c => c.UserId);
model.Field(c => c.LastLoginDate).Editable(false);
})
.Create(create => create.Action("User_Create", "User").Data("GetCompanyId"))
.Read(read => read.Action("User_Read", "User").Data("GetCompanyId"))
.Update(update => update.Action("User_Update", "User"))
)
.Pageable()
.Sortable()
.Filterable()
.Events(e => e.Edit("grid_Edit"))
)
A complete example already exists in Kendo Docs how to edit records using external forms
A mvvm bounded section <div id="editForm"> to grid row using kendo.bind($("#editForm"), viewModel)
So I'm at work (working with sensitive data might I add for posterity's sake), and the powers that be decide we need to use the all powerful and least documented new tool by Cakephp 3.0 (beta at this time).
Edit: My goal is to create several different templates for forms to call through the formhelper template or input methods. There really isn't much of an a good example for this.
Customizing the Templates FormHelper Uses:
As seen in the book(and nowhere else on the internet anywhere) the very short documentation is thus:
http://book.cakephp.org/3.0/en/core-libraries/helpers/form.html#customizing-the-templates-formhelper-uses
The site says you can use the template method and then give a vague "use":
$myTemplates = [
'inputContainer' => '<div class="form-control">{{content}}</div>',
];
$this->Form->templates($myTemplates);
Then it says you can use the input() method for which it gives no example.
And last but not least the custom template FormHelper should allow you to "make" or "create" as many of these custom formhelpers as you wish, but they give no example use of how to do that!? lulwut?
I can easily use it once like their example, but where's the power in a single custom template? That doesn't do me anygood.
So by a new possible solution I try and get a new error.
I get this error(within my view)(from the following code):
Fatal Error
Error: Class 'Configure' not found
//within bootstrap.php
Configure::write('templates', [
'shortForm' => [
'formstart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-4"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-4"><select name="{{name}}"{{attrs}}>{{content}}</select> </div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}} </div>',
'checkContainer' => '',],
'longForm' => [
'formstart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-6"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-6"><select name="{{name}}"{{attrs}}>{{content}}</select> </div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}} </div>',
'checkContainer' => '',],
'fullForm' => [
'formstart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-10"><input type="{{type}}" name="{{name}}" {{attrs}} /> </div>',
'select' => '<div class="col-md-10"><select name="{{name}}"{{attrs}}>{{content}}</select> </div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}} </div>',
'checkContainer' => '',]
]);
//within my view
<?php
$this->Form->templates(Configure::read('templates.shortForm'));
?>
Old Update: I added
use "Cake\Core\Configure;"
in my view and everything works great, but I would like to add this to the appropriate file in the hierarchy so that I don't have to add that to every view,
that is unless of course it causes efficacy issues for the entire app as a whole. Does anyone know which file it should go in? Regards and TIA!
Newest Update: I just figured it out. So simple! check my answer below! Hope this helped someone
What this fix does is allow you to have custom template forms (from cakephp 3!!!!) using bootstrap. If you want to set sizes using the form helper and all of it's goodness (security and what not).
Jose Zap of Cakephp told me to try bootstrap plugins and widgets and what not, but the real way to do this should have been this:
Step 1: Create config/templatesConfig.php and add your custom form stuff.
<?php
$config = [
'Templates'=>[
'shortForm' => [
'formStart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-4"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-4"><select name="{{name}}"{{attrs}}>{{content}}</select></div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}}</div>',
'checkContainer' => '',],
'longForm' => [
'formStart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-6"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-6"><select name="{{name}}"{{attrs}}>{{content}}</select></div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}}</div>',
'checkContainer' => '',],
'fullForm' => [
'formStart' => '<form class="" {{attrs}}>',
'label' => '<label class="col-md-2 control-label" {{attrs}}>{{text}}</label>',
'input' => '<div class="col-md-10"><input type="{{type}}" name="{{name}}" {{attrs}} /></div>',
'select' => '<div class="col-md-10"><select name="{{name}}"{{attrs}}>{{content}}</select></div>',
'inputContainer' => '<div class="form-group {{required}}" form-type="{{type}}">{{content}}</div>',
'checkContainer' => '',]
]
];
Step 2: From your controller inside the method for the correct view call this line.
Don't forget add this on the top of your controller
use Cake\Core\Configure;
$this->set('form_templates', Configure::read('Templates'));
Step 3: Add this within the bootstrap.php file
// Load an environment local configuration file.
// You can use this file to provide local overrides to your
// shared configuration.
Configure::load('templatesConfig','default'); //fixed
Step 4(finally): Add this line with the template name you want Bam!.
<?php $this->Form->templates($form_templates['shortForm']); ?>
Let's say you need all inputs to use a custom markup in a form to show the label after the input (default is before) and a different class for the hardcoded error-message for errors:
$this->Form->create($entity, ['templates' => [
'formGroup' => '{{input}}{{label}}',
'error' => '<div class="error">{{content}}</div>'
]]);
If you want to only customize a single input, pass the same 'templates' key to the FormHelper::input() options like so:
$this->Form->input('fieldname', ['templates' => [
'formGroup' => '{{input}}{{label}}',
'error' => '<div class="error">{{content}}</div>'
]]);
If you need to define multiple templates and re-use them whenever you want, here's something you can try (mind I am writing it here, never used it before):
// in bootstrap (as this is a config i believe
Configure::write('templates', [
'foo' => [....],
'bar' => [....]
]);
// in any view
$this->Form->templates(Configure::read('templates.foo'));
$this->Form->create(...);
....
You could also create your own helper and define the templates there, etc.
It really all depends on what you want to achieve but that should give you a good understanding of how templates work (not just in forms by the way).
How to print ex-tax amount on featured, bestseller and related module? I tried with $product array but there is no key for ex-tax amount.
Open your bestseller controller file (catalog/controller/module/bestseller.php), and modify this part:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'special' => $special,
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
... by declaring 2 new variables, called price_ex_tax and special_ex_tax in the products array:
$this->data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'price' => $price,
'price_ex_tax' => $this->currency->format($result['price']),
'special' => $special,
'special_ex_tax' => $this->currency->format($result['special'],
'rating' => $rating,
'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
);
Then you could access the new variables in the bestseller view file (catalog/view/theme/your_theme_name/template/module/bestseller.tpl). Look for this part:
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
</div>
<?php } ?>
... and replace with:
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price'] . "(" . $product['price_ex_tax'] . ")"; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price'] . "(" . $product['price_ex_tax'] . ")"; ?></span> <span class="price-new"><?php echo $product['special'] . "(" . $product['special_ex_tax'] . ")"; ?></span>
<?php } ?>
</div>
<?php } ?>
You could repeat the same steps for the featured module as well (controller file: catalog/controller/module/featured.php - view file: catalog/view/theme/your_theme_name/template/module/featured.tpl). You can find the related products in the product controller file (catalog/controller/product/product.php), and you can display it in the product view file (catalog/view/theme/your_theme_name/product/product.tpl). I hope this helped.
For me it worked when I added this to the controller file: catalog/controller/module/featured.php
Just above the $this->data['products'][] = array( add the following line:
$extax = $this->currency->format($product_info['price']);
Then within the array( add:
'extax' => $extax,
Finally go to catalog/view/theme/your_theme_name/template/module/featured.tpl and add:
<?php echo $product['extax']; ?> where you wish to display the price without tax or
<?php echo $product['price'] . "(" . $product['extax'] . ")"; ?> to show both inc and exc, hope that helps.