2014-04-04 45 views
2

控制器功能代碼:獲取笨錯誤 - 一個PHP錯誤遇到消息:試圖讓非對象的屬性

$surveydata = $this->getsurveydatabasedonId($SurveyId); 
$this->load->view('editsurvey', array('surveydata' => $surveydata)); 

視圖代碼:

<h1 class="page-header">Edit Survey</h1> 
       <?php 
       $att = array('id' => 'editsurvey_form', 'role' => 'ajax-form'); 
       echo form_open('welcome/editsurvey', $att); 
       ?> 
       <div class="span5 offset1" id="form_div"> 
        <?php echo validation_errors('<div class="alert alert-danger reg_error">', '</div>'); ?> 
        <div class="form-group control-group warning"> 
         <input name="SurveyId" style="display:none" type="text" class="form-control" data-validation-required-message="Please enter a Survey Id" id="SurveyId" required placeholder="Please enter the Survey Id" value="<?php echo set_value('SurveyId', $surveydata->SurveyId); ?>"> 
         <label for="SurveyTitle">Survey Title</label> 
         <input name="SurveyTitle" type="text" class="form-control" data-validation-required-message="Please enter a Survey Title" id="SurveyTitle" required placeholder="Please enter the Survey Title" value="<?php echo set_value('SurveyTitle', $surveydata->SurveyTitle); ?>"> 
         <p class="help-block"></p> 
        </div> 
        <div class="form-group control-group warning"> 
         <label for="SurveyIntroduction">Survey introduction</label> 
         <textarea name="SurveyIntro" type="text" class="form-control" id="SurveyIntro" placeholder="Enter the Survey Introduction"><?php echo set_value('SurveyIntro', $surveydata->SurveyIntro); ?></textarea> 
        </div> 

        <button type="submit" class="btn btn-large btn-warning">Edit Survey</button> 
       </div> 
       </form> 

我得到出現以下錯誤:

A PHP Error was encountered 

Severity: Notice 

Message: Trying to get property of non-object 

Filename: views/editsurvey.php 

Line Number: 11 

我正在通過陣列,但它無法正常工作有人可以幫我嗎?

+0

'$ surveydata'是否在控制器中包含密鑰'surveydata'? – Rikesh

+0

是的,它確實已經放置了控制器代碼以及 – vini

+0

您可以檢查'var_dump($ surveydata);'在您的視圖文件的頂部?\ – Rikesh

回答

1

請確保,

您的$surveydata數據。

如果通過

$resultSet->result() OR $resultSet->row()獲取的結果,然後用$surveydata->SurveyTitle

如果你是通過在獲取結果:

$resultSet->result_array() OR $resultSet->row_array(),然後用$surveydata['SurveyTitle]

而且,請務必檢查計數$surveydata

+0

這是數據陣列(大小= 1) 0 => 陣列(大小= 7) 'SurveyId'=>字符串 '145'(長度= 3) 'SurveyTitle'=>字符串「調查6'(length = 8) 'SurveyIntro'=>字符串'Survey 6'(長度= 8) 'CreatedBy'=>字符串'm123456789'(長度= 10) 'DateCreated'=> string'2014-04- 04,08:12'(length = 19) 'isDisabled'=>字符串'0'(長度= 1) 'SurveyLink'=>字符串'21491'(長度= 5) – vini

+0

我正在讀取一行數據 – vini

+0

然後,你應該檢查num_rows()。 – Pupil

1

應該$surveydata[0]['SurveyId'],不$surveydata->SurveyId

同爲SurveyTitle 應該$surveydata[0]['SurveyTitle'],不$surveydata->SurveyTitle

+0

致命錯誤:無法使用stdClass類型的對象作爲第12行中C:\ wamp \ www \ surveytool \ application \ views \ editsurvey.php中的數組調用堆棧#TimeMemoryFunctionLocation 10.0006264992 {main}().. \ index.php:0 20.0017322600require_once('C:\ wamp \ www \ surveytool \ system \ core \ CodeIgniter.php'\ – vini

+0

您也在下一行做過同樣的錯誤。請改正,無論你使用過'$ surveydata-> SurveyId' – dikesh

+0

我得到錯誤 – vini

相關問題