How to add action columns in yajra datatables laravel - laravel

im stuck adding column actions for edit and delete button with yajra datatables, im using DataTables Service because im wanna add export button too, here is my my datatables code :
public function dataTable($query)
{
return datatables()
->eloquent($query);
}
/**
* Get query source of dataTable.
*
* #param \App\InfoDataTable $model
* #return \Illuminate\Database\Eloquent\Builder
*/
public function query(InfoDataTable $model)
{
// return $model->newQuery();
$data = DataInfo::select('data-info.*');
return $this->applyScopes($data);
}
/**
* Optional method if you want to use html builder.
*
* #return \Yajra\DataTables\Html\Builder
*/
public function html()
{
return $this->builder()
->columns($this->getColumns())
->addAction()
->parameters([
'dom' => 'Bfrtip',
'buttons' => ['csv', 'excel', 'print'],
]);
}
/**
* Get columns.
*
* #return array
*/
protected function getColumns()
{
return [
Column::make('employee_no'),
Column::make('name'),
Column::make('address'),
Column::make('birthplace'),
Column::make('birthdate'),
Column::make('age'),
Column::make('occupation'),
Column::make('status'),
Column::make('gender'),
Column::make('startdate'),
];
}
and here is my code in my controller for rendering the table
public function index(InfoDataTable $dataTable)
{
$User = User::where('id', Auth::id())->first();
if($User->role == 'superadmin'){
return $dataTable->render('superadmin.index');
} else {
return $dataTable->render('admin.index');
}
}
and my blade looks like this
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="card">
<div class="card-header">Dashboard</div>
<div class="card-body">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
</div>
<div class="card-body">
<div class="table-responsive">
<div class="panel panel-default">
{{(!! $dataTable->table() !!)}}
</div>
</div>
</div>
</div>
</div>
</div>
#stop
#push('scripts')
{!! $dataTable->scripts() !!}
#endpush
my current view looks like this
any suggestions? sorry for my broken english, tried many tutorial but can't find the correct one

