I have two tables branch and roadname each branch have many roadnames. I need to add this roadname on the selected branch. One branch can have multiple roads. I am not able to insert the values please guide me through.
Table branch:
enter image description here
Roadname
enter image description here
Here is my code:
Blade
#section('content');
<div class="content-wrapper">
<form id="roadnames" action="{{route('addroad',[$branch[0]->id])}}" method="POST">
<input type = "hidden" name = "_token" value = "<?php echo csrf_token(); ?>">
<table id ="add">
<tr>
<thead>
<th>RoadName</th>
</thead>
</tr>
<tbody>
<tr>
<td><input type="text" class="form-control" name="roads[]" id="road"></td>
</tr>
</tbody>
</table>
<button id="add_road" class="btn btn-primary"> Add More</button>
<input type="submit" name="submit" class="submit action-button" value="Submit"/>
</form>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#add_road").on("click", function(){
$('#add tr:last').clone().appendTo('#add');
});
});
</script>
#endsection
Controller
public function addroads(Request $request,$id)
{
$resultset = DB::select('select * from table_branch where id = ?',[$id]);
$roadname = $request->input('roads');
$branch_id = $id;
$arr = array($roadname,$branch_id);
if(DB::table('roadname')->insert($arr))
{
echo "Records inserted";
}
else
{
echo "Records not inserted";
}
return view('addroads',array('branch'=>$resultset));
}
Routes
Route::get('/admin/road/addrecord/{id}', '\App\Http\Controllers\AdminController#addroads')->name('addroad');
I suggest you to create models for each table using php artisan command.Models help you to write relationship and keep your code clean ,also it will quicker compare to db queries
For example php artisan make:model Branch
Branch Model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Branch extends Model
{
use HasFactory;
protected $table="table_branch";
protected $guarded=['id'];
public function roadName(){
return $this->hasMany(RoadName::class);
}
}
RoadName model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class RoadName extends Model
{
use HasFactory;
protected $table="roadname";
protected $guarded=['id'];
}
In your controller
$branch=\App\Models\Branch::query()->find($id);
$roadName=[];
if(isset($request->roads)&&count($request->roads)){
foreach ($request->roads as $value){
$roadName[]=new \App\Models\RoadName(['roadname' => $value]);
}
$branch->roadName()->saveMany($roadName);
}
Note: this created using laravel 8.
You can learn more about in official documentation
Ref:https://laravel.com/docs/8.x/eloquent-relationships#one-to-many
Related
So I'm trying to figure out how to make this work I have a Leave Application(which is currently just a form that stores the data) which is supposed to remove the "Days Granted" like Annual Leaves or Sick Leaves based on the dates from them for example "from 27/08/2020" and "to 30/08/2020" which is 3 days I want to get those numbers from between the dates and in the user table on the leave_days_granted field(which always has default value 20) to remove it from there so leave_days_granted - 3 = 17 something like this so I can display it on the view how many that user has left
I have added this in the user model
class User
{
public function leaveBalance()
{
$daysUsed = $this->leaves->map->numberOfDays()->sum();
return $this->leave_days_granted - $daysUsed;
}
// You can also add a helper to make your controller more readable.
public function hasAvailableLeave()
{
return $this->leaveBalance() > 0;
}
public function leaves()
{
return $this->hasMany(\App\Leave::class);
}
}
And this is added in the Leave Model
class Leave
{
protected $dates = ['from', 'to'];
public function numberOfDays()
{
return $this->from->diffInDays($to);
}
}
So here I don't get why this isn't working it's not changing anything in the database when I request a leave and I'm not sure now if I'm supposed to add something more on the Leave controller to call this or the View of the Leave
This is how I get the dates on the view
<div class="card-body">
<form method="POST" action="{{route('leaves.store')}}">
#csrf
<div class="form-group">
<label>From Date</label>
<div class="col-md-6">
<input class="datepicker" type="text" class="form-control #error('from') is-invalid #enderror" name="from" required="">
#error('from')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group">
<label>To Date</label>
<div class="col-md-6">
<input class="datepicker1" type="text" class="form-control #error('to') is-invalid #enderror" name="to" required="">
This is the form link This is the users table link This is the leaves table link
This is the LeaveController
public function index()
{
if(Auth::guard('admin')->check())
{
$users = User::all();
$leaves = Leave::latest()->paginate(5);
return view('admin/leave/index', compact('leaves'),compact('users'));
}
$role = Auth::guard('web')->user()->role_id;
if($role == 1)
{
return view('unauthorized');
}
else
{
$leaves = Leave::latest()->paginate(5);
return view('admin/leave/index', compact('leaves'));
}
}
public function create()
{
$leaves = Leave::latest()->where('user_id',auth()->user()->id)->paginate(5);
return view('leave.create',compact('leaves'));
}
public function store(Request $request)
{
$this->validate($request,[
'from'=>'required',
'to'=>'required',
'description'=>'required',
'type'=>'required'
]);
$data=$request->all();
$data['user_id']=auth()->user()->id;
$data['message']='';
$data['status']=0;
$leave =Leave::create($data);
$admins = Admin::all();
$users = User::where('role_id', 2)->get();
foreach ($admins as $admins) {
foreach($users as $users){
$admins->notify(new LeaveSent($leave));
$users->notify((new LeaveSent($leave)));
}
}
return redirect()->back()->with('message','Leave Created');
}
I understand that you have one user with 20 days availables for vacations or permissions.
You need that for each leave request, this count days of leave, and deduct of days availables for each user
I make this:
transform dates in object Carbon
get diff days
update days availables for user
In your controller
//transform dates in object Carbon
$from = Carbon::parse($request->from);
$to = Carbon::parse($request->to);
//get diff days
$diff = $from->diffInDays($to)
//find user and deduct days
$user = User::findOrFail(Auth::user()->id);
$user->days_availables = $user->days_availables - $diff
$user->update();
you learn more use Carbon library in: https://carbon.nesbot.com/docs/
Hello I was trying to pass some arguments but I don't know how to get value of input using twig here is my code :
okey first of all im displaying the blog details using this detailsaction which also rendering a form to add comments to the blog ;
public function detailsAction(Request $request,Blog $blog){
$user=$this->getUser();
if($user==null)
return $this->redirectToRoute('fos_user_security_login');
$add_comment = new CommentaireBlog();
$em = $this->getDoctrine()->getManager();
$comments = $em->getRepository(CommentaireBlog::class)->findByBlog($blog);
$add_comment->setBlog($blog);
$add_comment->setUser($user);
$add_comment->setDate( new \DateTime());
$form = $this->createFormBuilder($add_comment)
->add('contenu', TextareaType::class)
->getForm();
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$add_comment = $form->getData();
$em = $this->getDoctrine()->getEntityManager();
$em->persist($add_comment);
$em->flush();
return $this->redirectToRoute('blog_details', array('id' => $blog->getId()));
}
}
return $this->render('blog/details.html.twig', array(
'form' => $form->createView(),
'comment' => $add_comment,
'blog' => $blog,
'comments'=>$comments,
));
}
twig page:
{{ form_start(form) }}
<div class="row form-group">
<div class="col col-md-3"><label class=" form-control-label">Votre Commentaire </label></div>
<div class="col-12 col-md-9"> {{ form_widget(form.contenu, { 'attr': {'class': 'form-control'} }) }}<small class="form-text text-muted"></small></div>
<button type="submit" class="btn btn-default">Envoyer</button>
<div class="col-12 col-md-9">
</div>
</div>
{{ form_end(form) }}
now what i want to do is that after someone add a comment and its(racist/verbual abuse..) an other user can report the comment and a mail will be sent so i used reportAction which take three arguments the reason the message and comment id
public function reportAction($msg,$type,$id)
{
}
i still didnt write inside it cause first of all i need to the value of inputs so i went to the twig page and i made this little form to get inputs but idk how to get the value
here is the form :
<div class="modal-body">
<form id="lala" method="GET">
<label for="cars">Reason:</label>
<select id="reportreason">
<option value="Inappropriate Content">Inappropriate Content</option>
<option value="Spam">Spam</option>
<option value="Racism">Racism</option>
<option value="Nudity">Nudity</option>
<option value="Other">Other</option>
</select>
<div class="form-group">
<label for="message-text" class="col-form-label">Message:</label>
<textarea id="reportmessage" class="form-control" id="message-text"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<a id="reportlink" href="{{ path('comment_report', { 'msg': form.vars.data.reportmessage ,'type': form.vars.data.reportreason, 'id': comment.id }) }}" type="button" class="btn btn-primary">Send message</a>
</div>
this is yml file :
blog_details:
path: /{id}/details
defaults: { _controller: "BlogBundle:Blog:details" }
methods: [GET, POST]
comment_report:
path: /{msg}/{type}/{id}/report
defaults: { _controller: "BlogBundle:Blog:report" }
methods: [GET, POST]
but im getting this error now :
Neither the property "reportmessage" nor one of the methods "reportmessage()", "getreportmessage()"/"isreportmessage()" or "__call()" exist and have public access in class "BlogBundle\Entity\CommentaireBlog".
so how can i get get the value of the inputs using twig ?
Twig Object Syntax https://twigfiddle.com/01iobj
Effectively the twig error message is saying that in your path() arguments, you are passing an object without an associated key as {value} The correct syntax would be {key: value} or [value], resembling a JSON syntax.
{
"key1": { "key1a": "value1a" },
"key2": ["value2"],
"key3": "value3"
}
Result
$_GET = array(
'key1' => array('key1a' => 'value1a'),
'key2' => array('value2'),
'key3' => 'value3'
);
A different approach
Looking at what you want to do, you need to refactor your approach.
First change your controller pathing for ONLY the comment.
blog_details:
path: /{id}/details
defaults: { _controller: "BlogBundle:Blog:details" }
methods: [GET, POST]
comment_report:
path: /{comment}/report
defaults: { _controller: "BlogBundle:Blog:report" }
methods: [POST]
Next create a form instance for your modal, this will allow you use the FormInstance for rendering and validating the submitted form elsewhere. Ensuring that all of the validation occurs and you're not having to update different scripts for the same form.
/* /src/Form/CommentReportForm.php */
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type as Form;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints as Assert;
class CommentReportForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('reason', Form\ChoiceType::class [
'choices' => [
'Inappropriate Content' => 'Inappropriate Content',
'Spam' => 'Spam',
'Racism' => 'Racism',
'Nudity' => 'Nudity',
'Other' => 'Other'
]
])
->add('message', Form\TextType::class, [
'constraints' => [
new Assert\Length(['min' => 10]),
new Assert\NotBlank(),
],
]);
}
public function getBlockPrefix()
{
return 'report_comment_form';
}
}
Next, update your Controller actions accordingly.
public function detailsAction(Request $request, Blog $blog)
{
if (!$user = $this->getUser()) {
//this should be handled in your firewall configuration!!!!
return $this->redirectToRoute('fos_user_security_login');
}
$em = $this->getDoctrine()->getManager();
$add_comment = new CommentaireBlog();
$add_comment->setBlog($blog);
$add_comment->setUser($user);
$add_comment->setDate(new \DateTime());
$form = $this->createFormBuilder($add_comment)
->add('contenu', TextareaType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//Symfony form sets values for the model by_reference
$em->persist($add_comment);
$em->flush();
return $this->redirectToRoute('blog_details', array('id' => $blog->getId()));
}
/*
* create the report form
*/
$reportForm = $this->createForm(\App\Form\CommentReportForm::class);
$reportForm->handleRequest($request);
return $this->render('blog/details.html.twig', array(
'form' => $form->createView(),
'comment' => $add_comment,
'blog' => $blog,
'comments'=> $em->getRepository(CommentaireBlog::class)->findByBlog($blog),
/*
* give the report form a different name in twig
*/
'report_form' => $reportForm->createView(),
));
}
public function reportAction(Request $request, CommentaireBlog $comment)
{
$reportForm = $this->createForm(\App\Form\CommentReportForm::class);
$reportForm->handleRequest($request);
/** #var array|string[message, reason] */
$reportData = $reportForm->getData();
/*
array( 'reason' => 'value', 'message' => 'value' )
*/
dump($reportData);
if ($reportForm->isSubmitted() && $reportForm->isValid()) {
//send email
//redirect to success message
}
//display an error message
}
Lastly update your view to support the new form in your modal.
<div class="modal-body">
{{ form_start(report_form, { action: path('comment_report', { comment: comment.id }) })
{{ form_label(report_form.reason) }}
{{ form_widget(report_form.reason) }}
<div class="form-group">
{{ form_label(report_form.message) }}
{{ form_widget(report_form.message) }}
</div>
{{ form_end(report_form) }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Send message</button>
</div>
As a recommendation, I strongly urge you to record the report submissions in the database, to function as a case log and status of the reports. My approach will get you most of the way there, you would just need to create your App\Entity\CommentReport entity, with an optional association to the CommentaireBlog entity. Which would be passed to the form and adding the data_class to the form options resolver, mimicking what you have done in your other database forms.
I don't know why you wrote your path call like that, but there should not be any round brackets about the variables you want to use in your route. The following code should work:
<a
href="{{ path('comment_report', { 'msg': form.reportmessage.value ,'type': form.reportreason.value, 'id': comment.id }) }}"
type="button"
class="btn btn-primary">
Send message
</a>
So I have a problem with many to many relationships.
Currently, I have surat and surat_user table.
How do I insert data into surat and at the same time insert multiple values from select2 multiple forms into surat_user table and how to get data so I can update it.
UPDATE :
I solve the insert problem please see answer below
But now i have no idea how to update those values.
For example
surat_user
id_surat | id_user
1 | 1
1 | 2
How to update surat_user (in controller and model) if i want to remove one of id_user where 'id_surat = 1`
At the moment i don't know how to fetch the multiple values into select2 form edit so here is mu uncomplete codes :
Controller
public function edit_sm($id_surat){
$this->load->view('template/header');
$this->load->view('template/sidebar');
$where = array('id_surat' => $id_surat);
//$data=array('id_status'=> $this->M_sm->get_option());
$data['surat'] = $this->M_sm->edit_sm($where,'surat')->result();
$this->load->view('v_edit_surat',$data);
$this->load->view('template/footer');
}
public function edit_sm_proses() {
$data = array(
'id_surat'=>$this->input->post('id_surat'),
'no_surat'=>$this->input->post('no_surat'),
'id_status'=>$this->input->post('id_status'),
'id_user'=>$this->input->post('id_user')
);
$where = array(
'id_surat' => $id_surat
);
$this->M_sm->edit_sm_proses($where,$data,'surat');
redirect('SuratMasuk');
}
Model:
public function edit_sm($where,$table){
$this->db->join('status_surat', 'status_surat.id_status = surat.id_status');
return $this->db->get_where($table,$where);
}
public function edit_sm_proses($where,$data,$table){
$this->db->where($where);
$this->db->update($table,$data);
}
View
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="box box-solid box-primary"">
<div class="box-header with-border">
<h3 class="box-title">Default Box Example</h3>
</div>
<!-- /.box-header -->
<div class="box-body">
<?php foreach ($surat as $key) { ?>
<form method="post" action="<?php echo base_url()."SuratMasuk/edit_sm_proses" ?>" enctype="multipart/form-data" />
<input type="hidden" name="id_surat" value="<?=$key->id_surat?>">
<div class="form-group">
<label class="control-label col-lg-2">No Surat</label>
<div class="col-lg-5">
<input type="text" name="no_surat" class="form-control no_surat" placeholder="Masukkan Nomor Surat" value="<?=$key->no_surat?>">
<span class="help-block"></span>
</div>
</div>
<br>
<br>
<div class="form-body">
<div class="form-group">
<label class="control-label col-lg-2">Status</label>
<div class="col-lg-5">
<select class="form-control select2 id_status" name="id_status" style="width: 100%;">
<option value="<?=$key->id_status;?>" selected="<?=$key->id_status;?>"><?php echo $key->status;?></option>
<?php foreach ($id_status as $row) { ?>
<option value="<?php echo $row->id_status; ?>"> <?php echo $row->status; ?></option>
<?php } ?>
</select>
<span class="help-block"></span>
</div>
</div>
</div>
<br>
<br>
<div class="form-body">
<div class="form-group">
<label class="control-label col-lg-2">Disposisi</label>
<div class="col-lg-5">
<select class="form-control select2 id_user" name="id_user[]" style="width: 100%;">
<option value="<?=$key->id_user;?>" selected="<?=$key->id_user;?>"><?php echo $key->nama;?></option>
<?php foreach ($id_user as $row) { ?>
<option value="<?php echo $row->id_user; ?>"> <?php echo $row->nama; ?></option>
<?php } ?>
</select>
<span class="help-block"></span>
</div>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<button class="btn btn-danger" type="reset" value="reset">Reset</button>
<button class="btn btn-info">Update</button><br>
Kembali
</form>
<?php
}
?>
</div>
<!-- box-footer -->
</div>
<!-- /.box -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
</section>
<!-- /.content -->
Current Result :
result from codes above
Manage to solve the problem by my self.
i change my controller to this:
public function add_sm_proses(){
$data = array(
'no_surat'=>$this->input->post('no_surat'),
'id_status'=>$this->input->post('id_status')
);
$insert = $this->M_sm->trans_surat_user($data);
if($insert=1){
redirect('SuratMasuk');
} else {
echo "<h2>Gagal menambahkan data</h2>";
}
}
change my model to this :
public function trans_surat_user($data){
$this->db->trans_start();
$this->db->insert('surat', $data);
$id_surat = $this->db->query('SELECT surat.id_surat FROM surat ORDER BY id_surat DESC limit 1');
foreach ($id_surat->result() as $row) {
$id_surat_result = $row->id_surat;
}
$id_user = $_POST['id_user'];
foreach ($id_user as $data2) {
array_push($id_user, $data2);
$this->db->query('INSERT INTO surat_user (id_surat,id_user) VALUES ('.$id_surat_result.','.$data2.')');
}
$this->db->trans_complete();
}
class SuratMasuk extends CI_Controller {
public function add_sm_proses(){
$data = array(
'no_surat'=>$this->input->post('no_surat'),
'id_status'=>$this->input->post('id_status'),
);
Select MAX ID from table like this
$id_surat = $this->db->query('SELECT MAX(surat.id_surat) AS maxid FROM surat')->row()->maxid;
Update:-
$id_surat will give MAX ID present in the table. Don't use for next record.
First, Increment it by value 1 and then use it
$id_surat = $id_surat + 1;
$id_user = $this->input->post('id_user') ? $this->input->post('id_user') : array();
First, check if $id_user have values or not otherwise foreach loop will give e error
if(count($id_user) > 0){
foreach ($id_user as $u){
$data_values = array('id_surat' => $id_surat, 'id_user' => $u);
$this->db->insert('surat_user', $data_values);
}
}
$insert = $this->M_sm->add_sm($data);
$insert will not always return 1. So, only check if value exists
if($insert){
redirect('SuratMasuk');
} else {
echo "<h2>Gagal menambahkan data</h2>";
}
}
}
First, Show all record from DB and for each record add a button to edit the record.
Note:- Don't use <form> inside the loop
<a class="btn btn-warning btn-sm" href="<?= base_url('SuratMasuk/edit_sm/'.$row->id_surat)?>"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>Edit</a>
Controller for Edit
I'm just adding backend code here
where and table is reserved word for DB. It is better to not use it or use in another way.
public function edit_sm($id_surat){
$condition_array = array('id_surat' => $id_surat);
$data['surat'] = $this->M_sm->edit_sm($condition_array ,'surat');
}
Model for Edit
Get the record for edit
This function is getting only one record from DB so use row()
public function edit_sm($condition_array ,$record_in){
$this->db->join('status_surat', 'status_surat.id_status = surat.id_status');
return $this->db->get_where($record_in, $condition_array )->row();
}
Now, Form for will show with data populated in it.
Getting updated data from Controller
public function edit_sm_proses() {
$data = array(
'id_surat'=> $this->input->post('id_surat'),
'no_surat'=>$this->input->post('no_surat'),
'id_status'=>$this->input->post('id_status'),
'id_user'=>$this->input->post('id_user')
);
$condition_array = array(
'id_surat' => $this->input->post('id_surat')
);
$this->M_sm->edit_sm_proses($condition_array, $data, 'surat');
redirect('SuratMasuk');
}
Updating data in Model
public function edit_sm_proses($condition_array, $data, $record_in){
$this->db->where($condition_array);
return $this->db->update($record_in, $data);
}
I need to save the image for an avatar.
Can anyone give me a simple code to save and retrieve image?
I need to:
Save image in folder
Save image name in DB
Finally retrieve on image tag; I have to do it by Query Builder
Form:
<form action="" method="post" role="form" multiple>
{{csrf_field()}}
<legend>Form Title</legend>
<div class="form-group">
<label for="">Your Image</label>
<input type="file" name="avatar">
</div>
<button type="submit" class="btn btn-primary">save</button>
back
</form>
<img name="youravatar" src="">
</div>
Route:
Route::get('pic','avatarController#picshow');
Route::post('pic','avatarController#pic');
Controller:
I have the avatarController, but it is empty because I don't know what to do.
Database:
Table name: avatar
Fields: name id, imgsrc, created_at, Updated_at
Other:
I found this code but I can't find out anything:
if ($request->hasFile('avatar')) {
$file = array('avatar' => Input::file('avatar'));
$destinationPath = '/'; // upload path
$extension = Input::file('avatar')->getClientOriginalExtension();
$fileName = rand(11111,99999).'.'.$extension; // renaming image
Input::file('avatar')->move($destinationPath, $fileName);
}
First, make sure you have the encrypt attribute in your form
<form action="#" method="post" enctype="multipart/form-data">
You can use something similar to this in your controller
public function save(Request $request)
{
$file = $request->file('file');
// rename your file
$name = $file->getClientOriginalName();
\Storage::disk('local')->put($name, \File::get($file));
return "file saved";
}
Yes, you should store the file route in your database as well.
Make sure you are using a consistent path for your images like
Finally you have to create a route to give public access to your image file, like so:
Route::get('images/{file}', function ($file) {
$public_path = public_path();
$url = $public_path . '/storage/' . $file;
// file exists ?
if (Storage::exists($archivo))
{
return response()->file($pathToFile);
}
//not found ?
abort(404);
});
Check the docs about Laravel Responses
I hope this gives you an Idea of what to do.
Upload Image in laravel 5.4
check if request has image
$request->hasFile('image')
OR
$request->file('image')->isValid()
Now Save Image
$request->inputname->store('folder-name') return image path 'folder name/created image name
$request->image->store('images')
Check if image exits
Storage::disk('local')->exists('image name');
Delete Image
Storage::delete('image');
This is my code
if ($request->hasFile('image') && $request->file('image')->isValid())
{
$path = $request->image->store('images');
if(!empty($path)){
$edit = Model::FindOrFail($id);
// Delete old image
$exists = Storage::disk('local')->exists($edit->image);
if($exists){
Storage::delete($edit->image);
}
$edit->image = $path;
$edit->save();
}
}
Reference
I have a Helper as the following:
class IconHelper extends Helper{
public function showList(){
//render a template from ctp file
$template = loadFromTemplate('path/to/my.ctp');
}
}
I want a function to render a .ctp template and return it .
I found View Cells:
In the case that your content can is small inline template, then you can use the Helper, as following:
class IconHelper extends Helper{
public function show($icon){
$template = '<a class="btn btn-default">'.$icon.'</a>';
return $template
}
but in the case when the content is saved in a template CTP file, the best practice is to use the View Cells:
//helper class
class IconListCell extends Cell{
public function display($icon){
//script .....
$this->set(copmat('icon));
}
}
//file: src/Template/Cell/show.ctp
<a class="btn btn-default" style="font-size: 40px;width: 70px;">
<span class="'.$icon.'" id="icon-value-button" data-pack="default">/span>
</a>