我想更新/编辑我的数据..data得到更新,但在PHP的视图页面中显示一些错误

时间:2016-02-01 18:10:09

标签: php codeigniter

它显示以下错误:

  

1.Severity:警告

     

消息:缺少Super_Admin :: edit_category()

的参数1      

文件名:controllers / super_admin.php

     
      
  1. 严重性:注意

         

    消息:未定义的变量:category_id

         

    文件名:controllers / super_admin.php

  2.   

以下是Model的代码:

<?php

class Super_Admin_Model extends CI_Model
{

    public function select_catgory_info_by_id($category_id)
    {
        $this->db->select('*');
        $this->db->from('tbl_category');
        $this->db->where('category_id', $category_id);
        $query_result = $this->db->get();
        $result       = $query_result->row();
        return $result;
    }

    public function update_category_by_id($category_id, $data)
    {
        $this->db->where('category_id', $category_id);
        $this->db->update('tbl_category', $data);
    }

}
?>

以下是控制器代码:

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Super_Admin extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
        $admin_id = $this->session->userdata('admin_id');
        if ($admin_id == NULL)
        {
            redirect('admin_login', 'refresh');
        }
    }

    public function edit_category($category_id)
    {
        $data                  = array();
        $data['category_info'] = $this->super_admin_model->select_catgory_info_by_id($category_id);
        $data['maincontent']   = $this->load->view('admin/edit_category', $data, true);
        $data['title']         = 'Edit Category';
        $this->load->view('admin/admin_master', $data);
    }

    public function update_category()
    {
        $data                         = array();
        $category_id                  = $this->input->post('category_id', TRUE);
        $data['category_name']        = $this->input->post('category_name', TRUE);
        $data['category_description'] = $this->input->post('category_description', TRUE);
        $data['publication_status']   = $this->input->post('publication_status', TRUE);
        $this->super_admin_model->update_category_by_id($category_id, $data);
        $sdata['message']             = "Updated successfully";
        $this->session->set_userdata($sdata);
        redirect('super_admin/edit_category');
    }

}
?>

这是我的观点页面:

<div class="row">
    <div class="col-lg-12">
        <h1 class="page-header">Category Info</h1>
    </div>
    <!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-heading">
                Edit Category
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-6">
                        <form action="<?php echo base_url(); ?>super_admin/update_category" method="post"  >
                            <div>
                                <?php
                                $message = $this->session->userdata('message');
                                if ($message)
                                {
                                    echo $message;
                                    $this->session->unset_userdata('message');
                                }
                                ?>

                            </div>
                            <div class="form-group">
                                <label>Category Name</label>
                                <input class="form-control" name="category_name" value="<?php echo $category_info->category_name; ?>">
                                <input type="hidden" class="form-control" name="category_id" value="<?php echo $category_info->category_id; ?>">
<!--  <p class="help-block">Example block-level help text here.</p> -->
                            </div>

                            <div class="form-group">
                                <label>Category Description</label>
                                <textarea class="form-control" rows="3" name="category_description"  ><?php echo $category_info->category_description; ?> </textarea>

                            </div>

                            <div class="form-group">
                                <label>Category Status</label>
                                <div class="radio">
                                    <?php
                                    if ($category_info->publication_status == 1)
                                    {
                                        ?>
                                        <label>
                                            <input type="radio" name="publication_status"   id="optionsRadios1" value="1" checked>Published
                                        </label>
                                        <?php
                                    }
                                    else
                                    {
                                        ?>
                                        <label>
                                            <input type="radio" name="publication_status"   id="optionsRadios1" value="1" >Published
                                        </label>
                                        <?php
                                    }
                                    ?>
                                </div>
                                <div class="radio">
                                    <?php
                                    if ($category_info->publication_status == 0)
                                    {
                                        ?>
                                        <label>
                                            <input type="radio" name="publication_status" id="optionsRadios2" value="0" checked>Unpublished
                                        </label>
                                        <?php
                                    }
                                    else
                                    {
                                        ?>
                                        <label>
                                            <input type="radio" name="publication_status" id="optionsRadios2" value="0">Unpublished
                                        </label>
                                        <?php
                                    }
                                    ?>
                                </div>
                            </div>
                            <button type="submit" class="btn btn-default">Submit </button>
                            <button type="reset" class="btn btn-default">Reset </button>
                        </form>
                    </div>
                </div>
                <!-- /.row (nested) -->
            </div>
            <!-- /.panel-body -->
        </div>
        <!-- /.panel -->
    </div>
    <!-- /.col-lg-12 -->
</div>
<!-- /.row -->

1 个答案:

答案 0 :(得分:0)

Super_Admin::update_category()结束时,您拨打redirect('super_admin/edit_category');。这会将HTTP重定向到由方法/super_admin/edit_category处理的URL Super_Admin::edit_category()

此方法需要一个参数,但URL中没有给出(这是警告)。通知的原因很明显:由于edit_category()被调用而没有任何参数,因此未设置其参数$category_id

您应该像这样呼叫redirect()(例如):

redirect('super_admin/edit_category/'.$category_id);