i need implement a search by attribute “year”, but i need this in links (ex. when i click in link “2017”, $dataProvider return only records with “year” = “2017”), in index..php i have:
<div class="y-index">
<?php echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a(Yii::t('app', 'Create Oficios Apqe'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php Pjax::begin(); ?> <?= GridView::widget([
'dataProvider' => $dataProvider,
//'filterModel' => $searchModel,
'columns' => [
'id',
'name',
'minuta',
'year',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
<?php Pjax::end(); ?>
</div>
_search.php
<div class="y-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'minuta') ?>
<?= Html::a('2019', ['index', 'year' => '2019'], ['class' => 'year label label-efault', 'id' => '2019']) ; ?>
<?= Html::a('2018', ['index', 'year' => '2018'], ['class' => 'year label label-default', 'id' => '2018']) ; ?>
<?= Html::a('2017', ['index', 'year' => '2017'], ['class' => 'year label label-default', 'id' => '2017']) ; ?>
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('app', 'Reset'), [Yii::$app->controller->action->id], ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
basically i need the example with site from yii:
when i click in left menu in "Tutorial" option the link is set "https://www.yiiframework.com/wiki?category=3&version=2.0";
and after when i click in me menu "AJAX", the link is append and set to "https://www.yiiframework.com/wiki?tag=ajax&category=3&version=2.0";
basiclly i need search form param "year" with link, and with concatenate params from form "_search.php".
You can pass an array as the second parameter.
Html::a() uses yii\helpers\Url::to() on the background to create the link, docs. You can use any parameters that you want passing them as an array.
Html::a(
'2017',
['', 'year' => '2017'],
['class' => 'year label label-default', 'id' => '2017']
) ;
You just need to remove the action from the _search.php form it would submit to the current action automatically, and it would append the current query string with the new search parameters passed from the form.
Just change the
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
to
<?php $form = ActiveForm::begin([
'method' => 'get',
]); ?>
Related
Recentrly we developred a custom theme for our Wordpress website,
and I've used native comment Wordpress system that the code is something like below.
the question is how could we protect comment form from xss attack? it seems that scripts like <script>alert('hi');</script> runs simply on comments form.
any idea?
thank you.
<section>
<main>
<div class="comment-area">
<h2 class="comment-title -pb-20">
number of comments: <span><?php echo get_comments_number(); ?></span>
</h2>
<div class="comment-form">
<h3>Insert you comment here please.</h3>
<?php
$arg = array(
'title_reply' => '',
'comment_notes_before' => '',
'label_submit' => 'submmit',
);
comment_form($arg);
?>
</div>
<?php if (have_comments()) : ?>
<div class="comment-list">
<h1>all comments</h1>
<ul>
<?php
$args = array(
'style' => 'ul',
'callback' => null,
'end-callback' => null,
'type' => 'comment',
'reply_text' => 'reply',
'page' => '',
'per_page' => '',
'avatar_size' => 32,
'reverse_top_level' => true,
'reverse_children' => '',
'format' => 'html5',
'echo' => true,
);
wp_list_comments($args);
?>
</ul>
</div>
<div class="comments-pagination">
<?php if(get_comment_pages_count() > 1 && get_option('page_comments')) : ?>
<div>
<?php previous_comments_link('prev'); ?>
</div>
<div>
<?php next_comments_link('next'); ?>
</div>
<?php endif; ?>
</div><!-- .comments-pagination -->
<?php endif; ?>
</div>
</main>
</section>
add_filter( 'comment_text', 'sanitize_comment' );
function sanitize_comment( $comment_text ) {
$comment_text = sanitize_text_field($comment_text);
return $comment_text;
}
I need to create a common search in yii2 grid which will search from all the column of grid view table.This is what I did so far.
index.php
<div class="pull-right">
<?php yii\widgets\Pjax::begin(['id' => 'search-form' , 'timeout' => false, 'clientOptions' => ['method' => 'POST']]) ?>
<?php $form = ActiveForm::begin(['options' => ['data-pjax' => true ]]); ?>
<?= $form->field($model, 'searchString')->textInput(['maxlength' => 200])->label(false) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
<?php yii\widgets\Pjax::end() ?>
</div>
<?php Pjax::begin(['id' => 'assets']); ?>
<?=
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
/** column names **/
]);
?>
<?php Pjax::end(); ?>
$this->registerJs(
'$("document").ready(function(){
$("#search-form").on("pjax:end", function() {
$.pjax.reload({container:"#assets"});
});
});'
);
Now when I submit searchbox didn't get desired result. Is there anything which I need to do to get output which I want. I looked from these links.
Link1
Link2
Please help me to achieve this.
I have a manage quotations page. I need a search based on quotation name and project customer in drop down. With respect to quotation name, I got right search. But drop down user search is not working correctly. The drop down is using another model. The code I followed is given below:-
manageprojects.php
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form">
<?php $this->renderPartial('_search',array(
'model'=>$bots,
'modell'=>$model,
)); ?>
</div>
_search.php
<?php
/* #var $this QuotationsController */
/* #var $model Aquotations */
/* #var $form CActiveForm */
?>
<?php $form=$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<style>
.row1{width:auto; overflow:hidden;}
.row20{width:20%;display:inline-block;}
</style>
<div class="row1">
<div class="row20">
<?php echo $form->label($model,'Quotation Serial No'); ?>
<?php echo $form->textField($model,'serial_no'); ?>
</div>
<div class="row20">
<?php echo $form->label($model,'Project'); ?>
<?php echo $form->textField($model,'project_id',array('size'=>60,'maxlength'=>255,'id' =>'projectsid','onkeyup' => "searchcprojects()")); ?>
<div id="searchresult" style="background:#90EE90;"></div>
</div>
<div class="row20">
<?php echo $form->label($model,'Select User'); ?>
<?php echo CHtml::dropDownList('user_id', $model->id, CHtml::listData($model::model()->findAll(array('order' => 'name')), 'id', 'name'), array('empty' => 'Select User', 'class' => 'span12')); ?>
</div>
<div class="row20">
<?php echo CHtml::submitButton('Search', array("class" => "btn btn-danger")); ?>
</div>
</div><!--row1-->
<?php $this->endWidget(); ?>
project Controller
$model = new Acustomers();
$bot=new Aquotations('search');
$bot->unsetAttributes(); // clear any default values
if(isset($_GET['Aquotations'])){
$bot->attributes=$_GET['Aquotations'];
}
$this->render('managequotations',array(
'bots' => $bot,
'model' => $model,
You need to use the activeDropDownList not the dropDownList:
<?php echo CHtml::activeDropDownList($model, 'user_id',
CHtml::listData(User::model()->findAll(array('order' => 'name')),'id','name'),
array('empty' => 'Select User', 'class' => 'span12'));
?>
I'm building a site with Zend 2.3 and what I want to do is to paginate the results using
Zend Paginator. I don't get any error, in fact I can see every link correctly, however they don't work properly.
When I want to paginate the news within a category, Paginator generates the following links:
........./index/categories/1
........./index/categories/2
........./index/categories/3
............................
Instead the links I want (i.e category 2) should be like:
............/index/categories/2/1
............/index/categories/2/2
............/index/categories/2/3
This is my module.config:
'index'=>array(
'type'=>'Segment',
'options'=>array(
'route' => '/index[/[:action][/:id][/:id2]]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index'
),
),
),
I've already tried passing $cat_id from controller to URL helper ('id'=>$this->id) but it doesn't work. Only it seems to work when I hardcode the id value, for example:
First
This doesn't work:
First
So my question is, How can I do it work passing vars to Paginator?
Thanks
It's hard to create an example with such limited information but generally you'd follow this:
This would be in your controller
// This is some array of data that you've pulled from a data source
$arrayOfYourData = array();
$paginator = new \Zend\Paginator\Paginator(new \Zend\Paginator\Adapter\ArrayAdapter($arrayOfYourData));
$paginator->setItemCountPerPage(25);
$paginator->setCurrentPageNumber((int) $this->params()->fromQuery('page',1));
// now return $paginator to your view by assigning it to ViewModel, etc
Then in your view you would have something like this example
<?php echo $this->paginationControl($paginator, 'Sliding', 'your-namespace/pagination_control.phtml', array('route'=>'some/route', 'routeOptions'=>array('action'=>'some-action')); ?>
and then you should have a views/your-namespace/pagination_control.phtml as such:
<?php if ($this->pageCount): ?>
<div class="paginationControl">
<?php echo $this->firstItemNumber; ?> - <?php echo $this->lastItemNumber; ?>
of <?php echo $this->totalItemCount; ?>
<!-- First page link -->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url($this->route, array('page' => $this->first)); ?>">
First
</a> |
<?php else: ?>
<span class="disabled">First</span> |
<?php endif; ?>
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url($this->route, array('page' => $this->previous)); ?>">
< Previous
</a> |
<?php else: ?>
<span class="disabled">< Previous</span> |
<?php endif; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url($this->route, array('page' => $this->next)); ?>">
Next >
</a> |
<?php else: ?>
<span class="disabled">Next ></span> |
<?php endif; ?>
<!-- Last page link -->
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url($this->route, array('page' => $this->last)); ?>">
Last
</a>
<?php else: ?>
<span class="disabled">Last</span>
<?php endif; ?>
</div>
<?php endif; ?>
I'm using WP Events Manager and Advanced Custom Fields to develop a site, I have a custom post type called 'event' which I want to display via the below:
<article class="col-main col clearfix">
<table>
<tr>
<th>Cours</th>
<th>Niveau</th>
<th>Dates</th>
<th>Heures</th>
</tr>
<?php
$args = array(
'post_type' => 'event',
'posts_per_page' => 10,
'paged' => get_query_var('paged'),
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => '_event_start_date');
$loop = new WP_Query( $args );
if($loop->have_posts()):
while ( $loop->have_posts() ) : $loop->the_post();
$EM_Event = em_get_event($post->ID, 'post_id');
?>
<tr>
<td><?php echo $EM_Event->output('#_EVENTLINK'); ?></td>
<td><?php the_field('niveau'); ?></td>
<td><?php if($slug != 'stages-ete'): ?>Chaque: <?php the_field('jours'); echo '<br />'; endif; echo $EM_Event->output('#_EVENTDATES'); ?></td>
<td><?php echo $EM_Event->output('#_EVENTTIMES'); ?></td>
</tr>
<?php endwhile;?>
<?php else: ?>
<tr><td colspan="3"><em>Pas de cours à venir.</em></td></tr>
<?php endif; ?>
</table>
<div class="navigation">
<div class="next-posts"><?php next_posts_link('« Older Entries'); ?></div>
<div class="prev-posts"><?php previous_posts_link('Newer Entries »'); ?></div>
</div>
</article>
But it's not displaying the previous and next links. Any ideas?
Thanks
Try adding the arguments this way instead
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'event',
'posts_per_page' => 10,
'paged' => $paged,
'order' => 'ASC',
'orderby' => 'meta_value',
'meta_key' => '_event_start_date');
);