Displaying an Entity in Symfony? - php

I was tasked of making a shift managing web app.
I have used OpenSkedge (an open-source web app).
One of my tasks is that each user should have a Skill Set.
I have added a functionality where you add these Skill Sets, and I have another view which displays information for the user.
User Controller:
/**
* Finds and displays a User entity.
*
* #param integer $id ID of user
*
* #return \Symfony\Component\HttpFoundation\Response
*/
public function viewAction($id)
{
$em = $this->getDoctrine()->getManager();
if (is_null($id)) {
$id = $this->getUser()->getId();
}
$entity = $em->getRepository('OpenSkedgeBundle:User')->find($id);
VarDumper::dump($entity);
if (!$entity instanceof User) {
throw $this->createNotFoundException('Unable to find User entity.');
}
$deleteForm = $this->createDeleteForm($id);
return $this->render('OpenSkedgeBundle:User:view.html.twig', array(
'entity' => $entity,
'skillset' => $entity->getSkillset(),
'delete_form' => $deleteForm->createView(),
));
}
SkillSet Entity:
<?php
// src/OpenSkedge/AppBundle/Entity/SkillSet.php
namespace OpenSkedge\AppBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\KeyValueStore\Mapping\Annotations as KeyValue;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* OpenSkedge\AppBundle\Entity\SkillSet
*
* #ORM\Table(name="os_skillset")
* #ORM\Entity
*/
class SkillSet
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #ORM\Column(type="string", length=100)
*/
private $skillSet;
/**
* #ORM\Column(type="string", length=100)
*/
private $skillNumber;
/**
* #ORM\ManyToOne(targetEntity="user", inversedBy="sset")
* #ORM\JoinColumn(name="id", referencedColumnName="id")
*/
private $user;
public function getSkillSet()
{
return $this->skillSet;
}
public function setSkillSet($s){
$this->skillSet = $s;
return $this;
}
public function getSkillnumber()
{
return $this->skillNumber;
}
public function setSkillnumber($nm){
$this->skillNumber = $nm;
return $this;
}
public function getUser(){
return $this->user;
}
public function setUser(\OpenSkedge\AppBundle\Entity\User $u = null){
$this->user = $u;
return $this;
}
}
View Form:
{% extends 'OpenSkedgeBundle:Dashboard:index.html.twig' %}
{% block title %}{{ app_brand_name() }} - {{ entity.name }}{% endblock %}
{% block modulecontent %}
<div class="span12">
<h3>{{ entity.name }}</h3>
{% if app.user.id == entity.id %}
<div class="btn-group header-control">
<a class="btn" href="{{ path('user_edit', { 'id': entity.id }) }}"><i class="icon-pencil"></i> Edit</a>
</div>
{% elseif is_granted('ROLE_ADMIN') %}
<form action="{{ path('user_delete', { 'id': entity.id }) }}" method="post">
<div class="btn-group header-control">
<a class="btn" href="{{ path('user_edit', { 'id': entity.id }) }}"><i class="icon-pencil"></i> Edit</a>
{% if app.user.id != entity.id and delete_form is defined %}
{{ form_widget(delete_form) }}
<button class="btn btn-danger" type="submit"><i class="icon-trash icon-white"></i> Delete</button>
{% endif %}
</div>
</form>
{% endif %}
<div class="btn-group header-control">
<a class="btn btn-info" href="{{ path('user_schedules', { 'id': entity.id }) }}">Schedules</a>
<a class="btn btn-info" href="{{ path('user_positions', { 'id': entity.id }) }}">Positions</a>
<a class="btn btn-info" href="{{ path('user_supervisors', { 'id': entity.id }) }}">Supervisors</a>
<a class="btn btn-info" href="{{ path('user_employees', { 'id': entity.id }) }}">Employees</a>
</div>
<table class="table table-condensed">
<tbody>
<tr>
<th>Username</th>
<td>{{ entity.username }}</td>
</tr>
<tr>
<th>Name</th>
<td>{{ entity.name }}</td>
</tr>
<tr>
<th>Role</th>
<td>{{ entity.group.name }}</td>
</tr>
{% if entity.workphone %}
<tr>
<th>Work Phone</th>
<td>{{ entity.workphone }}</td>
</tr>
{% endif %}
{% if entity.homephone %}
<tr>
<th>Home Phone</th>
<td>{{ entity.homephone }}</td>
</tr>
{% endif %}
{% if entity.location %}
<tr>
<th>Location</th>
<td>{{ entity.location }}</td>
</tr>
{% endif %}
<tr>
<th>Email</th>
<td>{{ entity.email }}</td>
</tr>
{% if entity.min %}
<tr>
<th>Minimum Hours</th>
<td>{{ entity.min }}</td>
</tr>
{% endif %}
{% if entity.max %}
<tr>
<th>Maximum Hours</th>
<td>{{ entity.max }}</td>
</tr>
{% endif %}
{% if entity.hours %}
<tr>
<th>Requested Hours</th>
<td>{{ entity.hours }}</td>
</tr>
{% endif %}
{% if entity.notes %}
<tr>
<th>Notes</th>
<td>{{ entity.notes }}</td>
</tr>
{% endif %}
{% if is_granted('ROLE_ADMIN') %}
{% if entity.supnotes %}
<tr>
<th>Supervisor Notes</th>
<td>{{ entity.supnotes }}</td>
</tr>
{% endif %}
{% endif %}
<tr>
<th>Color</th>
<td><span class="label" style="background-color: {{ entity.color }};">{{ entity.color }}</span></td>
</tr>
<tr>
<th>Active</th>
<td>{% if entity.isactive == 1 %}yes{% else %}no{% endif %}</td>
</tr>
</tbody>
</table>
<h3>Skillsets</h3>
<ul class="skillset">
{% for set in skillset %}
{% endfor %}
</ul>
</div>
{% endblock %}
The following shows a dump of a User Entity:
As you can see, the user has a set property which includes the Skill Sets which have been added in the new form.
However, the following doesn't display such skillsets in the page:
<h3>Skillsets</h3>
<ul class="skillset">
{% for set in skillset %}
{% endfor %}
</ul>
How can I solve this problem?