Actions column is default for yajra datatables. So I found how to remove it: https://yajrabox.com/docs/laravel-datatables/6.0/remove-column (I have never tried this)
public function dataTable($query)
{
return datatables()
->eloquent($query)
->removeColumn('action');
}
If you want to edit actions column, try my code:
public function dataTable($query)
{
$dataTable = new EloquentDataTable($query);
return $dataTable->addColumn('action', 'folderNameInViewfolder.datatables_actions');
}
This is what in datatables_actions (full name: datatables_actions.blade.php)
{!! Form::open(['route' => ['routename.destroy', $id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{{ route('routename.show', $id) }}" class='btn btn-default btn-xs'>
<i class="glyphicon glyphicon-eye-open"></i>
</a>
<a href="{{ route('routename.edit', $id) }}" class='btn btn-default btn-xs'>
<i class="glyphicon glyphicon-edit"></i>
</a>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', [
'type' => 'submit',
'class' => 'btn btn-danger btn-xs',
'onclick' => "return confirm('Are you sure?')"
]) !!}
</div>
{!! Form::close() !!}
My code is different from yours, so I will show my code:
Datatables code:
public function dataTable($query)
{
$dataTable = new EloquentDataTable($query);
return $dataTable->addColumn('action', 'cachthuclamviecs.datatables_actions');
}
/**
* Get query source of dataTable.
*
* #param \App\Models\Cachthuclamviec $model
* #return \Illuminate\Database\Eloquent\Builder
*/
public function query(Cachthuclamviec $model)
{
return $model->newQuery();
}
/**
* Optional method if you want to use html builder.
*
* #return \Yajra\DataTables\Html\Builder
*/
public function html()
{
return $this->builder()
->columns($this->getColumns())
->minifiedAjax()
->addAction(['width' => '120px', 'printable' => false])
->parameters([
'dom' => 'Bfrtip',
'stateSave' => true,
'order' => [[0, 'desc']],
'buttons' => [
['extend' => 'create', 'className' => 'btn btn-default btn-sm no-corner', 'text' => '<span><i class="fa fa-plus"></i> Thêm</span>'],
['extend' => 'export', 'className' => 'btn btn-default btn-sm no-corner', 'text' => '<span><i class="fa fa-download"></i> Xuất <span class="caret"></span></span>'],
['extend' => 'print', 'className' => 'btn btn-default btn-sm no-corner', 'text' => '<span><i class="fa fa-print"></i> In</span>'],
['extend' => 'reset', 'className' => 'btn btn-default btn-sm no-corner', 'text' => '<span><i class="fa fa-undo"></i> Cài lại</span>'],
['extend' => 'reload', 'className' => 'btn btn-default btn-sm no-corner', 'text' => '<span><i class="fa fa-refresh"></i> Tải lại</span>'],
],
]);
}
/**
* Get columns.
*
* #return array
*/
protected function getColumns()
{
return [
'cachthuclamviec'
];
}
Controller code:
public function index(CachthuclamviecDataTable $cachthuclamviecDataTable)
{
return $cachthuclamviecDataTable->render('cachthuclamviecs.index');
}
Blade code:
#section('css')
#include('layouts.datatables_css')
#endsection
{!! $dataTable->table(['width' => '100%', 'class' => 'table table-striped table-bordered']) !!}
#push('scripts')
#include('layouts.datatables_js')
{!! $dataTable->scripts() !!}
#endpush
datatables_actions blade code:
{!! Form::open(['route' => ['cachthuclamviecs.destroy', $id], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{{ route('cachthuclamviecs.show', $id) }}" class='btn btn-default btn-xs'>
<i class="glyphicon glyphicon-eye-open"></i>
</a>
<a href="{{ route('cachthuclamviecs.edit', $id) }}" class='btn btn-default btn-xs'>
<i class="glyphicon glyphicon-edit"></i>
</a>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', [
'type' => 'submit',
'class' => 'btn btn-danger btn-xs',
'onclick' => "return confirm('Are you sure?')"
]) !!}
</div>
{!! Form::close() !!}
Put file datatables_actions here: datatables_actions:
Code maybe have differences because of Boostrap, jQuery,... version

Related

Why update picture doesn't detect file uploaded?

I am using laravel 5 to create an edit form for a profile and can update picture in the form.
I want to store a new image in edit form. I use this code in edit.blade to get the image by user.
View:
{!! Form::model($dataItemregistration,['method' => 'PATCH', 'action' => ['Modul\ProfilController#update', $dataItemregistration->ItemRegistrationID, 'files' => true] ]) !!}
<div class="form-group">
<div class="row">
<div class="col-lg-3">
{{ Form::label('pic', 'Gambar (Saiz gambar, 250x300px)') }}
</div>
<div class="col-lg-7">
{!! Form::file('gambar', array('class' => 'form-control')) !!}
</div>
</div>
</div>
<br>
<div class="col-lg-10 text-center">
{!! link_to(URL::previous(),'Back', ['class' => 'btn btn-warning btn-md']) !!}
{{ Form::submit('Update', ['class' => 'btn btn-primary']) }}
</div>
{!! Form::close() !!}
Controller:
public function update(Request $request, $id)
{
$valueitemregistrations = Itemregistration::find($id);
$this->validate($request,['gambar' => 'max:100000',]);
if ($request->hasFile('gambar')) {
// Get the file from the request
$file = $request->file('gambar');
// Get the contents of the file
$content = $file->openFile()->fread($file->getSize());
$valueitemregistrations->Picture = $content;
$valueitemregistrations->update();
if($valueitemregistrations) {
return redirect('profil');
} else {
return redirect()->back()->withInput();
}
} else {
echo "testing";
}
}
When I try to upload and update, it goes to echo "testing". It doesn't detected any files uploaded..
I had been using the same code for add.blade and it works.
Is it related to route path or else?
This happens when your HTML form doesn't have enctype="multipart/form-data".
In this case the cause is 'files' => true being part of the wrong array inside Form::model(); it's inside the 'action' array when it should be outside. Try this:
Form::model($dataItemregistration, [
'method' => 'PATCH',
'action' => ['Modul\ProfilController#update', $dataItemregistration->ItemRegistrationID],
'files' => true,
]);

storing data with name of author - laravel 5.2

I have hasMany relation to my model user and reports.
I want to set author name for the reports. (Like a blog-post author)
my model User:
public function reports() {
return $this->hasMany('App\Report', 'author_id');
}
model Report
public function user() {
return $this->belongsTo('App\User', 'author_id');
}
and my controller:
public function create()
{
$category = Category::lists('title','id');
return view('dash.reports.create')->with('category', $category);
}
/**
* Store a newly created resource in storage.
*
* #return void
*/
public function store(Request $request)
{
$this->validate($request, ['title' => 'required', ]);
Report::create($request->all());
Session::flash('flash_message', 'Report added!');
return redirect('dash/reports');
}
I'm able to set in in phpmyadmin, but how can i set it with my controller?
edit: my view:
{!! Form::open(['url' => '/dash/reports', 'class' => 'form-horizontal']) !!}
<div class="form-group {{ $errors->has('title') ? 'has-error' : ''}}">
{!! Form::label('title', 'Servizio', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('title', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('title', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('title') ? 'has-error' : ''}}">
{!! Form::label('date', 'Data lavorativa', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-2">
{!! Form::selectRange('day', 1, 31, null, ['class' => 'form-control']) !!}
{!! $errors->first('day', '<p class="help-block">:message</p>') !!}
</div>
<div class="col-sm-2">
{!! Form::selectMonth('month', null, ['class' => 'form-control']) !!}
{!! $errors->first('month', '<p class="help-block">:message</p>') !!}
</div>
<div class="col-sm-2">
{!! Form::select('year', array('2016' => '2016', '2015' => '2015'), null, ['class' => 'form-control']) !!}
{!! $errors->first('year', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('category_id') ? 'has-error' : ''}}">
{!! Form::label('category_id', 'Cliente', ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::select('category_id', $category, null, ['class' => 'form-control'] ) !!}
{!! $errors->first('category_id', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
{!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!}
</div>
</div>
{!! Form::close() !!}
Very easy. Replace Report::create... with this.
$user = Auth::user();
$report = new Report($request->all());
$report->author()->associate($user);
$report->save();
Make sure you use Auth; up at the top.
This uses the Auth object to get the current user,
Builds a new Report using the $request data without saving,
Tells the report we're associating $user as the author for the model,
Saves the report with the authorship information.
solution:
public function store(Request $request)
{
$this->validate($request, ['title' => 'required', ]);
$user = Auth::user()->id;
$report = new Report($request->all());
$report->author_id = $user;
$report->save();
Session::flash('flash_message', 'Report added!');
return redirect('dash/reports');
}

Laravel 5.2 login issue

Strange issue, when I use the default register route, and I create a user, I can enter inside my app, everything ok. But if I use my CRUD, or the MySQL command for create the user, I can't login.
These credentials do not match our records. (sorry for bad english, I attach the image)
Andrea and Raffaello can login (create with register default route)
Marino can't (generate with my CRUD function) but appear 3 identical records..
routes.php :
Route::group(['middleware' => ['web']], function () {
Route::resource('dash/reports', 'Dash\\ReportsController');
});
/* ruote for Admin */
Route::group(['middleware' => ['role:admin']], function () {
Route::resource('dash/categories', 'Dash\\CategoriesController');
});
Route::group(['middleware' => ['role:admin']], function () {
Route::resource('dash/roles', 'Dash\\RolesController');
});
Route::group(['middleware' => ['role:admin']], function () {
Route::resource('dash/permissions', 'Dash\\PermissionsController');
});
Route::group(['middleware' => ['role:admin']], function () {
Route::resource('dash/users', 'Dash\\UsersController');
});
/* another routes */
Route::auth();
Route::get('/home', 'HomeController#index');
Route::get('/', function () {return view('welcome');});
Controller (custom CRUD operation)
<?php
namespace App\Http\Controllers\Dash;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Auth;
use App\User;
use App\Report;
use App\Category;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Session;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class UsersController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Display a listing of the resource.
*
* #return void
*/
public function index()
{
$users = User::paginate(15);
return view('dash.users.index', compact('users'));
}
/**
* Show the form for creating a new resource.
*
* #return void
*/
public function create()
{
return view('dash.users.create');
}
/**
* Store a newly created resource in storage.
*
* #return void
*/
public function store(Request $request)
{
$this->validate($request, ['email' => 'required', 'name' => 'required', 'password' => 'required', 'surname' => 'required', ]);
$user = new User($request->all());
$user->password = bcrypt($request);
$user->save();
return redirect('dash/users');
}
/**
* Display the specified resource.
*
* #param int $id
*
* #return void
*/
public function show($id)
{
$user = User::findOrFail($id);
return view('dash.users.show', compact('user'));
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
*
* #return void
*/
public function edit($id)
{
$user = User::findOrFail($id);
return view('dash.users.edit', compact('user'));
}
/**
* Update the specified resource in storage.
*
* #param int $id
*
* #return void
*/
public function update($id, Request $request)
{
$this->validate($request, ['email' => 'required', 'name' => 'required', 'password' => 'required', 'surname' => 'required', ]);
$user = User::findOrFail($id);
$user->update($request->all());
Session::flash('flash_message', 'User updated!');
return redirect('dash/users');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
*
* #return void
*/
public function destroy($id)
{
User::destroy($id);
Session::flash('flash_message', 'User deleted!');
return redirect('dash/users');
}
}
view:
#extends('layouts.app')
#section('content')
<div class="container">
<h1>Create New User</h1>
<hr/>
{!! Form::open(['url' => '/dash/users', 'class' => 'form-horizontal']) !!}
<div class="form-group {{ $errors->has('email') ? 'has-error' : ''}}">
{!! Form::label('email', trans('users.email'), ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('email', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('email', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('name') ? 'has-error' : ''}}">
{!! Form::label('name', trans('users.name'), ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('name', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('name', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('password') ? 'has-error' : ''}}">
{!! Form::label('password', trans('users.password'), ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('password', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('password', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('surname') ? 'has-error' : ''}}">
{!! Form::label('surname', trans('users.surname'), ['class' => 'col-sm-3 control-label']) !!}
<div class="col-sm-6">
{!! Form::text('surname', null, ['class' => 'form-control', 'required' => 'required']) !!}
{!! $errors->first('surname', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
{!! Form::submit('Create', ['class' => 'btn btn-primary form-control']) !!}
</div>
</div>
{!! Form::close() !!}
#if ($errors->any())
<ul class="alert alert-danger">
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
#endif
</div>
#endsection
also my custon postLogin() in AuthController for try to overlap default postLogin() - but not working
public function postLogin(LoginRequest $request)
{
if (Auth::attempt(['email' => $request->input('email'), 'password' => $request->input('password')]))
{
return redirect('/dash-board');
}
return redirect('/login')->withErrors([
'email' => 'The credentials you entered did not match our records. Riprovare?',
]);
}
there is it
you need to specify the data you get from $request
you are storing password not correctly
change this :
$user = new User($request->all());
$user->password = bcrypt($request);
$user->save();
to this :
$user = new User($request->all());
$user->password = bcrypt($request->pwInputName);
$user->save();
pwInputName : is the password input name in your view
the issue was that you bcrypt all of $request

Laravel 5 MethodNotAllowedHttpException issues

I am trying to make a simple CRUD for Clients. At the moment I can view clients and get to the edit page. However, if I try to update or create a client, I get a MethodNotAllowedHttpException.
My routes look like the following
Route::model('clients', 'Client');
Route::bind('clients', function($value, $route) {
return App\Client::whereSlug($value)->first();
});
Route::resource('clients', 'ClientsController');
My controller is like so
<?php
namespace App\Http\Controllers;
use App\Client;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Input;
use Redirect;
use Illuminate\Http\Request;
class ClientsController extends Controller {
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
$clients = Client::all();
return view('clients.index', compact('clients'));
}
/**
* Show the form for creating a new resource.
*
* #return Response
*/
public function create()
{
return view('clients.create');
}
/**
* Store a newly created resource in storage.
*
* #return Response
*/
public function store()
{
$input = Input::all();
Client::create( $input );
return Redirect::route('clients.index')->with('message', 'Client created');
}
/**
* Show the form for editing the specified resource.
*
* #param \App\Client $client
* #return Response
*/
public function edit(Client $client)
{
return view('clients.edit', compact('client'));
}
/**
* Update the specified resource in storage.
*
* #param \App\Client $client
* #return Response
*/
public function update(Client $client)
{
$input = array_except(Input::all(), '_method');
$client->update($input);
return Redirect::route('clients.index', $client->slug)->with('message', 'Client updated.');
}
/**
* Remove the specified resource from storage.
*
* #param \App\Client $client
* #return Response
*/
public function destroy(Client $client)
{
$client->delete();
return Redirect::route('clients.index')->with('message', 'Client deleted.');
}
}
I then have a form partial like so
<div class="form-group">
{!! Form::label('clientName', 'Client Name:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('clientName', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('contactEmail', 'Contact Email:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('contactEmail', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('slug', 'Slug:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('slug', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::submit($submit_text, ['class'=>'btn btn-default']) !!}
</div>
And my edit.blade.php is like so
<h2>Edit Client</h2>
{!! Form::model($client, ['class'=>'form-horizontal'], ['method' => 'PATCH', 'route' => ['clients.update', $client->slug]]) !!}
#include('clients/partials/_form', ['submit_text' => 'Edit Client'])
{!! Form::close() !!}
I have researched this error and a lot of people refer to javascript, but I am not using any javascript at the moment.
Why would I be getting this error? As I say, I get it when I try to create a client as well.
Thanks
As an update, if I remove the form partial and add this to ed.it.blade.php instead, it seems to work
{!! Form::model($client, [
'method' => 'PATCH',
'route' => ['clients.update', $client->slug]
]) !!}
<div class="form-group">
{!! Form::label('clientName', 'Client Name:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('clientName', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('contactEmail', 'Contact Email:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('contactEmail', null, array('class' => 'form-control')) !!}
</div>
</div>
<div class="form-group">
{!! Form::label('slug', 'Slug:', array('class' => 'col-sm-5 control-label blue')) !!}
<div class="col-sm-7">
{!! Form::text('slug', null, array('class' => 'form-control')) !!}
</div>
</div>
{!! Form::submit('Update Client', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
Why is that?

symfony2 update entity out of modal

almost whole night I'm trying to update an entity with a form in a modal, but it doesn't work...
My twig template looks like :
{% for entity in entities %}
<tr>
<td class="text-center">{{ entity.id }}</td>
<td class="text-center">{{ entity.cashbackDays }} Tage</td>
<td class="text-center">{{ entity.cashbackPercent }} %</td>
<td class="text-center">{{ entity.nettoDays }} Tage</td>
<td class="text-center">
<a data-toggle="modal" data-target="#editCashbackModal" class="btn btn-xs btn-default" href="{{ path('cashback_edit', { 'id': entity.id }) }}"><i
class="fa fa-edit"></i></a>
</td>
</tr>
{% endfor %}
</tbody>
<div class="modal fade" id="editCashBackModal" tabindex="-1" role="dialog" aria-labelledby="editCashBackModalLabel" aria-hidden="true">
</div>
the modal template looks like:
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">×</span></button>
<h4 class="modal-title" id="editCashBackModalLabel">Skontoschlüssel bearbeiten</h4>
</div>
<div class="modal-body">
{{ form(edit_form) }}
<ul class="record_actions">
<li>
<a href="{{ path('cashback') }}">
Back to the list
</a>
</li>
<li>{{ form(delete_form) }}</li>
</ul>
</div>
<div class="modal-footer">
</div>
</div>
</div>
I think I got problems with the variable in the URl but I don't know how to fix it.
This is the part of my controller:
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('sulzerAppBundle:Cashback')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Cashback entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Creates a form to edit a Cashback entity.
*
* #param Cashback $entity The entity
*
* #return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Cashback $entity)
{
$form = $this->createForm(new CashbackType(), $entity, array(
'action' => $this->generateUrl('cashback_update', array('id' => $entity->getId())),
'method' => 'PUT',
));
$form->add('submit', 'submit', array('label' => 'Update'));
return $form;
}
The Error is that the modal doesn't open at click on edit
You have to add form submission:
protected $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('sulzerAppBundle:Cashback')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Cashback entity.');
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
$editForm->handleRequest($this->requestStack);
if ($editForm->isSubmitted() && $editForm->isValid()) {
/** #var Cashback $cashback */
$cashback = $editForm->getData();
...
$em->persist($cashback);
$em->flush();
}
...
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
Read more about forms and symfony 2.7 demo

Resources