Search Function in Symfony2 is not working - php

I am working on a project using symfony framework. I just want to make a simple search function wherein it can search all the entities that contain with what the user inputted. When I tried to run my code, its not working it keeps on redirecting to my no found result even if their is a related files to be found with.
Here is my controller:
public function searchAction(Request $request){
$request = $this->getRequest();
$data = $request->request->get('search');
$em = $this->getDoctrine()->getManager();
$query = $em->createQuery(
'SELECT a,b,c
FROM SampleBundle:transactionDetail a
JOIN a.transaction b
JOIN b.documentRelated c
WHERE a.pNumber LIKE :data
AND b.senderId LIKE :data
AND b.receiverId LIKE :data
AND b.transactDate LIKE :data
AND a.amountPaid LIKE :data')
->setParameter('data',$data);
$res = $query->getResult();
if($res == null){
return $this->render('SampleBundle:Sample:noresult.html.twig');
}
return $this->render('SampleBundle:Sample:search.html.twig', array('res' => $res));
}
and for my search.html.twig
{% extends '::layout.html.twig' %}
{% block pageTitle %} Related Files Found{% endblock %}
{% block body %}
div class="table-responsive margins" >
<table class="table table-condensed table-striped table-bordered table-hover no-margin">
<thead>
<tr style="height: 40px; ">
<th>Transaction Date</th>
<th>Sender ID</th>
<th>Receiver ID</th>
<th>P Number</th>
<th>Amount Paid</th>
</tr>
</thead>
<tbody>
<tr>
{% for res in res %}
{% for other in res.transaction %}
<td >{{res.transaction.transactDate|date('YMd')}} {{res.ediTransaction.transactionDate|date('H:i')}}</td>
<td>{{res.transaction.senderId}}</td>
<td >{{res.transaction.receiverId}}</td>
{% if other.pNumber != null %}
<td style="word-break: break-all">{{other.pNumber}}</td>
{% else %}
<td>N/A</td>
{% endif %}
{% if other.amountPaid != null %}
<td style="word-break: break-all">{{other.amountPaid}}</td>
{% else %}
<td>N/A</td>
{% endif %}
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
{% block javascripts %}
{% javascripts
'bundles/sampledoc/js/jQuery.js'
'bundles/sampledoc/js/bootstrap.js'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
my form for searching:
<form action="{{path('sample_search')}}" method="POST">
<div class="form-group input-group">
<input type="text" name="search" class="form-control" placeholder="Search" style="width: 200px; float: right;" >
<span class="input-group-btn"><button class="btn btn-default" type="submit" style="margin-right: 20px;"><i class="fa fa-search"></i></button></span>
</div>
</form>
Can somebody help me with this one? thanks in advance.

Data can't equal all your criteria. If you AND everything in your query data has to match all fields, so you will probably return no results.
Try something like:
WHERE a.pNumber LIKE :data
OR b.senderId LIKE :data
OR b.receiverId LIKE :data
OR b.transactDate LIKE :data
OR a.amountPaid LIKE :data')
->setParameter('data', "%$data%");
And look at the generated SQL with
$query->getSQL()
This way you can actually test your query directly on the DB.

Assuming $data is an associative array holding all the goodies, I do not think you can just hand it to setParameter() the way you are doing. You need to break it down more specifically, for each of those "LIKE" clauses.
Completely untested but I suspect you are looking for something like:
`
WHERE a.pNumber LIKE :pNumber
AND b.senderId LIKE :senderId
AND b.receiverId LIKE :recieveId
AND b.transactDate LIKE :transactDate
AND a.amountPaid LIKE :amountPaid')
->setParameters(array(
'pNumber' => $data['pNumber'],
'receiverId' => $data['receiverId'],
'transactDate' => $data['transactDate'],
'amountPaid' => $data['amountPaid'],
));
`

Related

Twig dividing data into tables

I am working on a webapplication but ive ran into a hiccup, I have gathered data from my database and displayed the records into a datatable, my problem is that I can not just have one table the client wants me to divide the table into multiple based on what interger is in a column(omloopNummer).
The best ive gotten so far is with the following code it wil split the table up into lets say 4 tables if the interger in the database wil go 1,2,3,4 but it wil only show 1 record in each table while it should be more.
If there is any other simple solution to this instead of using twig I would be happy to try it.
<div id="index" class="table-responsive">
{% set i = 1 %}
{% for duel in duels %}
{% if duel.omloopNummer == i %}
{% set i = i + 1 %}
<table id="" class="table display-" style="width: 90%; margin-top: 30px">
<thead>
<tr>
<th>Omloop</th>
<th>Team 1</th>
<th>vs</th>
<th>Team 2</th>
<th>Acties</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ duel.omloopNummer }}</td>
<td>{{ duel.team1 }}</td>
<td>vs</td>
<td>{{ duel.team2 }}</td>
<td>{{ include('duel/_delete_form.html.twig') }}</td>
</tr>
</tbody>
</table>
{% endif %}
{% endfor %}
You could use PHP to group Duels by omloopNummer in the controller before passing to twig.
$duels = $duelRepository->findAll();
$sorted = [];
foreach($duels as $duel){
$sorted[$duel->getOmloopNummer()][] = $duel;
}
return $this->render('template.html.twig', [
'duel_groups' => $sorted,
]);
Then in twig, loop through the sorted array building a table for each non-empty group and inside each tbody loop through the group.
{% for group in duel_groups %}
...
{% if group is not empty %}
<table>
...
<tbody>
{% for duel in group %}
<tr>...</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
...
{% endfor %}