Related

symfony insert multiple rows insted of one

I have a wired situation here. On persisting symfony inserts multiple records instead of one. I can't find any problem with my code and I am not sure how to debug this error because it seems all fine.
Logic behind application is that user can select two bus station and create a route. Also he needs to define price and group (minimum and maximum people). Additionally, user needs to select bus vehicles that will drive this particular route
Does someone knows where is the problem?
Here is the output of entity when form is submitted
StationStandardPrice {#553 ▼
-id: null
-company: Company {#549 ▶}
-busVehicleGroupSize: BusVehicleGroupSize {#1233 ▶}
-departureStation: Stations {#1247 ▶}
-destinationStation: Stations {#1236 ▶}
-currency: Currencies {#1015 ▶ …2}
-price: 99.0
-busVehicles: ArrayCollection {#554 ▼
-elements: array:2 [▼
0 => BusVehicle {#1023 ▶}
1 => BusVehicle {#1208 ▶}
]
}
}
This is entity of route (shorted version)
/**
* #var integer
*
* #ORM\Column(name="id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* #var \AppBundle\Entity\Company
*
* #ORM\ManyToOne(targetEntity="Company")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="company_id", referencedColumnName="id")
* })
*/
private $company;
/**
* #var \AppBundle\Entity\BusVehicleGroupSize
*
* #ORM\ManyToOne(targetEntity="BusVehicleGroupSize")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="bus_vehicle_group_size_id", referencedColumnName="id")
* })
*/
private $busVehicleGroupSize;
/**
* #var \AppBundle\Entity\Stations
*
* #ORM\ManyToOne(targetEntity="Stations")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="departure_station_id", referencedColumnName="id")
* })
*/
private $departureStation;
/**
* #var \AppBundle\Entity\Stations
*
* #ORM\ManyToOne(targetEntity="Stations")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="destination_station_id", referencedColumnName="id")
* })
*/
private $destinationStation;
/**
* #var \AppBundle\Entity\Currencies
*
* #ORM\ManyToOne(targetEntity="Currencies")
* #ORM\JoinColumns({
* #ORM\JoinColumn(name="currency_id", referencedColumnName="id")
* })
*/
private $currency;
/**
* #var float
*
* #ORM\Column(name="price", type="decimal", precision=10, scale=2, nullable=false)
*/
private $price;
/**
* Many groups can have many bus vehicles
*
* #ORM\ManyToMany(targetEntity="BusVehicle", inversedBy="busVehicleGroup")
* #ORM\JoinTable(name="standard_station_price_bus_groups",
* joinColumns={#ORM\JoinColumn(name="station_standard_price_id", referencedColumnName="id")},
* inverseJoinColumns={#ORM\JoinColumn(name="bus_vehicle_id", referencedColumnName="id")}
* )
**/
private $busVehicles;
/**
* Add bus vehicle
* #param BusVehicle $busVehicles
*/
public function addBusVehicles(BusVehicle $busVehicles)
{
if ($this->busVehicles->contains($busVehicles)) {
return;
}
$this->busVehicles->add($busVehicles);
$busVehicles->addBusVehicleGroup($this);
}
/**
* Remove bus vehicle
* #param BusVehicle $busVehicles
*/
public function removeBusVehicles(BusVehicle $busVehicles)
{
if (!$this->busVehicles->contains($busVehicles)) {
return;
}
$this->busVehicles->remove($busVehicles);
$busVehicles->removeBusVehicleGroup($this);
}
Controller:
/**
* Creates a new stationStandardPrice entity.
* #Template
*/
public function newAction(Request $request)
{
$stationStandardPrice = new Stationstandardprice();
$form = $this->createForm(StationStandardPriceType::class, $stationStandardPrice, array(
'user' => $this->getUser()
)
);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
dump($stationStandardPrice);
$em = $this->getDoctrine()->getManager();
$em->persist($stationStandardPrice);
$em->flush();
$this->addFlash('success', 'admin.stationstandardprice.created');
//return $this->redirectToRoute('stationstandardprice_show', array('id' => $stationStandardPrice->getId()));
}
return [
'stationStandardPrice' => $stationStandardPrice,
'form' => $form->createView(),
];
}
Database output:
Many to Many table status:
EDIT 1: Added twig
{% extends 'AdminBundle::layout.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link href="{{ asset('resources/public/css/datatables.min.css', 'busrent_admin') }}" rel="stylesheet"/>
<link href="{{ asset('resources/public/css/smart_wizard.min.css', 'busrent_admin') }}" rel="stylesheet"/>
<link href="{{ asset('resources/public/css/smart_wizard_theme_dots.min.css', 'busrent_admin') }}" rel="stylesheet"/>
{% endblock %}
{% block title %} {{ 'admin.stationstandardprice.new.title'|trans }} {% endblock %}
{% block breadcrumb %}
<div class="col-lg-10">
<h2>{{ 'admin.stationstandardprice.new.title'|trans }}</h2>
<ol class="breadcrumb">
<li>
{{ 'admin.dashboard.index.title'|trans }}
</li>
<li>
{{ 'admin.stationstandardprice.index.title'|trans }}
</li>
<li class="active">
<strong>{{ 'admin.stationstandardprice.new.title'|trans }}</strong>
</li>
</ol>
</div>
<div class="col-lg-2">
</div>
{% endblock %}
{% block content %}
<div class="wrapper wrapper-content animated fadeInRight">
<div class="row">
<div class="col-lg-12">
<div class="ibox float-e-margins">
<div class="ibox-title">
<h5>{{ 'admin.stationstandardprice.new.title'|trans }}</h5>
<div class="ibox-tools">
<a class="collapse-link">
<i class="fa fa-chevron-up"></i>
</a>
</div>
</div>
<div class="ibox-content">
<div class="row">
<div class="col-lg-12">
{{ form_start(form) }}
<div id="smartwizard">
<ul>
<li><a href="#step-1">Step Title<br/>
<small>Step description</small>
</a>
</li>
<li><a href="#step-2">Step Title<br/>
<small>Step description</small>
</a>
</li>
<li><a href="#step-3">Step Title<br/>
<small>Step description</small>
</a>
</li>
</ul>
<div>
<div id="step-1" class="">
{{ form_row(form.departureStation) }}
{{ form_row(form.destinationStation) }}
</div>
<div id="step-2" class="">
{{ form_row(form.busVehicleGroupSize) }}
{{ form_row(form.price) }}
{{ form_row(form.currency) }}
</div>
<div id="step-3" class="">
{% if app.user.company is not null %}
<div class="ibox-content">
<table id="busVehicleTable" class="table table-striped">
<thead>
<tr>
<th>{{ 'admin.busvehicle.form.licencePlate'|trans }}</th>
<th>{{ 'admin.busvehicle.form.chassisNumber'|trans }}</th>
<th>{{ 'admin.busvehicle.form.passengerSeatsNumber'|trans }}</th>
<th>{{ 'admin.busvehicle.form.busType'|trans }}</th>
<th>{{ 'admin.busvehicle.form.emissionClass'|trans }}</th>
<th>{{ 'admin.busvehicle.form.fullDayPrice'|trans }}</th>
<th>{{ 'admin.busvehicle.form.halfDayPrice'|trans }}</th>
<th>{{ 'admin.busvehicle.form.pricePerKm'|trans }}</th>
<th>{{ 'admin.busvehicle.form.amenities'|trans }}</th>
<th>{{ 'actions'|trans }}</th>
</tr>
</thead>
<tbody>
{% set inc = 0 %}
{% for busVehicle in app.user.company.busVehicle %}
<tr>
<td>{{ busVehicle.licencePlate }}</td>
<td>{{ busVehicle.chassisNumber }}</td>
<td>{{ busVehicle.passengerSeatsNumber }}</td>
<td>{{ busVehicle.busType.type }}</td>
<td>{{ busVehicle.emissionClass.name }}</td>
<td>{{ busVehicle.fullDayPrice }}</td>
<td>{{ busVehicle.halfDayPrice }}</td>
<td>{{ busVehicle.pricePerKm }}</td>
<td>
<i style="cursor: pointer;" class="fa fa-search"
aria-hidden="true"
data-toggle="collapse"
data-target="#amenities{{ inc }}"></i>
</td>
<td>
<div id="addBusVehicleDiv{{ busVehicle.id }}">
<button data-id="{{ busVehicle.id }}" href="#"
class="addBusVehicle btn btn-primary btn-sm">
<i class="fa fa-plus"></i>
<span class="bold"> Add bus vehicle</span>
</button>
</div>
<div id="removeBusVehicleDiv{{ busVehicle.id }}"
style="display: none;">
<div id="removeBusVehicleDiv{{ busVehicle.id }}">
<button data-id="{{ busVehicle.id }}"
href="#"
class="removeBusVehicle btn btn-danger btn-sm">
<i class="fa fa-times"></i>
<span class="bold"> Remove bus vehicle</span>
</button>
</div>
</div>
</td>
</tr>
<tr id="amenities{{ inc }}" class="collapse">
<td>
>{{ 'admin.busvehicle.form.amenities'|trans }}:
</td>
<td>
<div>
<p>
{% for busAmenity in busVehicle.busVehiclesAmenities %}
{% if loop.last %}
{{ busAmenity.name }}
{% else %}
{{ busAmenity.name }},
{% endif %}
{% endfor %}
</p>
</div>
</td>
</tr>
{% set inc = inc + 1 %}
{% endfor %}
</tbody>
</table>
</div>
{% endif %}
</div>
</div>
</div>
{{ form_end(form) }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script src="{{ asset('resources/public/js/jquery.smartWizard.min.js', 'busrent_admin') }}"></script>
<script src="{{ asset('resources/public/js/busVehicleGroup.js', 'busrent_admin') }}"></script>
{% endblock %}
JS:
// Smart Wizard
$('#smartwizard').smartWizard({
selected: 0, // Initial selected step, 0 = first step
keyNavigation:true, // Enable/Disable keyboard navigation(left and right keys are used if enabled)
autoAdjustHeight:true, // Automatically adjust content height
cycleSteps: false, // Allows to cycle the navigation of steps
backButtonSupport: true, // Enable the back button support
showStepURLhash: true,
useURLhash: true, // Enable selection of the step based on url hash
lang: { // Language variables
next: 'Next',
previous: 'Previous'
},
toolbarSettings: {
toolbarPosition: 'bottom', // none, top, bottom, both
toolbarButtonPosition: 'right', // left, right
showNextButton: true, // show/hide a Next button
showPreviousButton: true, // show/hide a Previous button
toolbarExtraButtons: [
$('<button disabled id="finishForm" type="submit"></button>').text('Finish')
.addClass('btn btn-info')
]
},
anchorSettings: {
anchorClickable: false, // Enable/Disable anchor navigation
enableAllAnchors: false, // Activates all anchors clickable all times
markDoneStep: true, // add done css
enableAnchorOnDoneStep: true // Enable/Disable the done steps navigation
},
contentURL: null, // content url, Enables Ajax content loading. can set as data data-content-url on anchor
disabledSteps: [], // Array Steps disabled
errorSteps: [], // Highlight step with errors
theme: 'dots',
transitionEffect: 'fade', // Effect on navigation, none/slide/fade
transitionSpeed: '400'
});
$("#smartwizard").on("showStep", function(e, anchorObject, stepNumber, stepDirection) {
if (stepNumber == 2){
$('#finishForm').attr("disabled", false);
}
else{
$('#finishForm').attr("disabled", true);
}
});
the problem seems to be in:
public function addBusVehicles(BusVehicle $busVehicles)
{
if ($this->busVehicles->contains($busVehicles)) {
return;
}
$this->busVehicles->add($busVehicles);
$busVehicles->addBusVehicleGroup($this);
}
when call
$busVehicles->addBusVehicleGroup($this);
your are adding a new route to the relation, try without calling this method.

Doctrine - Create dynamical list in View

I am trying to create a view for display the total sales for all the suppliers and customers of a shop.
The total sales for a customer are easy to obtain, the problem is when I have to create the columns with the brands, I have been looking through this site, doctrine, etc, But I cannot find any solution.
SaleController.php
/**
* #Route("/widget/summarize")
*
* #return Render
*/
public function widgetSummarizeAction()
{
$suppliers = $this->getDoctrine()->getEntityManager()->createQueryBuilder()
->select(['su.name AS name'])
->from('AppBundle:Supplier', 'su')
->getQuery()
->getArrayResult()
;
$data = $this->getDoctrine()->getManager()->createQueryBuilder()->groupBy('c.name')
->select([
's.id AS id',
's.invoiceDate AS invoiceDate',
'c.name AS customer',
'SUM(ROUND(s.amount * s.price, 2)) AS totalSales',
'su.name AS supplier',
])
->from('AppBundle:Sale', 's')
->leftJoin('s.supplierCustomer', 'sc')
->leftJoin('sc.customer', 'c')
->leftJoin('sc.supplier', 'su')
->getQuery()
->getArrayResult()
;
return $this->render('AppBundle::home_widget.html.twig', [
'title' => 'Total Sales',
'icon' => 'money',
'urlList' => $this->generateUrl($this->getUrlList()),
'rowRoute' => $this->getUrlEdit(),
'data' => $data,
'columns' => [
'customer' => 'customer',
'totalSales' => 'Total Sales'
]
]);
home_widget.html.twig
<div class="panel panel-default home-widget">
<div class="panel-heading">
<h2 class="panel-title pull-left">
{% if icon is defined and icon is not empty %}<i class="fa fa-{{ icon }}"></i>{% endif %}
{{ title }}
</h2>
{% if urlList %}
<a class="btn btn-primary pull-right" href="{{ urlList }}">See All</a>
{% endif %}
<div class="clearfix"></div>
</div>
<div class="panel-body">
{% if data is not empty and data is iterable %}
<table class="table table-bordered table-striped">
<thead>
<tr>
{% for column in columns %}
<td>{{ column }}</td>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in data %}
{% set href = url(rowRoute, {'id': row.id}) %}
<tr>
{% for key,column in columns %}
<td>
<a href="{{ href }}">
{{ row[key] | raw }}
</a>
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
</div>
Maybe try get colulmns name by:
$em = $this->getDoctrine()->getManager();
$columns = $em->getClassMetadata(your_entity_name::class)->getFieldNames();
and loop through the columns in twig template.
<thead>
<tr>
{% for column in columns %}
<td>{{ column }}</td>
{% endfor %}
</tr>
</thead>

Count content of columns in table symfony2/twig/doctrine

So I have this table created with a crud in my symfony2 project. The table displays different products with each their own price. I would like to have a output with the total value of all products at the bottom of the table.
index.html.twig of entity "waarde"
{% extends '::base.html.twig' %}
{% block body -%}
<h1>Waarde voorraad</h1>
<table class="records_list">
<thead>
<tr>
<th>Product</th>
<th>Type</th>
<th>Fabriek</th>
<th>Aantal</th>
<th>Prijs</th>
<th>Inkoop Waarde</th>
<th>Verkoop Waarde</th>
<th>Locatie</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td>{{ entity.getProduct().getNaam() }}</td>
<td>{{ entity.getProduct().getType() }}</td>
<td>{{ entity.getProduct().getFabriek() }}</td>
<td>{{ entity.aantal }}</td>
<td>{{ entity.getProduct().getInkoopprijs() }}</td>
<td>{{ entity.getProduct().getInkoopprijs() * entity.aantal }}</td>
<td>{{ entity.getProduct().getVerkoopprijs() * entity.aantal }}</td>
<td>{{ entity.getLocatie().getLocatienaam() }}</td>
<td>
<ul>
<li>
show
</li>
<li>
edit
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('waarde_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock %}
I have a association between the entities "Product" and "Waarde"(=value).
<td>{{ entity.getProduct().getInkoopprijs() }}</td>
The code above returns the price of a product. I already have done a simple code to calculate the value of a single product by this code ("aantal" = quantity/amount of products)
<td>{{ entity.getProduct().getInkoopprijs() * entity.aantal }}</td>
{% set sum = 0 %}
{% for entity in entities %}
{% set sum = sum + (entity.getProduct().getInkoopprijs() * entity.aantal) %}
{% endfor %}
Total price: {{ sum }}

How can I order my table's columns using a keyword?

My column is currently {article, formation , tous article , tous formation, notif, offre}. I want to make it in this order {article, tous articles , espace&nbsp, formation , tous formation , &nbsp, notif , offre}
This is my code, the td is named: ban.page
<table id="liste-offresemploi" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th width="5">#</th>
<th>Titre 1</th>
<th>Type</th>
<th>Page</th>
<th>pagetest</th>
<th width="20">Statut</th>
<th>URL</th>
<th width="5"></th>
<th width="5" class="header"></th>
</tr>
</thead>
<tbody>
{% if nb_bannieres > 0 %}
{% for bann in bannieres %}
<tr>
<td>{{ bann.idbanniereinterne }}</td>
<td>{{ bann.titre }}</td>
<td>{% if bann.type == 2 %} Publicité {% else %} {% if bann.type == 1 %} Structure {% endif %} {% endif %}</td>
<td id="tri">{{bann.page }}</td>
<td>{% if bann.page == "articles" %} 0 {% else %} {% if bann.page == "toutarticles" %} 1 {% endif %} {% endif %} </td>
<td><a href="#?" class="toogleactif" name="banniereinterne-{{ bann.idbanniereinterne }}" rel="{% if bann.actif %}0{% else %}1{% endif %}">
{% if bann.actif %}
<button class="btn btn-success actifjs">Actif</button>
{% else %}
<button class="btn btn-warning actifjs">Non Actif</button>
{% endif %}
</a>
</td>
<td>{{ bann.url }}</td>
<td><span class="glyphicon glyphicon-edit btnadmin btnedit" title="Editer" rel="table_banniereinterne|id_{{ bann.idbanniereinterne }}"></span></td>
<td><span class="glyphicon glyphicon-trash btnadmin deladmin" title="Supprimer" rel="{{ bann.idbanniereinterne }}|banniereinterne|0"></span></td>
</tr>
An easy solution is to add in your entity a field order (type int) and give the order value
Category | Order
------------ | ------
article | 2
formation | 3
tous article | 1
And then order in your query by this Order column ASC and you will get
tous article
article
formation

Twig template extend ignored

I have 2 Entities: Clinic, Vet, for which I created CRUD templates with app/console generate:doctrine:crud
I first created the Clinic entity and created my "admin template" in AgriHealth/AhpBundle/Resources/views/admin.html.twig and then extend this in
AgriHealth/AhpBundle/Resources/views/Clinic/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
This worked.
Then I created Entity Vet and ran the crud generator. Again I'm extending:
AgriHealth/AhpBundle/Resources/views/Vet/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
But this seems to be ignored, as the layout from my admin template doesn't come through. I have tried:
app/console cache:clear
renaming admin.html.twig: causes an error in both views as expected
I must be missing something? Any ideas?
Twig code below:
src/AgriHealth/AhpBundle/Resources/views/admin.html.twig
{% extends '::base.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link href="{{ asset('bundles/agrihealthahp/css/admin.css') }}" rel="stylesheet" />
<link href="{{ asset('bundles/agrihealthsecurity/css/admin.css') }}" rel="stylesheet" />
{% endblock %}
{% block body -%}
<div class="row" id="header">
<div class="small-12 columns">
<h1><a href=""><img src="/bundles/agrihealthahp/images/agrihealth-logo.png" />
<span>Animal Health Planner</span></a></h1>
</div>
</div>
<div class="row" id="menu">
<div class="small-12 columns">
</div>
</div>
<div class="row" id="content">
<div class="small-12 columns">
{% block admin %}{% endblock %}
</div>
</div>
<div class="row" id="black_footer">
<div class="small-12 medium-5 columns footer-black-1">
<div class="moduletable">
<div class="custom">
<p>www.agrihealth.co.nz</p></div>
</div>
</div>
<div class="small-12 medium-7 columns ">
<div class="left footer-black-2">
<div class="moduletable">
<div class="custom">
<p>0800 821 421</p></div>
</div>
</div>
<div class="right footer-black-3">
<div class="moduletable">
<div class="custom">
<p><sup></sup><sup><img style="line-height: 1.1;" src="/bundles/agrihealthahp/images/agrihealth_white.png" alt="agrihealth white"></sup></p></div>
</div>
</div>
</div>
</div>
{% endblock %}
src/AgriHealth/AhpBundle/Resources/views/Clinic/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
{% block admin -%}
<h1>Clinics</h1>
<ul class="actions">
<li>
<a href="{{ path('clinic_new') }}">
Add Clinic
</a>
</li>
</ul>
<table class="records_list">
<thead>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Fax</th>
<th>After Hours</th>
<th>Email</th>
<th></th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td>{{ entity.name }}</td>
<td>{{ entity.phone }}</td>
<td>{{ entity.fax }}</td>
<td>{{ entity.afterhours }}</td>
<td>{{ entity.email }}</td>
<td>
<ul class="actions">
<li>
edit
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
src/AgriHealth/AhpBundle/Resources/views/Vet/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
{% block body -%}
<h1>Vets</h1>
<ul class="actions">
<li>
<a href="{{ path('vet_new') }}">
Add Vet
</a>
</li>
</ul>
<table class="records_list">
<thead>
<tr>
<th>Name</th>
<th>Mobile</th>
<th>Clinic</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('vet_edit', { 'id': entity.id }) }}">{{ entity.firstname }} {{ entity.lastname }}</td>
<td>{{ entity.mobile }}</td>
<td>{{ entity.clinic }}</td>
<td>
<ul class="actions">
<li>
edit
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
Check the source of the page for the stylesheets included in admin.html.twig.
If they are there, the problem is that you are overriding your body block.
Change
src/AgriHealth/AhpBundle/Resources/views/Vet/index.html.twig:
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
{% block body -%}
to
{% extends 'AgriHealthAhpBundle::admin.html.twig' %}
{% block admin -%}
If your stylesheets are not in the page there must be another problem .

Categories