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

#1
controller:

public function edit($slug){

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

$this->load->view('templates/header');
$this->load->view('posts/edit', $data);
$this->load->view('templates/footer');
 
}


                                                 viewSadedit.php)
<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">
    <label>Title</label>
    <input type="text" class="form-control"name="title" placeholder="Add Title">
  </div>
  <div class="form-group">
    <label >Body</label>
    <textarea  class="form-control" name="body" placeholder="Add Body"> </textarea>
  </div>
  <button type="submit" class="btn btn-primary">Submit</button>
</form>


                                                   viewSadview.php)
<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']; ?>
</div> 

<hr>

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

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



                                                      routes:

<?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;
Reply

#2
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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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