Two dimensional array in Twig

I have satellite images stored in a mysql database. The table has attributes latitude,longitude. I want to send them to the twig and display as a map, my php controller looks like this.
public function highlightAction()
{
$highlighted=$this->getDoctrine()
->getRepository('AppBundle:satelliteImage')
->findAll();
$images = array();
foreach ($highlighted as $key => $high) {
$images[$key] = base64_encode(stream_get_contents($high->getImage()));
}
return $this->render('satelliteImages/highlighted.html.twig',array(
'highlighted' => $highlighted,
'images' => $images
));
}
My twig code is this:
<tbody>
{% for key,high in highlighted %}
<tr>
<img alt="Embedded Image" src="data:image/png;base64,{{ images[key] }}" />
</tr>
{% endfor %}
</tbody>
I am displaying the images as a vertical array. Any suggestions, I might need to display them as a map.
A two dimensional array in twig?
You can use something like this:
<table>
<tbody>
{% for key in 0..2 %}
<tr>
{% for key in 0..3 %}
<td>
<img alt="Embedded Image" src="data:image/png;base64,
{{ images[loop.parent.key*4 + key] }}" />
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
Read the Twig for documentation.

Method for Object does not exist?

I am new to symfony2 I'm trying to create a search function and got this
error 'Method "ediTransaction" for object "Matrix\MatrixEdiBundle\Entity\Edi997SegmentInError" does not exist in MatrixEdiBundle:Matrix:rejectedTrans.html.twig at line 58'
is it what problem is it? Anyone?
Repository
class Edi997DetailsRepository extends EntityRepository{
public function getDetails($gsNumber, $senderId, $receiverId, $page = 1, $limit = 5 ){
$em = $this->getEntityManager();
$query = $em->createQuery(
'SELECT partial a.{id, ak301, ak401},
partial b.{errorCode, condition},
partial c.{edi997DetailId, errorCodeId, noOfTrans},
partial d.{ediTransactionId, senderId, receiverId, gsNumber, isaNumber, fileName}
FROM MatrixEdiBundle:Edi997SegmentInError a
JOIN a.ediAk403ErrorCodes b
JOIN a.edi997Details c
JOIN c.ediTransaction d
WHERE d.gsNumber LIKE :gsNumber
AND d.senderId LIKE :senderId
AND d.receiverId LIKE :receiverId
AND c.errorCodeId != 1
AND d.flag = 1')
->setParameter('gsNumber', "%$gsNumber%")
->setParameter('senderId', "%$senderId%")
->setParameter('receiverId', "%$receiverId%")
->setFirstResult(($page-1)*$limit)
->setMaxResults($limit);
$paginator = new Paginator($query, $fetchJoinCollection = false );
$paginator->setUseOutputWalkers(false);
return $paginator;
}
}
Twig :
{% if transaction != null %}
{% for trans in transaction %}
<tr>
<td style="width: 11%;">
{{ render(controller('MatrixEdiBundle:Matrix:getTradingPartnerName', {'timexID' : trans.ediTransaction.receiverId, 'customerID' : trans.ediTransaction.senderId})) }}
</td>
{%
set result=render(controller('MatrixEdiBundle:Matrix:getFile', {'fileName' : trans.ediTransaction.fileName, 'senderId': trans.ediTransaction.receiverId , 'receiverId' : trans.ediTransaction.senderId }))|split('+', 4)
%}
<td style="width: 10%;">{{ result[0] }}</td>
<td style="width: 40%;">{{ result[3] }}<br><br>
{% if trans.errorCodeId == 2 %}
<span style="background-color: yellow;">Accepted but <br/>errors were <br/>noted</span><br/>
{% elseif trans.errorCodeId == 3 %}
<span style="background-color: yellow;">Partially<br/> Accepted</span><br/><br/>
{{ trans.acceptedTrans }} Accepted,<br/>
{{ trans.noOfTrans - trans.acceptedTrans }} Rejected
{% else %}
<span style="background-color: yellow;">Rejected</span>
{% endif %}
<br/>
{%
set error=render(controller('MatrixEdiBundle:Matrix:getError', {'id': trans.edi997DetailId }))|split('+')
%}
<span>
<p style="white-space: normal;">
{% if error[0] != "0" %}
{{ error[0] }}{{ "%02d"|format(error[1]) }}<br/>
{{ error[2] }}
{% else %}
Errors were not specified in 997 file
{% endif %}
</p>
</span>
</td>
<td style="width: 10%;">{{ result[2] }}</td>
<td style="width: 7%;">{{ result[1] }}</td>
<td style="width: 5%;">{{ trans.noOfTrans }}</td>
<td style="width: 7%;">{{ trans.ediTransaction.receiverId }}</td>
<td style="width: 8%;">{{ trans.ediTransaction.senderId }}</td>
<td>
<center><i class="fa fa-trash o" style="color:#1975A3;"></i></center>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td colspan="15" class="alignment result"> No Result Found </td>
</tr>
{% endif %}
The answer is in the error.
In your Edi997SegmentInError entity object, there is no ediTransaction method.
Probable causes:
The method doesn't exist in any object
The method exists in an
object, just not the one you're accessing
Looking at your repository method, that seems to be in your Edi997Details entity.
Presumably you'd access it via {{trans.edi997Details.ediTransaction.receiverId}} - but I'm really guessing there - you have to follow your object hierarchy correctly in twig. If you're not sure exactly which object you're accessing, try using {{dump(trans)}} to see what you have.

Symfony2 Table with 3 entity in Twig

First of all, sorry by advance for my english which is not perfect.
I have a problem for days by reporting 3 doctrine entity in a Twig Table template.
It's a table for manage stocks at work. I have different materials which have each different sizes. Each couple (1 material + 1 size) got a number as amound to order.
So I first created 3 entity :
Stock (represent materials) ManyToMany Dimension (represent sizes)
Besoin (needs) got a ManyToOne relation with both Stock and Dimension.
Then, I created few Stocks, Dimensions and needs with my forms to get a test database.
The goal is now to create a double entry table with the dimensions list, Stocks list and in each cell the needed number.
It's in this step that I have bugs.
For now I can give you my code and hope someone can help me by giving me a tips.
Controller :
public function commandeAction()
{
$em = $this->getDoctrine()->getManager();
$materiauxlist = $em->getRepository('TGComptaBundle:Stock')->findAll();
$dimensionslist = $em->getRepository('TGComptaBundle:Dimension')->findAll();
$tab1 = array_merge($materiauxlist, $dimensionslist);
$besoins = array();
foreach ($materiauxlist as $stock) {
foreach ($dimensionslist as $dimension) {
$besoin = $em->getRepository('TGComptaBundle:Besoin')->findBesoins($stock, $dimension);
}
}
return $this->render('TGProdBundle:Projet:stocks.html.twig', array(
'materiauxlist' => $materiauxlist,
'dimensionslist' => $dimensionslist,
'besoin' => $besoin));
}
View :
{% block tgprod_body %}
<div class="well">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>#</th>
{% for dimension in dimensionslist %}
<th>{{ dimension.name }}</th>
{% endfor %}
</tr>
</thead>
{% for stock in materiauxlist %}
<tr>
<td>{{ stock.name }}</td>
{% for dimension in dimensionslist %}
{% if besoin %}
<td>{{ besoin.nombre }}</td>
{% else %}
<td>X</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
Repository :
public function findBesoins($stock, $dimension)
{
$qb = $this->createQueryBuilder('b');
$qb
->where('b.stock = :stock')
->andwhere('b.dimension = :dimension')
->setParameter('stock', $stock)
->setParameter('dimension', $dimension);
$qb
->getQuery()
->getResult();
}
My actual problem is : I have X in all cells
Before I asked your help I tried :
foreach ($materiauxlist as $stock) {
foreach ($dimensionslist as $dimension) {
$besoin = $em->getRepository('TGComptaBundle:Besoin')->findBesoins($stock, $dimension);
$besoins[] = $besoin;
}
}
and :
<table class="table table-hover table-bordered">
<thead>
<tr>
<th>#</th>
{% for dimension in dimensionslist %}
<th>{{ dimension.name }}</th>
{% endfor %}
</tr>
</thead>
{% for stock in materiauxlist %}
<tr>
<td>{{ stock.name }}</td>
{% for dimension in dimensionslist %}
{% for besoin in besoins %}
{% if besoin %}
<td>{{ besoin.nombre }}</td>
{% else %}
<td>X</td>
{% endif %}
{% endfor %}
{% endfor %}
</tr>
{% endfor %}
</table>
But it was wrong result (I had like 10000 X on each row)
I thinked it's the "{% for besoin in besoins %}" which is wrong, it should be something like "{% for besoin.dimension.stock in besoins %}" but I can't write this in twig.
and I tried something like this to :
$table = array('stock' => $stock, 'dimension' => $dimension, 'besoin' => $besoin);
$besoins[] = $table;
when I do a { dump() } in Twig I have array with number of stock x number of dimension and all with a null besoin so it seems strange ... and finally I didn't find how to render this array in my table so I let this solution away :/

Symfony2: use flush() or persist() to optimize data handling

Im working with Symfony (const version="2.5.10") and using XAMPP with PHP version of 5.5.19
My problem is I keep on getting out of memory error. Because I think I query thousand of data (rows) in the database. For info, I have a lot of data in the database. I want to use flush() or anything that could be use to optimize my data handling.
Here is my code in my indexAction controller:
public function indexAction(){
$em = $this->getDoctrine()->getManager();
$po = $em->getRepository('MatrixEdiBundle:EdiTransactionDetail')->findDocs('850');
return $this->render('MatrixEdiBundle:Matrix:index.html.twig', array('po' => $po));
}
index.html.twig
{% extends '::layout.html.twig' %}
{# {% include 'MatrixEdiBundle:Matrix:header.html.twig'%} #}
{% block body %}
<div class="content">
</br>
<table id="datTable" class="table table-bordered table-condensed table-hover">
<thead>
<th colspan="8">Edi Matrix</th>
<tr>
<th>Po Numbers</th>
<th>Trading Partner Id</th>
<th>PO 855 Acknowledgement</th>
<th>PO 997 Acknowledgement</th>
<th>Advance Shipment Notice</th>
<th>Invoice</th>
<th>Purchase Order Change</th>
<th>Order Status</th>
</tr>
</thead>
<tbody>
{% for tran in po %}
<tr>
<td><a href="{{ path('matrix_edi_showpo', {'po_num': tran.poNumber}) }}"data-toggle="modal" data-target="#myModal">{{tran.poNumber}}</td>
<td>{{tran.ediTransaction.senderId}}</td>
<td><a href="{{ path('matrix_edi_findAll', {'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'doc_type': 855}) }}"data-toggle="modal"data-target="#myModal">
{{ render(controller('MatrixEdiBundle:Matrix:matrix', {
'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'reciever_id': tran. ediTransaction.receiverId, 'doc_type': 855, 'gs_number': tran.ediTransaction.gsNumber })) }}</a>
</td>
<td><a href="{{ path('matrix_edi_poack', {'gs_number': tran.ediTransaction.gsNumber, 'receiver_id': tran.ediTransaction.receiverId, 'sender_id': tran.ediTransaction.senderId}) }}"data-toggle="modal"data-target="#myModal">
{{ render(controller('MatrixEdiBundle:Matrix:matrix', {
'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'reciever_id': tran. ediTransaction.receiverId, 'doc_type': 997, 'gs_number': tran.ediTransaction.gsNumber })) }}</a>
</td>
<td><a href="{{ path('matrix_edi_findAll', {'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'doc_type': 856}) }}"data-toggle="modal"data-target="#myModal">{{ render(controller('MatrixEdiBundle:Matrix:matrix', {
'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'reciever_id': tran.ediTransaction.receiverId, 'doc_type': 856, 'gs_number': tran.ediTransaction.gsNumber }))}}</a>
</td>
<td>{{ render(controller('MatrixEdiBundle:Matrix:matrix', {'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'reciever_id': tran.ediTransaction.receiverId, 'doc_type': 810, 'gs_number': tran.ediTransaction.gsNumber})) }}
</td>
<td>{{ render(controller('MatrixEdiBundle:Matrix:matrix', {'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'reciever_id': tran.ediTransaction.receiverId, 'doc_type':860, 'gs_number': tran.ediTransaction.gsNumber})) }}
</td>
<td><a href="{{ path('matrix_edi_findAll', {'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'doc_type': 870}) }}"data-toggle="modal"data-target="#myModal">{{ render(controller('MatrixEdiBundle:Matrix:matrix', {
'po_num': tran.poNumber, 'sender_id': tran.ediTransaction.senderId, 'reciever_id': tran.ediTransaction.receiverId, 'doc_type': 870, 'gs_number': tran.ediTransaction.gsNumber
})) }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false" >
<div class="modal-dialog">
<div class="modal-content" style="width: 650px;">
<div class="modal-header" style="background-color: #2d6ca2; color: white;">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true" style="color: white;">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="myModalLabel" >Details</h4>
</div>
<div class="modal-body">
Loading, please wait......
<div class="bootstrap-table">
<div class="fixed-table-container" style="height: 299px; padding-bottom: 37px;">
<div class="fixed-table-body">
<div class="fixed-table-loading" style="top: 27px; display: none;">Loading, please wait…</div>
</div>
<div class="fixed-table-pagination"></div>
</div>
</div><div class="clearfix"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" >Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
{% endblock %}
{% block javascripts %}
{% javascripts
'bundles/matrixdoc/js/jQuery.js'
'bundles/matrixdoc/js/jquery.dataTables.min.js'
'bundles/matrixdoc/js/dataTables.bootstrap.js'
'bundles/matrixdoc/js/bootstrap.js'
%}
<script src="{{ asset_url }}"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#datTable').dataTable( {
"scrollY": "400px",
"scrollCollapse": true,
"pagingType": "simple",
});
$('body').on('hidden.bs.modal', '.modal', function () {
$(this).removeData('bs.modal');
});
$(document).on("hidden.bs.modal", function (e) {
$(e.target).removeData("bs.modal").find(".modal-content").empty();
});
});
</script>
{% endjavascripts %}
{% endblock %}
You should use pagination getting your data with limits and coupled with partial to get your needed fields if you don't need everything.
http://zrashwani.com/pagination-optimization-symfony2-doctrine/#.VV1av_mSwbg
for partial in DQL , simple example for user:
//partial_fields is an array, which can be passed like this $repo->getPartialUser($user_id, array('field1', 'field2', 'etc..');
public function getPartialUser($id, $partial_fields){
$qb = $this->_em->createQueryBuilder()
->select('partial u.{'.implode(',',$partial_fields).'}')
->from('AcmeUserBundle:User', 'u')
->where('u.id = :id')
->setParameter('id', $id);
$result = $qb->getQuery()->getOneOrNullResult();
return $result;
}
EDIT EXAMPLE CODE :
i will give you an example but you will probably still need to adapt it to your code or maybe it will work out of the box.
First you need a new twig with simple piece of code to show pages numbers for navigation below the table (note that i will not use datatables paginator but we will keep it for table layout rendering) :
pager.html.twig
<div class="pagination">
<div class="pagination-buttons">
{% if pagination.page>1 %}
<a href="{{ path(pagination.route,
pagination.route_params|merge({'page': 1})) }}"><<</a>
<a href="{{ path(pagination.route,
pagination.route_params|merge({'page': pagination.page-1})) }}"><</a>
{% endif %}
{#display p numbers only from p-4 to p+4 but don't go <1 or >pages_count#}
{% for p in range(max(pagination.page-4, 1),
min(pagination.page+4, pagination.pages_count)) %}
<a{% if p == pagination.page %} class="current-page"{% endif %}
href="{{ path(pagination.route,
pagination.route_params|merge({'page': p})) }}">{{ p }}</a>
{% endfor %}
{% if pagination.page<pagination.pages_count %}
<a href="{{ path(pagination.route,
pagination.route_params|merge({'page': pagination.page+1})) }}">></a>
<a href="{{ path(pagination.route,
pagination.route_params|merge({'page': pagination.pages_count})) }}">>></a>
{% endif %}
</div>
</div>
EdiTransactionDetailRepository:
add a function with your field that you use in your table :
public function getPagedDocs($page = 1, $limit = 50)
{
$qb = $this->_em->createQueryBuilder()
->select('partial d.{field1,field2 , etc..},
partial et.{field1,field2, etc..}'
))//select doc fields and second partial for your join select edittransaction fields if you have other joins add another partial etc..
->from('YourBundle:DocsEntity', 'd')
->innerJoin('d.ediTransaction', 'et')//not sure which join you need i have no clue but i believe you will want an inner one since you will want a doc to have a ediTransaction because i didn't see any checks in your twig for it if null.
->setFirstResult(($page - 1) * $limit)
->setMaxResults($limit);
$paginator = new Paginator($qb, $fetchJoinCollection = false);//for more performance fetchjoincollection to false if you have joined tables
$paginator->setUseOutputWalkers(false);//for more performance set to false for more information http://www.doctrine-project.org/jira/browse/DDC-2890
return $paginator;
}
PS: Change limit to how many records you want to show in each page depending on the load of data you have make it lower if it is slow for 50 this is depend on how much data each row have.
Next the indexAction in your controller :
public function indexAction($page){
$em = $this->getDoctrine()->getManager();
$po = $em->getRepository('MatrixEdiBundle:EdiTransactionDetail')->getPagedDocs($page, 50);
$count = $po->count();
$pagination = array(
'page' => $page,
'route' => 'docs_index_route_name', //i dont know which name you have but it should be the route name of this indexAction
'route_params' => array()
);
if ($max_records > 0)
$pagination['pages_count'] = max(ceil($count / $max_records), 1);
return $this->render('MatrixEdiBundle:Matrix:index.html.twig', array('po' => $po,
'pagination' => $pagination
));
}
Routing:
You need to modify the route of your indexAction as we added a parameter page you need to add it for the route too :
index_docs:
pattern: /index/{page}
defaults: { _controller: "YourBundle:Controller:index", page: 1 }
NOTE : you will need to change the names and stuff i dont know you controller names and bundles so normally you will only need to add /{page} to the pattern and , page:1 to your _controller config which is the default value.
Last thing to do is your index.html.twig which need to include our pager.html.twig
include this piece of code after you close your table :
{% if po|length > 0 and pagination['pages_count'] is defined and pagination['pages_count'] > 0 %}
{#---------Pager----------#}
<div style="text-align:center;">
{% include 'YourBundle:EntityDoc:pager.html.twig' %}
</div>
{% endif %}
NOTE : The include is the path to the file where you create the pager.html.twig i assume you are familiar with how this works.
So if i didn't forget anything this should work out of the box , it should enhance greatly your performance but i am afraid that your render controller there for each row may still be problematic. But try this solution first and see, it depends what you put inside those controllers.

Categories