"遇到PHP错误" codeigniter项目出错

时间:2015-04-03 14:37:36

标签: php codeigniter

我在尝试查看创建新用户页面时遇到以下错误。

遇到PHP错误 严重性:注意 消息:未定义的变量:列表 文件名:views / rtc.php 行号:33

遇到PHP错误 严重性:注意 消息:尝试获取非对象的属性 文件名:views / rtc.php 行号:33

我在尝试运行创建新用户文件时遇到这些错误,我正在尝试创建动态下拉列表。以下是我的 视图> rtc.php

<script type="text/javascript" src="js/common.js"></script>
    <div class="contentform">        

        <fieldset style="width:55%;float:left;margin-left:5%;">
            <legend >New RTC</legend>

        <!--FORM STARTS HERE-->

        <form action="<?= site_url('form/rtc_insert'); ?>" method="post">   

            <label >RTC ID:<span id="rtc_reg_id_re" style="font-size:12px;float:right;"></span></label>
            <input type="text" name="id" id="rtc_reg_id" placeholder="RTC ID" required/>                 
            <label >Name:</label>
            <input type="text" name="name"  placeholder="Name" required/>
                <label >Country:</label>
                   <select name="country" >
                       <option>Select Country</option>
                        <option value="Bangladesh">Bangladesh</option>
                        <option value="India">India</option>
                        <option value="Nepal">Nepal</option>
                        <option value="Bhutan">Bhutan</option>
                        </select><br/><br/>                                
            <?php
            if($list->num_rows > 0){
                ?>
                <label >Dzongkhag:</label>
                <select onchange="selectGeog(this.options[this.selectedIndex].value)">
                    <option value="-1">Select Dzongkhag</option>
            <?php foreach($list->result() as $listElement){ ?>
                    <option value="<?php echo $listElement->id?>"><?php echo $listElement->dz_name?></option>
            <?php
                    }
                ?> 

                 <label >Geog:</label>
                <select id="geog_dropdown" onchange="selectVillage(this.options[this.selectedIndex].value)">
                    <option value="-1">Select geog</option>
                </select>
                <span id="geog_loader"></span>

                <label >Village:</label>
                <select id="village_dropdown">
                    <option value="-1">Select village</option>
                </select>
                <span id="village_loader"></span>

                <label >Address:</label>
                <textarea type="text" name="address" placeholder="Address" required/></textarea>                       
                <input type="submit" value="Save" id="rtc_reg_submit" class="button"><br/>
             <?php
            }else{
                echo 'No Country Name Found';
            }
            ?>
                </form>

这是我的控制器&gt; form.php

    function rtc_insert()   
    {

        $session_user=$this->session->userdata('logged_in');
        if($session_user['ath']=='admin')
        {$msg = $this->drop_model->getDzongkhag();
            redirect('form/rtc/You Have Successfully Created '.$msg);

        }
        else
            {
            echo ' <script type="text/javascript">
                        alert("Access Error....");
                        </script>';
                redirect('login/home');
            }

    }
public function dropDown()
    {
        $this->load->model('drop_model');
        $result['list']=$this->model->getDzongkhag();
        $this->load->view('rtc',$result);
        }

    public function loadData()
    {
        $loadType=$_POST['loadType'];
        $loadId=$_POST['loadId'];

        $this->load->model('drop_modelmodel');
        $result=$this->model->getData($loadType,$loadId);
        $HTML="";

        if($result->num_rows() > 0){
            foreach($result->result() as $list){
                $HTML.="<option value='".$list->id."'>".$list->name."</option>";
            }
        }
        echo $HTML;
    }

和模型&gt; drop_model.php

    <?php
class drop_model extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function getDzongkhag(){
        $this->db->select('id,dz_name');
        $this->db->from('dzongkhag');
        $this->db->order_by('dz_name', 'asc'); 
        $query=$this->db->get();
        return $query; 
    }

    function getData($loadType,$loadId){
        if($loadType=="geog"){
            $fieldList='gid,g_name as name';
            $table='geog';
            $fieldName='dz_id';
            $orderByField='g_name';                     
        }else{
            $fieldList='vid,village_name as name';
            $table='village';
            $fieldName='geog_id';
            $orderByField='village_name';   
        }

        $this->db->select($fieldList);
        $this->db->from($table);
        $this->db->where($fieldName, $loadId);
        $this->db->order_by($orderByField, 'asc');
        $query=$this->db->get();
        return $query; 
    }
}
?>

一切运行正常,在我从教程中学到的表单中添加了动态下拉列表的代码后问题就开始了!欢迎任何帮助。谢谢

2 个答案:

答案 0 :(得分:0)

错误在if(list->num_rows > 0)if($list->num_rows() > 0)

答案 1 :(得分:0)

尝试从控制器&gt; form.php:

替换它
redirect('form/rtc/You Have Successfully Created '.$msg);

我建议在闪烁成功或失败消息时使用Flashdata