Skip to content

Commit

Permalink
Editando Posts Parte 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristian Pessanha da Silva committed Sep 28, 2021
1 parent f66e229 commit c7618a2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 30 deletions.
8 changes: 6 additions & 2 deletions app/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ public function create($request, $response)

}

public function edit($request, $response)
public function edit($request, $response, $params)
{
return $this->container->view->render($response, 'post/edit.twig');
$data = [
'post' => Post::find($params['id'])
];

return $this->container->view->render($response, 'post/edit.twig', $data);
}

public function update($request, $response)
Expand Down
2 changes: 1 addition & 1 deletion resources/views/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</div>
{% if auth.check and auth.user.permissions.is_admin %}
<div class="has-text-right">
<a href="" class="button is-warning is-focused">Editar</a>
<a href="{{ path_for('post.edit', { 'id': post.id }) }}" class="button is-warning is-focused">Editar</a>
<a href="{{ path_for('post.delete')}}?id={{ post.id }}" class="button is-danger is-focused">Deletar</a>
</div>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/post/create.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="column is-8 is-offset-2">
<div class="card article">
<div class="card-content">
<form action="" method="POST">
<form action="{{ path_for('post.create') }}" method="POST">

<div class="field is-horizontal">
<div class="field-label is-normal">
Expand Down
41 changes: 15 additions & 26 deletions resources/views/post/edit.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="column is-8 is-offset-2">
<div class="card article">
<div class="card-content">
<form action="" method="POST">
<form action="{{ path_for('post.edit', {'id' : post.id }) }}" method="POST">

<div class="field is-horizontal">
<div class="field-label is-normal">
Expand All @@ -15,12 +15,15 @@
<div class="field-body">
<div class="field">
<p class="control is-expanded has-icons-left">
<input class="input is-medium" type="text" name="title"
placeholder="Windows 10 terá um novo terminal com abas.">
<input class="input is-medium {{ errors.title ? 'is-danger' : '' }}" type="text" name="title"
placeholder="Windows 10 terá um novo terminal com abas." value="{{ post.title }}">
<span class="icon is-small is-left">
<i class="fas fa-heading"></i>
</span>
</p>
{% if errors.title %}
<small class="has-text-danger">{{ errors.title | first }}</small>
{% endif %}
</div>
</div>
</div>
Expand All @@ -33,47 +36,32 @@
<div class="field is-narrow">
<div class="control">
<label class="radio">
<input type="radio" value="1" name="status">
<input type="radio" {{ post.published ? 'checked' : '' }} value="1" name="published">
Publicado
</label>
<label class="radio">
<input type="radio" value="0" checked name="status">
<input type="radio" {{ post.published ? '' : 'checked' }} value="0" name="published">
Rascunho
</label>
</div>
</div>
</div>
</div>

<div class="field is-horizontal">
<div class="field-label">
<label class="label">Destacar</label>
</div>
<div class="field-body">
<div class="field is-narrow">
<div class="control">
<label class="radio">
<input type="radio" value="1" checked name="featured">
Sim
</label>
<label class="radio">
<input type="radio" value="0" name="featured">
Não
</label>
</div>
</div>
</div>
</div>

<div class="field is-horizontal">
<div class="field-label is-normal">
<label class="label">Descrição</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<textarea id="summernote" name="description" class=""></textarea>
<textarea id="summernote" name="description" class="{{ errors.description ? 'is-danger' : '' }}">
{{ post.description }}
</textarea>
</div>
{% if errors.description %}
<small class="has-text-danger">{{ errors.description | first }}</small>
{% endif %}
</div>
</div>
</div>
Expand All @@ -94,6 +82,7 @@
</form>
</div>
</div>
{% include "components/notifications.twig" %}
</div>

</section>
Expand Down

0 comments on commit c7618a2

Please sign in to comment.