• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i am facing 404_error when i press the edit button


public function edit($slug){

$data['post'] = $this->post_model->get_posts($slug);
if (empty($data['post']))
$data['title']= 'Edit Post';

$this->load->view('posts/edit', $data);

<h2><?= $title ?> </h2>

<?php echo validation_errors(); ?>

<?php echo form_open('posts/create'); ?>
<input type="text" id="hide" name="did" value="<?php echo $post['id']; ?>">

  <div class="form-group">
    <input type="text" class="form-control"name="title" placeholder="Add Title">
  <div class="form-group">
    <label >Body</label>
    <textarea  class="form-control" name="body" placeholder="Add Body"> </textarea>
  <button type="submit" class="btn btn-primary">Submit</button>

<h2> <?php echo $post['title']; ?> </h2>
<small class="post-date">posted on: <?php echo $post['created_at']; ?> </small> <br>
<div class="post-body">
<?php echo $post['body']; ?>


<a class="btn btn-default pull-left" href="<?php echo base_url(); ?>posts/edit/">Edit</a>
<?php echo form_open('/posts/delete/'.$post['id']);?> 

<input type="submit" value="delete"class="btn btn-success ">


<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$route['posts/create'] = 'posts/create';
$route['posts/delete/(:num)'] = 'posts/delete/$1';
$route['posts/(:any)'] = 'posts/view/$1';
$route['posts'] = 'posts/index';
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

The edit method in your controller is expecting an argument ($slug).
The button in your view doesn't pass any argument:

PHP Code:
<class="btn btn-default pull-left" href="<?php echo base_url(); ?>posts/edit/">Edit</a

Load (or autoload) the url helper and change it to:
PHP Code:
<?= anchor('posts/edit/' $post['slug'], 'Edit''class="btn btn-default pull-left"');?>

The anchor function will automatically insert the site_url() (not the base_url()) into the href part.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.