控制器功能代码:
$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 :(得分:1)
应该是$surveydata[0]['SurveyId']
,而不是$surveydata->SurveyId
SurveyTitle也是如此
它应该是$surveydata[0]['SurveyTitle']
,而不是$surveydata->SurveyTitle
答案 1 :(得分:1)
请确认,
您的$surveydata
。
如果您通过
获取结果 $resultSet->result()
或$resultSet->row()
,然后使用$surveydata->SurveyTitle
如果您通过以下方式获取结果:
$resultSet->result_array()
或$resultSet->row_array()
,然后使用$surveydata['SurveyTitle]
另外,请务必核对$surveydata