我的项目中codeigniter中的未定义索引

时间:2019-01-08 10:34:48

标签: codeigniter

遇到PHP错误 严重程度:通知

消息:未定义索引:ccover

文件名:Admin_controller / Admin_categories_con.php

行号:39

回溯:

文件:/home3/acropoli/bharatphoton.acropolisglobal/application/controllers/Admin_controller/Admin_categories_con.php
线:39
功能:_error_handler

<?php
class Admin_categories_con extends CI_Controller {

public function index()
{
    $this->load->model('AdminLoginModel');
    $categories = $this->AdminLoginModel->cat_list();
    $this->load->view('Admin_panel/Admin_categories', ['categories'=>$categories ], array('error' =>''));

}

public function test()
{
    echo "Category add successfully";
}


 public function catadd()
{


    $config = [
        'upload_path' => '../uploads',
        'allowed_types' => 'jpg|png|jpeg|gif',
        ];
    $this->load->library('upload', $config);
    $this->load->model('AdminLoginModel');
    $data_form= $this->input->post(NULL,TRUE);

    if($data_form && !$this->upload->do_upload())

    {
    $this->load->model('AdminLoginModel');
    $data_form= $this->input->post(NULL,TRUE);

    if($data_form && !$this->upload->do_upload())
    {
        $cname=$data_form['cname'];
        $ccover=$data_form['ccover'];

   $data=array(
       'cname'=>$cname,
       'ccover'=>$ccover,
       );     

       $this->AdminLoginModel->catadd($data);
       redirect('Admin_controller/Admin_categories_con/test');
    }

    $this->load->view('Admin_panel/Admin_categories'); 
} 
else
{
$this->index();
}
}
}

//这是我的视图文件//

   
<div id="right-panel" class="right-panel">
 <?php include APPPATH.'views/Admin_panel/Admin_header1.php'; ?>

<?php echo form_open_multipart('Admin_controller/Admin_categories_con/catadd'); ?>
    <div class="breadcrumbs">
        <div class="col-sm-4">
            <div class="page-header float-left">
                <div class="page-title">
                    <h1>CATEGORIES</h1>
                </div>
            </div>
        </div>
    </div>
    <div class="content mt-3">
        <div class="col-xl-12">
            <div class="card">
                <div class="card-body">
                    <div class="col-md-8 offset-2">
                        <div class="row form-group">
                           <div class="col col-md-3"><label for="select" class=" form-control-label">Add new Categories</label>
                           </div>
                                <div class="col-12 col-md-9">
                                    <input type="text" id="text-input" name="cname" placeholder="" class="form-control">
                                </div>

                        </div>
                        <div class="row form-group"> 
                           <div class="col col-md-3"><label for="select" class=" form-control-label">Categories Image</label>
                           </div>
                                <div class="col-12 col-md-9">
                                    <input type="file" id="text-input" name="ccover" placeholder="" class="form-control">
                                </div>

                        </div>
                       <div class="row form-group">
                           <div class="col col-md-3"></div>
                            <div class="col-md-3">
                               <button type="submit" class="btn btn-outline-success btn-sm btn-block">Submit</button>
                           </div>
                        </div>
                    </div> 
                </div>
                  <div class="card-body">
                    <table class="table">
                                <thead class="thead-dark">
                                    <tr>
                                        <th scope="col">S.no</th>
                                        <th scope="col">Category Name</th>
                                        <th scope="col">Image</th>
                                        <th scope="col">Status</th>
                                        <th scope="col">Action</th>    
                                    </tr>
                                </thead>
                                <tbody>
                                   <?php if(count($categories) ): ?>
                                    <?php $index=0; ?>

                                        <?php foreach($categories as $category): ?>
                                        <?php $index++; ?>
                                    <tr>
                                        <td><?php echo $index; ?></td>
                                        <td><?= $category->cname ?></td>
                                        <td><?= $category->ccover ?></td>
                                        <td><?= $category->cstatus ?></td>

                                        <td><button type="button"
                                        class="btn btn-danger" data-toggle="modal" data-target="#myModal">Delete</button></td>
                                    </tr>
                                     <?php endforeach; ?>

                                <?php else: ?>
                                     <tr>
                                         <td colspan="6">
                                             No Record Found
                                         </td>
                                     </tr> 

                                        <?php endif; ?>
                                    </tbody>
                            </table>
                    </div>
             </div>  
        </div>

    </div> 
     <?php include APPPATH.'views/Admin_panel/Admin_footer.php'; ?>
</div>

   <?php include APPPATH.'views/Admin_panel/Admin_script.php'; ?>
   </form>

2 个答案:

答案 0 :(得分:0)

您确定$ ccover变量已发送到php吗?

答案 1 :(得分:0)

您无法在post元素中获取输入类型文件...为了获取文件名... codeigniter具有上载类的方法数据..您可以在其中获取文件名...因此 为了上传文件

        if ( ! $this->upload->do_upload('ccover'))
        {
                print_r($this->upload->display_errors());
        }

do_upload方法强制您上传文件...,之后您可以获取文件名

更改

$ccover = $data_form['ccover'];

$ccover = $this->upload->data('file_name');