Welcome Guest, Not a member yet? Register   Sign In
undefined index
#11

[eluser]swgj19[/eluser]
Just changed and no result. I will post my view, controller,and model for the posts that is working fine. Keep in mind that the methods for comments and posts are almost identical. So maybe by looking at the posts mvc, we can find the answer to the comments issue.

view

Code:
<br />
<h1>&lt;?php echo $title;?&gt;</h1>

&lt;?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();
?&gt;
<br />


Controller:

Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Posts 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('post_model', 'posts');
  $this->load->model('category_model', 'categories');

  if ($this->session->userdata('user_id') < 1)
  {
   redirect('blog/login','refresh');
  }
}

// --------------------------------------------------------------------

/**
  * index()
  *
  * Description:
  *
  * @access public
  * @return void
  */
public function index()
{
  $data['title'] = "Manage Posts";
  $data['main'] = 'admin_posts_home';
  $data['posts'] = $this->posts->get_all_posts();
  $data['cats'] = $this->categories->get_top_categories();

  $this->load->vars($data);
  $this->load->view('dashboard');  
}

// --------------------------------------------------------------------

/**
  * create()
  *
  * Description:
  *
  * @access public
  * @return void
  */
public function create()
{
  if ($this->input->post('title'))
  {
   $this->posts->add_post();
   $this->session->set_flashdata('message','Post created');

   redirect('admin/posts/index','refresh');
  }
  else
  {
   $data['title'] = "Create Post";
   $data['main'] = 'admin_posts_create';
   $data['cats'] = $this->categories->get_categories_dropdown();

   $this->load->vars($data);
   $this->load->view('dashboard');    
  }
}

// --------------------------------------------------------------------

/**
  * edit()
  *
  * Description:
  *
  * @access public
  * @param string
  * @return void
  */
public function edit($id = 0)
{
  if ($this->input->post('title'))
  {
   $this->posts->update_post();
   $this->session->set_flashdata('message', 'Post updated');

   redirect('admin/posts/index', 'refresh');
  }
  else
  {
   $data['title'] = "Edit Post";
   $data['main'] = 'admin_posts_edit';
   $data['post'] = $this->posts->get_post($id);
   $data['cats'] = $this->categories->get_categories_dropdown();

   $this->load->vars($data);
   $this->load->view('dashboard');    
  }
}

// --------------------------------------------------------------------

/**
  * delete()
  *
  * Description:
  *
  * @access public
  * @param string
  * @return void
  */
public function delete($id = 0)
{
  $this->posts->delete_post($id);
  $this->session->set_flashdata('message', 'Post deleted');

  redirect('admin/posts/index', 'refresh');
}

}


// ------------------------------------------------------------------------
/* End of file admin_model.php */
/* Location: ./application/models/admin_model.php */


Messages In This Thread
undefined index - by El Forum - 11-27-2012, 01:53 AM
undefined index - by El Forum - 11-27-2012, 01:54 AM
undefined index - by El Forum - 11-27-2012, 04:12 AM
undefined index - by El Forum - 11-27-2012, 04:44 AM
undefined index - by El Forum - 11-27-2012, 05:06 AM
undefined index - by El Forum - 11-27-2012, 05:07 AM
undefined index - by El Forum - 11-27-2012, 05:35 AM
undefined index - by El Forum - 11-27-2012, 05:44 AM
undefined index - by El Forum - 11-27-2012, 05:56 AM
undefined index - by El Forum - 11-27-2012, 06:07 AM
undefined index - by El Forum - 11-27-2012, 06:21 AM
undefined index - by El Forum - 11-27-2012, 06:23 AM
undefined index - by El Forum - 11-27-2012, 07:49 AM
undefined index - by El Forum - 11-27-2012, 09:30 AM
undefined index - by El Forum - 11-27-2012, 09:39 AM
undefined index - by El Forum - 11-27-2012, 10:08 AM
undefined index - by El Forum - 11-27-2012, 01:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB