isset 可以与 CodeIgniter 的 get 方法一起使用吗?
使用 CodeIgniter 我试图查看 URL 中的“ID”是否是“uID”(用户 ID)或“sID”(系统 ID)。
我使用的代码是:
if(isset($this->input->get('uID'))) {
$getID = $this-input->get('uID');
} else {
$getID = $this->input->get('sID');
}
当我使用该代码时,我收到服务器错误,指出该网站暂时关闭或正在建设中。有什么想法吗?
Using CodeIgniter I'm trying to see if the 'ID' in the URL is 'uID' (user id) or 'sID' (system id).
The code I'm using is:
if(isset($this->input->get('uID'))) {
$getID = $this-input->get('uID');
} else {
$getID = $this->input->get('sID');
}
When I use that I get a server error saying the website is temporarily down or under construction. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您收到的警告可能是 500 错误 - 这意味着您的服务器未设置为向您显示错误,或者您没有在 index.php 文件中启用它。
您收到但没有看到的错误是:“致命错误:无法在写入上下文中使用函数返回值”,因为您无法在函数上使用 isset 。
如果可以的话,它不会执行您所期望的操作,因为 CI 的
$this->input->get('key')
始终返回一个值 - 如果键返回值,则返回 false不存在。因此,为了完成您想要做的事情,您可以这样写:
根据下面的评论,我想我也会以对您有意义的方式提供它:
这两个解决方案在功能上是相同的。
The warning you're getting is probably a 500 error -- meaning your server is not set up to display errors to you, or you don't have it enabled in your index.php file.
The error you're getting, but not seeing is: "Fatal error: Can't use function return value in write context" because you can't use isset on a function.
If you could it wouldn't do what you're expecting as CI's
$this->input->get('key')
always returns a value -- it returns false if the key does not exist.Therefore, to accomplish what it seems you're trying to do, you'd write:
Based on the comment below, I thought I'd also provide it in a way that makes sense to you:
The two solutions are functionally the same.
isset
仅适用于变量。$this->input->get()
是一个函数调用。这会给你一个错误。我猜测如果请求中未设置
uID
,$this->input->get
将返回null
或 < code>false 或类似的东西。即您不需要isset
,返回值应该已经是 falsey。我建议您花一点时间阅读PHP isset 和空的权威指南。
isset
works only on variables.$this->input->get()
is a function call. That gives you an error.I would guess that if
uID
isn't set in the request,$this->input->get
will returnnull
orfalse
or some such. I.e. you don't needisset
, the return value should already be falsey.I'd recommend you invest the little time it takes to read The Definitive Guide To PHP's isset And empty.