I've configure blackboot (i.e. bootstrap) on yii and I've been using it for the past couple of weeks to develop my website. However, at this point I'm running into a slight problem. Generally, the pages that are generated have a top menu, a side menu (on the left side that says something like "Create XXXX" "Manage XXXXX"_ and the content displayed in the center. I'd like to be able to delete the current menu and instead use that space to display my own form/field. The current code in the index view is
<?php
/* #var $this RecipientController */
/* #var $dataProvider CActiveDataProvider */
$this->breadcrumbs=array(
'Recipients',
);
$this->menu=array(
array('label'=>'List Recipient', 'url'=>array('index')),
array('label'=>'Create Recipient', 'url'=>Yii::app()->createUrl('recipient/create', array('id'=>$id))),
);
?>
<h1> Recipients </h1>
<div class="row">
<div class="span8 offset6">
<a class="btn btn-primary" href=
"<?php echo Yii::app()->createUrl('recipient/processpayment', array('id'=>$id)); ?>"> Pay All </a>
<a class="btn btn-inverse" href="<?php echo Yii::app()->createUrl('recipient/create', array('id'=>$id)); ?>" >Add User</a>
<div class ="span4">
</div>
</div>
</div>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'recipient-grid',
'dataProvider'=>$dataProvider,
'filter'=>$model,
'columns'=>array(
'name',
'position',
'msisdn',
'balance',
/*
* this is to implement the checklist
array(
'id'=>'autoId',
'class'=>'CCheckBoxColumn',
'selectableRows' => '50',
),
*/
),
)); ?>
<?
/*
php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
));
*/
?>
In which $this->menu() defines the area that I would like to be using. In its place I would like to put this html.
<div class="row">
<div class="span3">
<table class="table table-bordered">
<form action="<?php echo Yii::app()->createUrl('recipient/processpayment', array('id'=>$id)) ?>" method="post" >
<tr class="primary"><td> List Summary</td></tr>
<tr ><td>
<?php echo $numpeople; ?> Recipients
</td></tr>
<tr ><td>
Total Due: <?php echo $totaldue ?> rwf
</td></tr>
<tr> <td>
<?php
$accounts= CHtml::listData(Account::model()->findAll(array("condition"=>"user_id = $user_id")),'id', 'name');
echo CHtml::dropDownList("listF",'id', $accounts);
?>
</td> </tr>
<tr> <td>
<button class="btn btn-block btn-primary " type="submit">Pay Now</button> </td> </tr>
</td></tr>
</form>
</table>
</div>
<div class="span9"></div>
</div>
But, whenever I try to place this small box inside of my web page - I am forced to place it inside of the main blank page in the center. How can I override this menu/html so that I can place my own form on the left side of the page?
Related
I am looking to make a simple Pop-Up window using TbModal (as requested by my superiors). However, I have no clue how to do this. I have never written a modal before and I am not certain if I am doing it completely wrong.
All I need to do, is to create a Pop-up window once a button is clicked. In this window I need to simply add a name, a description and something that is called carousel. However, whenever I try to make it work I get the following error:
Alias "bootstrap.widgets.TbModal" is invalid. Make sure it points to an existing directory or file.
Below is what the button in my view looks like (using a TbButtonColumn):
'buttons'=>array(
'update'=>array(
),
'delete'=>array(
),
'clone'=>array(
'id'=>'clone-dashboard-button',
'label'=>'Clone',
'title'=>'Clone',
'url'=>'Yii::app()->createUrl("path/to/actionClone", array("id"=>$data->id))',
'option'=>array(
'rel'=>'tooltip',
'data-toggle'=>'tooltip',
'title'=>'Clone'
),
),
),
As well as the modal:
<?php $this->beginWidget('bootstrap.widgets.TbModal', array(
'id'=>'clone-form',
// 'focus'=>'#Dashboard_clone_title',
'htmlOptions'=>array(
'tabindex'=>'-1',
))); ?>
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h4>Test</h4>
</div>
<div class="model-body">
<div class="row">
<div class ="col-md-2">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textArea($model,'title', array('rows'=>1, 'cols'=>20,'class'=>'resize-non form-control')); // Title input?>
</div>
<div class ="col-md-2">
<?php echo $form->labelEx($model,'description'); ?>
<?php echo $form->textArea($model,'description', array('rows'=>1, 'cols'=>30,'class'=>'resize-non form-control')); //Description ?>
</div>
<div class ="col-md-2">
<?php echo $form->labelEx($model,'carousel'); ?>
<?php echo $form->checkbox($model,'carousel'); ?>
</div>
</div>
</div>
<div class="modal-footer">
<!--Buttons-->
<div class="pull-right">
<?php $this->widget('booster.widgets.TbButton', array(
'buttonType'=>'Clone',
'url'=>'Yii::app()->createUrl("path/to/actionClone", array("id"=>$data->id))',
'htmlOptions'=>array(
'onClick'=>"
$(this).attr(\"disabled\", \"disabled\");"
),
)); ?>
<?php $this->widget('booster.widgets.TbButton', array(
'buttonType'=>'button',
'label'=>'Cancel',
'htmlOptions'=>array(
'data-dismiss'=>'modal',
),
)); ?>
</div>
</div>
<?php $this->endWidget(); ?>
Friends, I am trying to update my shopping cart based on this article.
However, I cannot update the "quantity" value separately in the session. The article works with the products registered in the database. I use session. I believe that there is some detail in cart.ctp that is not correct in this transition! I appreciate if anyone can see what's going on!
cart.ctp
The code for my cart.ctp is as follows:
<html>
<body>
<main class="mt-1 pt-1">
<div class="container wow fadeIn">
<div class="row">
<div class="col-md-8 mb-4">
<div class="card">
<?php foreach($this->Session->read('carrinho') as $index=>$carrinho): ?>
<div class="container">
<div class="row">
<div class="col-md-10">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">product</th>
<th scope="col">price</th>
<th scope="col">Qte</th>
<th scope="col">subtotal</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
<?= $carrinho->has('produto') ? $this->Html->link($carrinho->produto->nome_produto, ['controller' => 'Produtos', 'action' => '/', $carrinho->produto->id]) : '' ?>
</th>
<td>
<strong>R$ <?php echo number_format($carrinho->produto->preco, 2, ',', '') ?></strong>
</td>
<td>
<?php echo $this->Form->create('Pedidos',array('id'=>'add-form',
'url'=>array('controller'=>'pedidos','action'=>'update',$carrinho->produto->id)));?>
<?php
echo $this->Form->control('quantidade',
array('type'=>'number', 'label'=>false,'min'=> 1,'size' => 2,
'maxlenght' => 2, 'class'=>'form-control','required' => 'true', 'value'=>$carrinho->quantidade));?> un.
<?php echo $this->Form->submit('update',array('class'=>'btn-md text-white waves-effect m-1', 'style' => 'background-color:#1ab394'));?>
<?php echo $this->Form->end();?>
</td>
<td>
<strong>
R$ <?php
$sub = ($carrinho->produto->preco * $carrinho->quantidade);
echo number_format($sub, 2, ',', '');
?>
</strong>
<?php $total = array(number_format($sub, 2, ',', ''));?>
</td>
</tr>
</tbody>
</table>
<hr width="40%">
</div>
</div>
</div>
<div class="row">
<div class="col-md-8">
</div>
<div class="col-md-2 mt-3">
<?= $this->Html->link(__('Update'), ['action' => 'update']); ?>
</div>
<div class="col-md-2 mt-3">
<?= $this->Html->link(__('Delete'), ['action' => 'delete', $index]); ?>
</div>
</div>
<?php endforeach; ?>
<br>
</div>
</div>
<div class="col-md-4 mb-4">
<form class="card p-2">
<div class="input-group">
<?= $this->Html->link(__('Checkout'), ['action' => 'checkout']); ?>
</div>
<?php echo $this->Form->end(); ?>
</div>
</div>
</div>
</main>
</body>
</html>
cart.php
public function update($productId = null) {
$session = $this->request->session();
$carrinho = $session->read('carrinho');
$quantidade = $this->request->data('quantidade');
if ($quantidade > 0) {
$carrinho[$productId] = $quantidade;
$session->write('carrinho', $carrinho);
return $this->redirect(['action' => 'index']);
}
}
Your edit resolves one major issue, which is that you were starting multiple forms inside td elements, but not ending them until much later. That would produce invalid HTML. Note that you still have your original $this->Form->end() call after the end of the table, that should be removed.
The main problem that you've got here is that your forms have zero information about what row they are supposed to be updating. You need to include some reference to which cart item, presumably either including $cart->product->id in the URL, like you have included $index in your delete function, or else as a hidden input in the form.
The second problem here is that you seem to think that the posted data is going to have some structure that it's not. You've named your control simply "quantity". That's all that's going to be in the data. You will have $this->request->data['quantity'], and it's just a single integer value, not an array you can foreach over. Hence that particular error.
And third, you are then trying to access $this->request->data['Carrinho']['produto_id'], which very much doesn't exist. Seems like you're trying to get the product ID from here, but (per the first issue above) you've never added that into the form.
So, something like this should resolve it all:
<?php echo $this->Form->create('Requests',array('id'=>'add-form',
'url'=>array('controller'=>'requests','action'=>'update',$cart->product->id)));?>
And then later:
public function update($productId) {
// ...
$carrinho = $session->read('carrinho');
$quantidade = $this->request->data('quantity');
if ($quantidade > 0) {
$carrinho[$productId] = $quantidade;
}
// ...
I'm writing a plugin for WordPress and I need to emulate the functionality (and style) of a WP table for the admin area. I mean those basic tables that appear on any menu page, like the ones that list the Pages or the Comments.
I've made some progress on that: I've managed to replicate the WP style by simply using the same CSS classes and HTML that they use in their own tables, but I'm not sure this is the right way to approach this.
I actually only need the pagination and filter functionalities, nothing else. I guess I can put my own logic here and get it done, but I was wondering if there was a simpler, more appropriate way to do this.
So, any thoughts on how should I build a table in the admin area of WordPress so that it matches the style/functionality of the default ones?
(BTW, I'm not using a Custom Post Type, just a custom top-level admin menu. Hence the need for a table made from scratch.)
Here's the code I'm using to display my custom admin page (there are some literal values for simplicity):
HTML:
<div class="wrap">
<h1><?= $helper->esc_html__(get_admin_page_title()) ?></h1>
<hr class="wp-header-end">
<br>
<form>
<div class="tablenav top">
<div class="alignleft actions">
<label for="filter-by-date" class="screen-reader-text">Filter by date</label>
<select name="filter-by-date">
<option value="all" selected>All dates</option>
<option value="last-month">Last month</option>
<option value="last-week">Last week</option>
<option value="today">Today</option>
</select>
<input type="submit" name="filter-action" class="button" value="Filter">
</div>
<div class="tablenav-pages">
<?php
// translators: %d: Total number of elements
$elements_count = sprintf($helper->esc_html__('%d elements'), $requests_count);
?>
<span class='displaying-num'><?= $elements_count ?></span>
<span class="pagination-links">
<span class="tablenav-pages-navspan" aria-hidden="true">«</span>
<a class="prev-page" href="#">
<span class="screen-reader-text">Previous page</span>
<span aria-hidden="true">‹</span>
</a>
<span class="paging-input">
<label for="current-page-selector" class="screen-reader-text">Current page</label>
<input type="text" name="paged" id="current-page-selector" class="current-page" value="2" size="1" aria-describedby="table-paging">
<span class="tablenav-paging-text"> of <span class="total-pages">3</span></span>
</span>
<a class="next-page" href="#">
<span class="screen-reader-text">Next page</span>
<span aria-hidden="true">›</span>
</a>
<span class="tablenav-pages-navspan" aria-hidden="true">»</span>
</span>
</div>
</div>
</form>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th class="manage-column column-primary"><?= $helper->esc_html__('Movie Title') ?></th>
<th class="manage-column"><?= $helper->esc_html__('Release') ?></th>
<th class="manage-column"><?= $helper->esc_html__('Language') ?></th>
<th class="manage-column"><?= $helper->esc_html__('User') ?></th>
<th class="manage-column"><?= $helper->esc_html__('Date') ?></th>
<th class="manage-column"><?= $helper->esc_html__('Actions') ?></th>
</tr>
</thead>
<tbody id="the-list">
<!-- If there are any requests, display each record, otherwise, inform the user -->
<?php if ($requests_count): ?>
<?php foreach ($requests as $request): ?>
<tr class="is-expanded">
<td class="column-primary" data-colname="Movie Title">
<strong><?= $helper->esc_html__($request->title) ?></strong>
</td>
<td data-colname="Release">
<?php if ($request->release === null): ?>
<span class="sr-text-info"><?= $helper->esc_html__('Not Specified') ?></span>
<?php else: ?>
<?= esc_html($request->release); ?>
<?php endif; ?>
</td>
<td data-colname="Language"><?= $helper->esc_html__($request->language) ?></td>
<td data-colname="User">
<?php if ($request->user === null): ?>
<span class="sr-text-info"><?= $helper->esc_html__('Anonimous') ?></span>
<?php else: ?>
<?= esc_html($request->user); ?>
<?php endif; ?>
</td>
<td data-colname="Date">
<?php
$date = new DateTime($request->date);
// translators: draft request date format, see http://php.net/date
$request_date_fmt = $helper->__('m/d/Y, g:i a');
echo esc_html($date->format($request_date_fmt));
?>
</td>
<td data-colname="Actions">
<a class="button" href="#">Delete</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr class="is-expanded">
<td class="sr-text-center" colspan="6">
<span class="sr-text-info"><?= $helper->esc_html__('There are no requests to show.') ?></span>
</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
Thanks in advance!
The best option is to extend the native WP_List_Table class which is already available in WordPress Core. While this is a private class in core, it probably won't change drastically in the future and I would personally consider it safe to extend.
When you define your own class and extend WP_List_Table, all you'll need to do is create your own methods with the logic for the data. The best part is that the parent WP_List_Table class will handle everything else for you (markup, styles, pagination, etc).
WP Engineer has a good beginner's guide to get you started. You can also search the web for "WP_List_Table guide", "WP_List_Table tutorial", (etc) and you'll find plenty of examples online.
I have this form (I used crud generator and model generator):
Create Pig
[Name]
[Breed]
[Sickness] [Add sickness]
How do I make add sickness create a new textfield everytime I click it? I already have a table for the multivalued sicknessid, I just need to access that table and add all the sicknesses, use one same id so I can use it as foreign key in the table.
<?php
/* #var $this PigController */
/* #var $model Pig */
/* #var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'pig-form',
'enableAjaxValidation'=>true,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->dropDownList($model,'name');?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'breed'); ?>
<?php echo $form->dropDownList($model,'breed', $model- >getBreedOptions()); ?>
<?php echo $form->error($model,'breed'); ?>
</div>
/*
ENTER CODE FOR SICKNESS HERE
*/
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
I also had the same scenario. What i have done is with script.
Try this. It worked for me. Please do make necessary changes
$(function(){
$("#add").click(function(){
if(5 > $(".attr").length) {
var cycleBlock = '<tr id="item'+i+'">';
cycleBlock += '<td style="width: 447px;"> <label for="CategoryMstExt_Attribute">Attribute</label> <input type="text" id="CategoryMstExt_0_attributes" name="CategoryMstExt['+i+'][attributes]" class="attrName'+i+'" maxlength="100" size="44"> </td> <td> <label for="CategoryMstExt_Data_Type">Data Type</label> <select id="CategoryMstExt_'+i+'_datatype" name="CategoryMstExt['+i+'][datatype]" class="attr" onchange="javascript:checkSelection(this.value,'+i+')"> <option value="17">Textarea</option> <option value="16">Textbox</option> <option value="18">Listbox</option> </select><img onclick="deleteElm(item'+i+'.id);" src="<?php echo Yii::app()->request->baseUrl; ?>/assets/81ff99cf/gridview/delete.png" alt=""> </td>';
cycleBlock += '</tr>';
var $cycleBlock = $(cycleBlock);
$('#fields').append($cycleBlock);
i++;
} else {
alert('Maximum attributes limit reached');
}
});
});
<?php
<img style="margin-left:600px;" id="add" src="<?php echo Yii::app()->request->baseUrl; ?>/media/images/add.png">
<table id="fields" >
<tr id="item1" >
<td style="width: 447px;">
<?php echo $form->labelEx($model, 'Attribute'); ?>
<?php echo $form->textField($model, '[0]attributes', array('size' => 44, 'maxlength' => 100, 'class' => 'attrName0')); ?>
</td>
<td >
<?php echo $form->labelEx($model, 'Data Type'); ?>
<?php echo $form->dropDownList($model, '[0]datatype', Array('17' => 'Textarea', '16' => 'Textbox', '18' => 'Listbox'), array('onChange' => 'javascript:checkSelection(this.value,0)', 'class' => 'attr')); ?>
<img onclick="deleteElm(item1.id);" src="<?php echo Yii::app()->request->baseUrl; ?>/media/images/delete_2.png" alt="">
</td>
</tr>
</table>
?>
I can not figure out how to make one row of my table display on another page. What I want to do make each individual row printable. Here is a screen shot.
Here is the php used to display the table (coupon_index.php):
<?php include template("header");?>
<div id="bdw" class="bdw">
<div id="bd" class="cf">
<div id="coupons">
<div class="dashboard" id="dashboard">
<ul><?php echo current_account('/coupon/index.php'); ?></ul>
</div>
<div id="content" class="coupons-box clear">
<div class="box clear">
<div class="box-top"></div>
<div class="box-content">
<div class="head">
<h2>My <?php echo $INI['system']['couponname']; ?></h2>
<ul class="filter">
<li class="label">Category: </li>
<?php echo current_coupon_sub('index'); ?>
</ul>
</div>
<div class="sect">
<?php if($selector=='index'&&!$coupons){?>
<div class="notice">There is no usable <?php echo $INI['system']['couponname']; ?></div>
<?php }?>
<table id="orders-list" cellspacing="0" cellpadding="0" border="0" class="coupons-table">
<tr><th width="300">Deal Item</th><th width="100" nowrap>Voucher's Number</th><th width="60" nowrap>Voucher's Password</th><th width="100" nowrap>Valid Till</th><th width="40">Email Voucher</th></tr>
<?php if(is_array($coupons)){foreach($coupons AS $index=>$one) { ?>
<tr <?php echo $index%2?'':'class="alt"'; ?>>
<td><a class="deal-title" href="/team.php?id=<?php echo $one['team_id']; ?>" target="_blank"><?php echo $teams[$one['team_id']]['title']; ?></a></td>
<td><?php echo $two['id']; ?></td>
<td><?php echo $two['secret']; ?></td>
<td><?php echo date('Y-m-d', $two['expire_time']); ?></td>
<td>Send</td>
</tr>
<?php }}?>
<tr><td colspan="5"><?php echo $pagestring; ?></td></tr>
</table>
</div>
</div>
<div class="box-bottom"></div>
</div>
</div>
<div id="sidebar">
</div>
</div>
</div> <!-- bd end -->
</div> <!-- bdw end -->
<?php include template("footer");?>
and more (index.php):
<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');
need_login();
$daytime = strtotime(date('Y-m-d'));
$condition = array(
'user_id' => $login_user_id,
'consume' => 'N',
"expire_time >= {$daytime}",
);
$count = Table::Count('coupon', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 10);
$coupons = DB::LimitQuery('coupon', array(
'condition' => $condition,
'coupon' => 'ORDER BY create_time DESC',
'size' => $pagesize,
'offset' => $offset,
));
$team_ids = Utility::GetColumn($coupons, 'team_id');
$teams = Table::Fetch('team', $team_ids);
include template('coupon_index');
Here is the html(coupon_index.html):
<!--{include header}-->
<div id="bdw" class="bdw">
<div id="bd" class="cf">
<div id="coupons">
<div class="dashboard" id="dashboard">
<ul>${current_account('/coupon/index.php')}</ul>
</div>
<div id="content" class="coupons-box clear">
<div class="box clear">
<div class="box-top"></div>
<div class="box-content">
<div class="head">
<h2>My {$INI['system']['couponname']}</h2>
<ul class="filter">
<li class="label">Category: </li>
${current_coupon_sub('index')}
</ul>
</div>
<div class="sect">
<!--{if $selector=='index'&&!$coupons}-->
<div class="notice">There is no usable {$INI['system']['couponname']}</div>
<!--{/if}-->
<table id="orders-list" cellspacing="0" cellpadding="0" border="0" class="coupons-table">
<tr><th width="300">Deal Item</th><th width="100" nowrap>Voucher's Number</th><th width="60" nowrap>Voucher's Password</th><th width="100" nowrap>Valid Till</th><th width="40">Print Voucher</th></tr>
<!--{loop $coupons $index $one}-->
<tr ${$index%2?'':'class="alt"'}>
<td><a class="deal-title" href="/team.php?id={$one['team_id']}" target="_blank">{$teams[$one['team_id']]['title']}</a></td>
<td>{$one['id']}</td>
<td>{$one['secret']}</td>
<td>${date('Y-m-d', $one['expire_time'])}</td>
<td></td>
</tr>
<!--{/loop}-->
<tr><td colspan="5">{$pagestring}</td></tr>
</table>
</div>
</div>
<div class="box-bottom"></div>
</div>
</div>
<div id="sidebar">
</div>
</div>
</div> <!-- bd end -->
</div> <!-- bdw end -->
<!--{include footer}-->
The simplest solution to output a row per page when printing is simply to use page-break-before or page-break-after CSS properties. That said, you'll need to supress these on either the first or last tr depending on which route you choose.
e.g.:
<style>
#media print {
table tr {page-break-after:always}
}
</style>
you need to pass the database rowID of the coupon in question, or some variation thereof. I would use some hash of it, maybe the MD5 of it, along with a check on the far side that the session person is the owner of that coupon and the coupon is valid...
so your print link would be:
<td>Send</td>
in coupon_index.php i cant understand what $two refers to.
you probably need to better name and indent that piece of code, find a suitable id for the row you want to display, passing this information to the appropriate controller which will load only the relevant row.