Codeigniter_Blog_App/application/views/posts/view.php

49 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2024-07-11 04:23:32 +00:00
<!--The Post array contains a row from the table posts-->
<h2><?php echo $post['title']; ?></h2>
<small class = "post-date">Posted on: <?php echo $post['created_at']; ?></small><br>
<img src="<?= site_url(); ?>assets/images/posts/<?= $post['post_image'];?>">
<div class = "post-body">
<?php echo $post['body']; ?>
</div>
<hr>
<?php if($this->session->userdata('user_id') == $post['user_id']): ?>
<hr>
<a class="btn btn-default pull-left" href="<?php echo base_url(); ?>posts/edit/<?php echo $post['slug']; ?>">Edit</a>
<?php echo form_open('/posts/delete/'.$post['id']); ?>
<input type="submit" value="Delete" class="btn btn-danger">
</form>
<?php endif; ?>
<hr>
<h3>Comments</h3>
<?php if($comments) : ?>
<?php foreach($comments as $comment) : ?>
<div class="well">
<h5><?= $comment['body']; ?> [by <strong><?= $comment['name'];?></strong>]</h5>
</div>
<?php endforeach; ?>
<?php else : ?>
<p>No Comments to display</p>
<?php endif; ?>
<hr>
<h3>Add Comments</h3>
<?= validation_errors();?>
<?= form_open('comments/create/'.$post['id']); ?>
<div class = "form-group">
<label>Name</label>
<input type="text" name = "name" class="form-control">
</div>
<div class = "form-group">
<label>Email</label>
<input type="text" name = "email" class="form-control">
</div>
<div class = "form-group">
<label>Body</label>
<textarea name = "body" class="form-control"></textarea>
</div>
<!--We are sending in the slug because we need to reload the page if the validations are not successful-->
<input type="hidden" name="slug" value="<?= $post['slug']; ?>">
<button class = "btn btn-primary"type="submit">Submit</button>
</form>