Yii 框架:未定义变量 - 关键字
public function actionSearch()
{
$this->showsearch = 1;
$data['keyword'] = isset($_REQUEST['keyword']) $_REQUEST['keyword']:NULL;
$data['option'] = isset($_REQUEST['option'])?$_REQUEST['option']:array();
$data['country'] = isset($_REQUEST['country'])?$_REQUEST['country']:NULL;
$this->render('search', $data);
}
在我的视图中,
<?php echo CHtml::textField('keyword', $keyword, array('style' => 'width:97%;')); ?>
输出显示,
500
Undefined variable: keyword.
你能告诉我错误是什么吗?
public function actionSearch()
{
$this->showsearch = 1;
$data['keyword'] = isset($_REQUEST['keyword']) $_REQUEST['keyword']:NULL;
$data['option'] = isset($_REQUEST['option'])?$_REQUEST['option']:array();
$data['country'] = isset($_REQUEST['country'])?$_REQUEST['country']:NULL;
$this->render('search', $data);
}
In my View I have,
<?php echo CHtml::textField('keyword', $keyword, array('style' => 'width:97%;')); ?>
The output says,
500
Undefined variable: keyword.
Can you tell me what the error is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要先检查是否有请求
当您第一次加载页面时,没有请求。
You need to check if there is some request first
When you just first load the page there is no request.
您的模型中是否有属性
关键字
?Do you have property
keyword
in your model?缺少一个“?”在 isset($_REQUEST['keyword']) 之后。应该是:
There is a missing '?' after isset($_REQUEST['keyword']). It should be :