[eluser]swgj19[/eluser]
I am getting the error. I am not sure why. Because my categories model and post model is working just fine with similar functions. I know this is not a db error as I have already tested.
Error:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: name
Filename: views/admin_comments_edit.php
Line Number: 9
This error is happening for every name of field in my form.
View:
Code:
<br />
<h1><?php echo $title;?></h1>
<?php
echo form_open('admin/posts/edit');
echo "<p><label for='ptitle'>Title</label><br/>";
$data = array('name'=>'title','id'=>'ptitle','size'=>25, 'value' =>$post['title']);
echo form_input($data) ."</p>";
echo "<p><label for='ptags'>Tags</label><br/>";
$data = array('name'=>'tags','id'=>'ptags','size'=>25, 'value' =>$post['tags']);
echo form_input($data) ."</p>";
echo "<p><label for='category_id'>Category </label><br/>";
echo form_dropdown('category_id', $cats, $post['category_id']) ."</p>";
echo "<p><label for='long'>Content</label><br/>";
$data = array('name'=>'body','id'=>'long','rows'=>5, 'cols'=>'40', 'value' =>$post['body']);
echo form_textarea($data) ."</p>";
echo "<p><label for='status'>Status</label><br/>";
$options = array('draft' => 'draft', 'published' => 'published');
echo form_dropdown('status', $options, $post['status']) ."</p><br />";
echo form_hidden('id', $post['id']);
echo form_submit('submit', 'update page');
echo form_close();
?>
<br />
controller
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Comments extends CI_Controller {
// --------------------------------------------------------------------
/**
* __construct()
*
* Constructor PHP 5+ NOTE: Not needed if not setting values!
*
* @access public
* @return void
*/
public function __construct()
{
parent::__construct();
$this->load->model('comment_model', 'comments');
if ($this->session->userdata('user_id') < 1)
{
redirect('blog/login', 'refresh');
}
}
// --------------------------------------------------------------------
/**
* index()
*
* Description:
*
* @access public
* @return void
*/
public function index()
{
$data['title'] = "Manage Comments";
$data['main'] = 'admin_comments_home';
$data['comments'] = $this->comments->get_all_comments();
$this->load->vars($data);
$this->load->view('dashboard');
}
// --------------------------------------------------------------------
/**
* create()
*
* Description:
*
* @access public
* @return void
*/
public function create()
{
if ($this->input->post('name'))
{
$this->comments->add_comment();
$this->session->set_flashdata('message', 'Comment created');
redirect('admin/comments/index', 'refresh');
}
else
{
$data['title'] = "Create Comment";
$data['main'] = 'admin_comments_create';
$data['comments'] = $this->comments->get_comments();
$this->load->vars($data);
$this->load->view('dashboard');
}
}
// --------------------------------------------------------------------
/**
* edit()
*
* Description:
*
* @access public
* @param string
* @return void
*/
function edit($id=0){
if ($this->input->post('name')){
$this->comments->update_comment();
$this->session->set_flashdata('message','Comment updated');
redirect('admin/comments/index','refresh');
}else{
//$id = $this->uri->segment(4);
$data['title'] = "Edit Comment";
$data['main'] = 'admin_comments_edit';
$data['comment'] = $this->comments->get_comments($id);
$data['comments'] = $this->comments->get_all_comments();
$this->load->vars($data);
$this->load->view('dashboard');
}
}
// --------------------------------------------------------------------
/**
* delete()
*
* Description:
*
* @access public
* @param string
* @return void
*/
public function delete($id = 0)
{
$this->comments->delete_comment($id);
$this->session->set_flashdata('message', 'Comment deleted');
redirect('admin/comments/index', 'refresh');
}
}
// ------------------------------------------------------------------------
/* End of file admin_model.php */
/* Location: ./application/models/admin_model.php */