无效的正则表达式标志 n
我试图使用以下代码从 kohana 3 中的 url 获取参数,但 fire bug 给了我一条错误消息“无效的正则表达式标志 n” 代码是:
CONTROLLER
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Test extends Controller_Template
{
public function action_index()
{
$this->template = View::factory('par');
$this->template->content = View::factory('par');
}
public function get()
{
$param1 = $this->request->param('param1');
$param2 = $this->request->param('param2');
$param3 = $this->request->param('param3');
echo "This is param1: ".$param1;
echo "This is param2: ".$param2;
echo "This is param3: ".$param3;
}
}
VIEW
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php $x=1;
$y=2;
$z=3;
?>
<input type="button" value = "button" onClick=<?php echo url::site('test/get'.$x);?> />
</body>
</html>
BOOT STRAP
Route::set('default', '(<controller>(/<action>(/<param1>)(/<param2>)(/<param3>)))',
array(
'param1' => '\d+',
'param2' => '\d+',
'param3' => '\d+',
))
->defaults(array(
'controller' => 'test',
'action' => 'index',
));
请帮我解决这个问题。
I am trying to get parameters from url in kohana 3 using the following code but fire bug is given me an error message "invalid regular expression flag n"
the code is:
CONTROLLER
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Test extends Controller_Template
{
public function action_index()
{
$this->template = View::factory('par');
$this->template->content = View::factory('par');
}
public function get()
{
$param1 = $this->request->param('param1');
$param2 = $this->request->param('param2');
$param3 = $this->request->param('param3');
echo "This is param1: ".$param1;
echo "This is param2: ".$param2;
echo "This is param3: ".$param3;
}
}
VIEW
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?php $x=1;
$y=2;
$z=3;
?>
<input type="button" value = "button" onClick=<?php echo url::site('test/get'.$x);?> />
</body>
</html>
BOOT STRAP
Route::set('default', '(<controller>(/<action>(/<param1>)(/<param2>)(/<param3>)))',
array(
'param1' => '\d+',
'param2' => '\d+',
'param3' => '\d+',
))
->defaults(array(
'controller' => 'test',
'action' => 'index',
));
please help me resolve this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来浏览器会看到这样的内容:
onClick
属性被解释为 JavaScript,而 JavaScript 中的/param/index.php
正试图成为后面跟随的正则表达式文字通过属性访问。正则表达式将为/param/
,带有修饰符i
、n
、d
、e
> 和x
。i
表示不区分大小写的匹配,以便通过;那么就会出现错误,因为 JavaScript 正则表达式没有n
修饰符。我认为您正在尝试使按钮充当链接,因此您需要添加一些引号和对
window.location
的分配:这应该让您更接近您想要去的地方或至少让你克服神秘的“无效的正则表达式标志n”错误。
It looks like the browser sees something like this:
The
onClick
attribute is being interpreted as JavaScript and/param/index.php
in JavaScript is trying to be a regular expression literal followed by a property access. The regex will be/param/
with modifiersi
,n
,d
,e
, andx
. Thei
means case insensitive matching so that gets through; then you an error because there is non
modifier for a JavaScript regular expression.I think you're trying to make the button act like a link so you need to add some quotes and an assignment to
window.location
:That should get you closer to where you're trying to go or at least get you past the mysterious "invalid regular expression flag n" error.