How I can grouping item in list, if I have different items with one ID?
I want if loop find two or more items with the same id combine them in to list ul > li.
For example:
{% extends 'base.html.twig' %}
{% block wrapper %}
<div class="panel panel-default">
<div class="panel-heading clearfix add">
Заявки
</div>
<table class="table">
<tr>
<th>ID</th>
<th>ID заявки</th>
<th>Склад</th>
<th>Матеріал</th>
<th>Кількість</th>
<th>Сумма</th>
<th>Дата</th>
<th>Час</th>
<th>Користувач</th>
</tr>
{% if itemEntries == null %}
<tr>
<td colspan="6">Елементи для показу відсутні</td>
</tr>
{% endif %}
{% for value in itemEntries %}
<tr>
<td>{{ value.id }}.</td>
<td>{{ value.bid }}</td>
<td>{{ value.storage.name }}</td>
<td>{{ value.item.name }} (ID: {{ value.item }})</td>
<td>{{ value.count }}</td>
<td>-{{ value.count * value.item.price }}</td>
<td>{{ value.date | date('d-m-Y') }}</td>
<td>{{ value.time | date('H:m:i') }}</td>
<td>{{ value.userLogin }}</td>
</tr>
{% endfor %}
</table>
</div>
{% endblock %}
Thanks!
The best way is to group the items in a SQL query.
So in you controller you should using groupBy() to grouping the result.
Look at this example:
$itemEntries = $this->em->createQueryBuilder()
->select('e')
->from('AppBundle:Entry', 'e')
->groupBy('e.bidId')
->getQuery()
->getResult();
Related
I am trying to iterate and print the text of the select element selected by the user. The key of the composite is item.
{% for item in data.item %}
<tr>
<td style="text-align: center;">{{ item.qty }} </td>
<td style="text-align: center;">{{ item.book }}</td>
</tr>
{% endfor %}
I know that item.book would only print the key. So how would I change it to print the text?
Help me guys, for this picture i want to disable view specific data from blade laravel this is the picture
https://i.stack.imgur.com/CuwB9.jpg
https://i.stack.imgur.com/NQfIc.jpg
this is my blade laravel file
<table class="table table-bordered table-responsive" style="margin-top: 20px">
<thead>
<tr>
<th>NO</th>
<th>NAMA</th>
<th>JABATAN</th>
<th>PROJECT</th>
<th>POSISI DALAM PROJECT</th>
<th>START PROJECT</th>
<th>FINISH PROJECT</th>
<th>DAYS PROJECT</th>
</tr>
</thead>
<tbody>
#php
$no = 1;
#endphp
#foreach ($data as $value)
<tr>
<td>{{ $no ++ }}</td>
<td>{{ $value->EMPLOYEE_NAME }}</td>
<td>{{ $value->EMPLOYEE_TITLE }}</td>
<td>{{ $value->PROJECT_NAME }}</td>
<td>{{ $value->PROJECT_ROLE }}</td>
<td>{{ $value->PROJECT_START }}</td>
<td>{{ $value->PROJECT_END }}</td>
<td>{{ $value->PROJECT_DURATION }}</td>
</tr>
#endforeach
</tbody>
</table>
and then controller to view $data
public function index(){
$data['data'] = DB::table('project')->join('employee','project.EMPLOYEE_ID','=','employee.EMPLOYEE_ID')
->select('EMPLOYEE_NAME' , 'EMPLOYEE_TITLE' , 'PROJECT_NAME' , 'PROJECT_ROLE' ,'PROJECT_START' , 'PROJECT_END' , 'PROJECT_DURATION')
->get();
return view('index',$data);
}
Help me guys... .
{% for item in product %}
<tr>
<td class="col-lg-5" > <h5> {{ item.tensp}}</h5></td>
<td class="col-lg-12"> {{ item.thanhphan}}</td>
<td class="col-lg-12"> {{ item.gia}}</td>
line 19 <td class="col-lg-12"> <img src="{{asset('/bundles/image/'{item.hinh})}}" alt=""/></td>
</tr>
{% endfor %}
I got this error message in Symfony Arguments must be separated by a comma. Unexpected token "punctuation" of value "{" ("punctuation" expected with value ",") in SP\findall.html.twig at line 19.
how can i fix it
Try concat string with ~ operator.
{% for item in product %}
<tr>
<td class="col-lg-5" ><h5> {{ item.tensp}}</h5></td>
<td class="col-lg-12">{{ item.thanhphan}}</td>
<td class="col-lg-12">{{ item.gia }}</td>
<td class="col-lg-12"><img src="{{ asset('/bundles/image/' ~ item.hinh)}}" alt=""/></td>
</tr>
{% endfor %}
I have a table with 10 rows and 10 columns with int values; I need the total to be print at 11th row, also i need to total and print at columns.
Example :
cell(1x11) = row1+row2+row3...row10;
cell(2x11) = row1+row2+row3...row10;
and
cell(11x1) = col1+col2+col3...col10;
cell(11x2) = col1+col2+col3...col10;
How can i do this easily.
Required result :
<table>
<tr>
<th></th>
<th>One</th>
<th>Two</th>
<th>Three</th>
<th>Total</th>
</tr>
<tr>
<td></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>6</td>
</tr>
<tr>
<td></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>6</td>
</tr>
<tr>
<td></td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>6</td>
</tr>
<tr>
<th>Total</th>
<td>3</td>
<td>6</td>
<td>9</td>
<td>18</td>
</tr>
</table>
My actual twig code:
`
{% set len = entities|length %}
{% set len_e = exams|length %}
{% if len_e != null and len_e is not empty and len_e > 0 %}
<div class="table-responsive">
<table id="FZUserExam" class="table table-striped table-bordered">
<thead>
<tr>
<th rowspan="2">SUBJECT</th>
<th rowspan="2">Max<br/>Marks</th>
{% for i in 1..len_e %}
{% if i == 1 %}
{% set terms = exams[0].term %}
{% set x = 1 %}
{% else %}
{% set name = exams[i-1].term %}
{% if name == terms %}
{% set x = x+1 %}
{% else %}
<th colspan="{{x+1}}">{{ terms }}</th>
{% set terms = exams[i-1].term %}
{% set x = 1 %}
{% endif %}
{% endif %}
{% if i == len_e %}
<th colspan="{{x+1}}">{{ terms }}</th>
{% endif %}
{% endfor %}
<th rowspan="2">Grand<br/>Total</th>
</tr>
<tr>
{% set terms = exams[0].term %}
{% set x = 1 %}
{% for i in 1..len_e %}
{% set name = exams[i-1].term %}
{% if name == terms %}
{% set x = x+1 %}
<th>{{ exams[i-1].exam }}</th>
{% else %}
<th>Total</th>
<th>{{ exams[i-1].exam }}</th>
{% set terms = exams[i-1].term %}
{% set x = 1 %}
{% endif %}
{% if i == len_e %}
<th>Total</th>
{% endif %}
{% endfor %}
</tr>
</thead>
<tbody>
{% set y = 0 %}
{% set total = 0 %}{% set gtotal = 0 %}
{% for a,s in subject %}
<tr>
<td>{{ s.name }}</td>
<td>{{ s.maxMarks }}</td>
{% set terms = exams[0].term %}
{% set x = 1 %}
{% for i in 1..len_e %}
{% set name = exams[i-1].term %}
{% if name == terms %}
{% set x = x+1 %}
{% if entities %}
{% if s.id == entities[y].subjects.id and entities[y].exams.id == exams[i-1].id %}
<td class="fz_t_e" data-val="{{ entities[y].marks }}" data-id="{{entities[y].id}}" data-exams="{{exams[i-1].id}}" data-student="{{student.id}}" data-subject="{{s.id}}">
{{ entities[y].marks }}
</td>
{% set total = total + entities[y].marks %}
{% if len > (y+1) %}
{% set y = y+1 %}
{% endif %}
{% else %}
<td class="fz_t_e" data-val="null" data-id="null" data-exams="{{exams[i-1].id}}" data-student="{{student.id}}" data-subject="{{s.id}}">-</td>
{% endif %}
{% else %}
<td class="fz_t_e" data-val="null" data-id="null" data-exams="{{exams[i-1].id}}" data-student="{{student.id}}" data-subject="{{s.id}}">-</td>
{% endif %}
{% else %}
<td>{{ total }}{% set gtotal = gtotal+total %}{% set total = 0 %}</td>
{% if entities %}
{% if s.id == entities[y].subjects.id and entities[y].exams.id == exams[i-1].id %}
<td class="fz_t_e" data-val="{{ entities[y].marks }}" data-id="{{entities[y].id}}" data-exams="{{exams[i-1].id}}" data-student="{{student.id}}" data-subject="{{s.id}}">
{{ entities[y].marks }}
</td>
{% set total = total + entities[y].marks %}
{% if len > (y+1) %}
{% set y = y+1 %}
{% endif %}
{% endif %}
{% else %}
<td class="fz_t_e" data-val="null" data-id="null" data-exams="{{exams[i-1].id}}" data-student="{{student.id}}" data-subject="{{s.id}}">-</td>
{% endif %}
{% set terms = exams[i-1].term %}
{% set x = 1 %}
{% endif %}
{% if i == len_e %}
<td>{{ total }}{% set gtotal = gtotal+total %}{% set total = 0 %}</td>
<td>{{ gtotal }}{% set gtotal = 0 %}</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
<tr class="totalColumn">
<td>Total</td>
{% for i in 1..len_e+4 %}
<td></td>
{% endfor %}
</tr>
{#<tr class="totalGrade">
<td>Grade</td>
{% for i in 1..len_e+4 %}
<td></td>
{% endfor %}
</tr>#}
</tbody>
</table>
</div>
{% else %}
<h3 class="text-center">Exam Table Not Updated</h3>
{% endif %}
</div>`
I don't know what data structure you're using to memorize your ints, but you could start with something like this:
<table>
{% for r in rows %}
<tr>
{% set rowTotal = 0 %}
{% for c in r.columns %}
{% set rowTotal = rowTotal + c.value %}
<td>{{ c.value }}</td>
{% endfor %}
<td>{{ rowTotal }}</td>
</tr>
{% endfor %}
</table>
Would anyone know the solution for the issue below?
Note: Symfony footer information bar (profiler) has the errors so system catches them. Template below belogs to FOSUserBundle.
When I use this (original) edit page, I can see the form validation errors in the page:
<form action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit">
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'profile.edit.submit'|trans }}" />
</div>
</form>
When I use this (modified) one, I cannot see the form validation errors in the page:
<form action="{{ path('fos_user_profile_edit') }}" {{ form_enctype(form) }} method="POST" class="fos_user_profile_edit">
<div>{{ form_errors(form) }}</div>
<table>
<tr>
<td>Username</td>
<td>{{ form_widget(form.username) }}</td>
</tr>
<tr>
<td>Email</td>
<td>{{ form_widget(form.email) }}</td>
</tr>
<tr>
<td>Current Password</td>
<td>{{ form_widget(form.current_password) }}</td>
</tr>
</table>
{{ form_widget(form._token) }}
<input type="submit" value="{{ 'profile.edit.submit'|trans }}" />
</form>
You can try setting error_bubbling in your form. According to the documentation:
If true, any errors for this field will be passed to the parent field or form. For example, if set to true on a normal field, any errors for that field will be attached to the main form, not to the specific field.
so if error_bubbling is set to false (by default) you should display error messages for specific fields like:
<tr>
<td>Username</td>
<td>{{ form_widget(form.username) }}</td>
<td>{{ form_errors(form.username) }}</td>
</tr>