I want to display a loading image when I click on a sorting link of a listing record. Before, I used the complete property of Paginator. This works well if the table has more than one record.
My code is as follows:
<?php
$this->Paginator->options(array(
'update' => '#ourCompany-part',
'evalScripts' => true,
'before' => $this->Js->get('#loading')->
effect('fadeIn', array('buffer' => false)),
'complete' => $this->Js->get('#loading')->
effect('fadeOut', array('buffer' => false)),
));
?>
When the table has one record and we click on the sorting link of the paginator, it doesn't display the loading image. If the table has no records, then the index page is not loaded. How could I solve this?
Personally i don't like JsHelper i wrote jquery pugins or small function in my view. So check that the javascript looks like where you see 1 record or no record, it seems that helper not render javascitpt.
Related
I'm making internet ordering site on Yii2 framework. Now I have page for restaurant page with products, where I can order specified product (can see on screen). How can I implement dynamic success flash image after ordering the product, that will appear on top of page and then fade out? I don't want for page to reload.
In your layout view file add (on top of your content):
<?=yii\bootstrap\Alert::widget([
'options' => [
'class' => 'alert-info',
],
'body' => Yii::$app->getSession()->getFlash('success'),
]);?>
In your controller
public function actionOrder()
{
....
//After order is made
Yii::$app->getSession()->addFlash('success', 'Your Order Has been made successfuly...');
//redirect
...
}
I have searched for this topic here and Google but I only found the solutions with PHP frameworks (for example, YII and Laravel)
I am developing a simple CMS and I would like to add widget system just like WordPress ( Recent Comments, Categories widgets )
List available widgets.
Users can active the widgets and use them in sidebar.
My steps:
1. First at all, I already made an admin tool as the screenshot blow ( jQuery UI sortable works fine)
Here is my php code:
$available_widgets = array(
0 => array(
'id' => 'recent-post',
'title' => 'Latest Pots',
'option' => array( 'display_count' => 5, 'multi_widget' => 0)
),
1 => array(
'id' => 'recent-comment',
'title' => 'Recent Commets',
'option' => array( 'display_count' => 5, 'multi_widget' => 0)
),
2 => array(
'id' => 'text-box',
'title' => 'Text Box',
'option' => array('multi_widget' => 1)
)
);
View
foreach ( $available_widgets AS $available_widget ) {
if ( $available_widget['option']['multi_widget'] == 0 ) {
echo '<li class="widget-box widget-single" data-widget-id="' . $available_widget['id'] . '" ><div class="widget-handle">' . $available_widget['title'] . '</div></li>';
}
else {
echo '<li class="widget-box widget-multiple" data-widget-id="' . $available_widget['id'] . '" ><div class="widget-handle">' . $available_widget['title'] . '</div></li>';
}
}
But I still no idea about the next step, any idea will be grateful.
Thanks.
Update:
For my step 2 I made a simple EventDispatcher, I put the link here if someone else needs it.
https://github.com/terrylinooo/PHP-EventDispatcher
You may be underestimating the complexity of this question. If you are doing this from scratch, there will be several things to consider.
Are you creating all your widgets, and then just want the user to be able to pick and choose which ones they want visible?
If so, roughly I would probably:
Obviously make html sidebar that will house the widgets, styled by your css. Have the width of column set to 0 if no widgets are published.
And of course make all your widgets in separate files probably in their own folder.
Have database table with at very least path to widget file, "published" boolean column, and "widget_order" column.
Choose where in the admin area the user will choose which ones to show, and have it change the "published" column in the table, and maybe also a small text box or dropdown where they can specify the order number.
Then on the front end, just do a database lookup in the sidebar, if the number of rows from the module table that are "published" is greater than 0, then 'echo' out a css value that will give your column the correct width (of your choice) instead of 0 width keeping it hidden otherwise if none are enabled.
The database look up should have the ORDER BY clause to follow the 'widget_order' values. This obviously is how the widgets get displayed in order by the users preference.
Now each widgets functionality is all in each file, so put any relevant php, Javascript etc, in each one which will make them easy to develop and modify. Obviously you can refactor after where feasible.
Hope this gives you an idea of what you're getting in to lol..
Take a look at Observer Pattern
or Event Dispatcher Pattern for plugin system
When installing plugins, don't forget to save it to the database
And, to list available widgets, you just need to query the database which plugins are available or activated.
I use CGridView in Yii to create tables. I would like to show my table with pagination, but display summary text (i.e. Displaying 1-4 of 4 results.) at the bottom of grid. Is it possible in Yii?
You need to add this property to your array options widget:
'template'=>'{items}{summary}{pager}'
This is how it should look like:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$model->search(),
'filter'=>$model,
'enablePagination' => true,
'template'=>'{items}{summary}{pager}',
'columns'=>array(...)
),
));
Yii docs - CBaseListView
'template'=>"{summary}\n{items}\n{pager}"
I am trying to modify a table built using Yii boostrap and CactiveDataprovider, the table works fine but it automatically also displays the count of all items found, how to disable displaying this count
this is the view logic currently
$this->widget('bootstrap.widgets.TbListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'viewData'=>array('page'=>$page),
'itemsTagName'=>'table',
'itemsCssClass'=>'items table table-striped table-condensed',
'emptyText'=>'<i> Sorry, there are no active items to display</i>',
));
You need to add this line:
'template' => "{sorter}\n{items}\n{pager}",
TbListView extends from CListView, which uses the template variable to control the layout. See: http://www.yiiframework.com/doc/api/1.1/CListView#template-detail
The default template is "{summary}\n{sorter}\n{items}\n{pager}" where {summary} is what shows the count. So if you remove that, the count won't show
You might be reffering to: example
If so, set the template property as needed.
You need to delete the summary text.
pages stands for the pagination
items stands for ... the list of items
<?php
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'template' => "{summary}\n{pager}\n{items}\n{summary}\n{pager}",
'itemView' => '_index',
'pager' => array(
'maxButtonCount' => 10,
),
)
);
?>
It is easy.
put propriety summaryText false.
<?php $this->widget('bootstrap.widgets.TbListView',array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view_mercado',
'summaryText'=>false //make it for hide summary text
)); ?>
What about using CSS? is pretty straight forward
I got this alternative answer from an offline source, posting here for completeness.Both Ionut-flavius-Pogacian and frostyterrier methods worked and are better solutions as defining the template gives even more control over the widget behavior rather than just defining the summaryText as in the answer below
Tblistview is not documented in Yii-bootstrap documentation, but scanning the source it seems it is wrapper for CListview class in Yii.
CListview extends CBaseListView which has the summaryText property. Passing Blank data to it, removes the count which is active by default.
http://www.yiiframework.com/doc/api/1.1/CBaseListView#template-detail
SummaryText has the following usable variables
{start}: the starting row number (1-based) currently being displayed
{end}: the ending row number (1-based) currently being displayed
{count}: the total number of rows
{page}: the page number (1-based) current being displayed, available since version 1.1.3
{pages}: the total number of pages, available since version 1.1.3
{start} {end} and {count} are visible by default
The code could be modified to
$this->widget('bootstrap.widgets.TbListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'viewData'=>array('page'=>$page),
'itemsTagName'=>'table',
'itemsCssClass'=>'items table table-striped table-condensed',
'emptyText'=>'<i> Sorry, there are no active items to display</i>',
'summaryText'=>''
));
I'm working on a site for a client that wants to be able to update modifying their content. The brief was to allow them to edit pages, but not create or delete them. For the site I decided to work with cakePHP, as I've heard good things.
First up, a quick explanation of my setup. I've got a single table, called 'contents', in which i'm storing each page's content. The table has a pid, a varchar 'title', a varchar 'slug' and a longtext 'body'. They're all pretty self explanitory, Each page will have it's own row, and body will be a simple HTML dump.
I've got two situations that I am having trouble with. Firstly, is setting the homepage. Cake's default is the page based on home.ctp, but that is static. Currently the page I was as the homepage is at localhost/alc/contents/view/2. I understand this is something to do with the routing, but most examples out there give half the solution, when I need every detail :P
The second problems is the slugs of the pages. Each page is currently under /contents/view/id, and i'd like this to be the slug in the database instead. Each time i try to change this (i.e. modify the view link in my index), I get an error rather than the page's content.
Any help on this would be appreciated, as there are the two things I cannot seem to grasp properly. Thanks!
By the way, you can view the site at http://www.roberttilt.name/web-dev/ALC_proto/
For the first question you need to open the /app/config/routes.php and change the line which is for the home page. i.e.:
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
need to become
Router::connect('/*', array('controller' => 'contents', 'action' => 'view'));
In your controller file /app/controllers/contents_controller.php go to action view and change it to accept empty id i.e.
function view($id = null){
if($id == null){ //Load the default home page
$this->find('first', array('conditions'=>array('default'=>1)));
} else {
//load the
$this->find('first', array('conditions'=>array('OR'=>array('slug'=>$id, 'id'=>$id))));
}
.....
}
This way if the id or slug are not provided you are loading the home page. If one of them is loaded, just use it to load the contents of the desired web page.
Your links will look like:
$this->Html->link('About', array('controller'=>'contents', 'action'=>'view', $slug_var));
The link will be converted to
About
Probably you have to take a look on the Cookbook.