无效的正则表达式标志 n

发布于 2024-11-29 05:46:19 字数 1600 浏览 0 评论 0原文

我试图使用以下代码从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌枕肩 2024-12-06 05:46:19

看起来浏览器会看到这样的内容:

onClick=/param/index.php

onClick 属性被解释为 JavaScript,而 JavaScript 中的 /param/index.php 正试图成为后面跟随的正则表达式文字通过属性访问。正则表达式将为 /param/ ,带有修饰符 inde > 和 xi 表示不区分大小写的匹配,以便通过;那么就会出现错误,因为 JavaScript 正则表达式没有 n 修饰符。

我认为您正在尝试使按钮充当链接,因此您需要添加一些引号和对 window.location 的分配:

<input type="button" value = "button" onClick="window.location = '<?php echo url::site('test/get'.$x);?>'" />

这应该让您更接近您想要去的地方或至少让你克服神秘的“无效的正则表达式标志n”错误。

It looks like the browser sees something like this:

onClick=/param/index.php

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 modifiers i, n, d, e, and x. The i means case insensitive matching so that gets through; then you an error because there is no n 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:

<input type="button" value = "button" onClick="window.location = '<?php echo url::site('test/get'.$x);?>'" />

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文