【发布时间】:2016-11-23 17:28:28
【问题描述】:
我在yii1工作。我想根据 id(主键)编辑记录,并将 id 以查询字符串的形式从一个页面传递到另一个页面。现在我想在收到 ID 的控制器上清理该 ID。
我使用filter_input(),但它无法工作。
public function actionEditStudentById()
{
try
{
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
echo $id;
die();
$id = $_GET['id'];
$model = StudentDetail::getStudentById($id);
if (!$model) throw new Exception;
if(isset($_POST['StudentDetail']))
{
$model->attributes = $_POST['StudentDetail'];
if($model->validate())
{
$model->save(FALSE);
Yii::app()->user->setFlash('update', "Record updated successfully!");
$this->redirect(['student/list']);
}
}
$this->render('_form',array('model'=>$model));
}
catch(Exception $e)
{
echo 'Invalid user id: user not available';
}
}
这里die()只是用来停止代码。就在die() 之前,id 始终为空。我希望 id 始终是一个数字,而不是 url 中允许的任何符号
【问题讨论】:
-
你的
getStudentById()方法是什么样的?
标签: php validation yii