Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL rules and Grid search error #1248

Closed
gimox opened this issue Nov 20, 2013 · 14 comments
Closed

URL rules and Grid search error #1248

gimox opened this issue Nov 20, 2013 · 14 comments
Labels
Milestone

Comments

@gimox
Copy link
Contributor

gimox commented Nov 20, 2013

i create a grid with filter in a view.

grid and filter work good.

when i enter some dato in filter search, i can see the get string in url bar somthink like this:
http://mysite.com?modelname[field]=value& ecc eccc

this work.

Now i need to change the url rules to display a pretty url.

if i add somthink like this:
'mystring/< modelname[field]\d+ >/cod'=>'controller/view',
i receive an exception:

Warning – yii\base\ErrorException
preg_match() expects parameter 2 to be string, array given

the problem is in the parsing "[]" in Url rules.

I think this need to be solved in the parsing.

@qiangxue
Copy link
Member

What is the complete error call stack?

@gimox
Copy link
Contributor Author

gimox commented Nov 23, 2013

url rules:

'agency/list/<ViewAgenzia[id]:\d+> /cod' =>'Agenzie/agenzie/index',
Warning – yii\base\ErrorException 
preg_match() expects parameter 2 to be string, array given

    1. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlRule.php at line 291
    286287288289290291292293294295296   

                }
            }

            // match params in the pattern
            foreach ($this->_paramRules as $name => $rule) {
                if (isset($params[$name]) && ($rule === '' || preg_match($rule, $params[$name]))) {
                    $tr["<$name>"] = urlencode($params[$name]);
                    unset($params[$name]);
                } elseif (!isset($this->defaults[$name]) || isset($params[$name])) {
                    return false;
                }

    2. yii\base\Application::handleError()
    3. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlRule.php – preg_match() at line 291
    4. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlManager.php – yii\web\UrlRule::createUrl() at line 246
    5. in /var/www/payfolder/vendor/yiisoft/yii2/yii/data/Sort.php – yii\web\UrlManager::createUrl() at line 339
    6. in /var/www/payfolder/vendor/yiisoft/yii2/yii/data/Sort.php – yii\data\Sort::createUrl() at line 306
    7. in /var/www/payfolder/vendor/yiisoft/yii2/yii/grid/DataColumn.php – yii\data\Sort::link() at line 112
    8. in /var/www/payfolder/vendor/yiisoft/yii2/yii/grid/Column.php – yii\grid\DataColumn::renderHeaderCellContent() at line 60
    9. in /var/www/payfolder/vendor/yiisoft/yii2/yii/grid/GridView.php – yii\grid\Column::renderHeaderCell() at line 275
    10. in /var/www/payfolder/vendor/yiisoft/yii2/yii/grid/GridView.php – yii\grid\GridView::renderTableHeader() at line 229
    11. in /var/www/payfolder/vendor/yiisoft/yii2/yii/widgets/BaseListView.php – yii\grid\GridView::renderItems() at line 124
    12. in /var/www/payfolder/vendor/yiisoft/yii2/yii/widgets/BaseListView.php – yii\widgets\BaseListView::renderSection() at line 102
    13. yii\widgets\BaseListView::yii\widgets\{closure}()   
    14. in /var/www/payfolder/vendor/yiisoft/yii2/yii/widgets/BaseListView.php – preg_replace_callback() at line 104
    15. in /var/www/payfolder/vendor/yiisoft/yii2/yii/grid/GridView.php – yii\widgets\BaseListView::run() at line 198
    16. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/Widget.php – yii\grid\GridView::run() at line 89
    17. in /var/www/payfolder/frontend/modules/Agenzie/views/agenzie/index.php – yii\base\Widget::widget() at line 44
    39404142434445  

                            'class' => 'common\components\ActionColumn',
                            'modalTitle'=>' Sei sicuro di voler eliminare questa filiale?',
                            'modelRecordName'=>'nome'
                            ]
                        ],
        ]); ?>
    </div>

    18. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/View.php – require() at line 281
    19. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/View.php – yii\base\View::renderPhpFile() at line 221
    20. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/View.php – yii\base\View::renderFile() at line 131
    21. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/Controller.php – yii\base\View::render() at line 307
    22. in /var/www/payfolder/frontend/modules/Agenzie/controllers/AgenzieController.php – yii\base\Controller::render() at line 76
    7172737475767778798081  


            return $this->render('index', [
                                            'dataProvider'  => $dataProvider,
                                            'searchModel'   => $searchModel,
                                            'r' =>$_GET
                                            ]);
        }

        /**
         * Displays a single AgenzieIndirizzo model.
         * @param integer $id

    23. app\modules\Agenzie\controllers\AgenzieController::actionIndex()
    24. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/InlineAction.php – call_user_func_array() at line 53
    25. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/Controller.php – yii\base\InlineAction::runWithParams() at line 130
    26. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/Module.php – yii\base\Controller::runAction() at line 585
    27. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/Application.php – yii\base\Module::runAction() at line 77
    28. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/Application.php – yii\web\Application::handleRequest() at line 283
    29. in /var/www/payfolder/frontend/web/index.php – yii\base\Application::run() at line 18
    131415161718    

        require(__DIR__ . '/../config/main.php'),
        require(__DIR__ . '/../config/main-local.php')
    );

    $application = new yii\web\Application($config);
    $application->run();

$_GET = array (
  'ViewAgenzia' => 
  array (
    'id' => '5',
    'nome' => '',
    'comune' => '',
    'main_name' => '',
    'enabled' => '',
    'stato' => '',
  ),
);

$_SERVER = array (
  'REDIRECT_HTTPS' => 'on',
  'REDIRECT_SSL_TLS_SNI' => 'www.payfolder.com',
  'REDIRECT_STATUS' => '200',
  'HTTPS' => 'on',
  'SSL_TLS_SNI' => 'www.payfolder.com',
  'SSL_SERVER_S_DN_C' => 'IT',
  'SSL_SERVER_S_DN_ST' => 'IT',
  'SSL_SERVER_S_DN_L' => 'Cagliari',
  'SSL_SERVER_S_DN_O' => 'Easynetwork',
  'SSL_SERVER_S_DN_OU' => 'EasyNetwork',
  'SSL_SERVER_S_DN_CN' => 'www.payfolder.com',
  'SSL_SERVER_S_DN_Email' => 'info@easy-network.it',
  'SSL_SERVER_I_DN_C' => 'IT',
  'SSL_SERVER_I_DN_ST' => 'IT',
  'SSL_SERVER_I_DN_L' => 'Cagliari',
  'SSL_SERVER_I_DN_O' => 'Easynetwork',
  'SSL_SERVER_I_DN_OU' => 'EasyNetwork',
  'SSL_SERVER_I_DN_CN' => 'www.payfolder.com',
  'SSL_SERVER_I_DN_Email' => 'info@easy-network.it',
  'SSL_VERSION_INTERFACE' => 'mod_ssl/2.4.6',
  'SSL_VERSION_LIBRARY' => 'OpenSSL/1.0.1',
  'SSL_PROTOCOL' => 'TLSv1',
  'SSL_SECURE_RENEG' => 'true',
  'SSL_COMPRESS_METHOD' => 'NULL',
  'SSL_CIPHER' => 'ECDHE-RSA-AES256-SHA',
  'SSL_CIPHER_EXPORT' => 'false',
  'SSL_CIPHER_USEKEYSIZE' => '256',
  'SSL_CIPHER_ALGKEYSIZE' => '256',
  'SSL_CLIENT_VERIFY' => 'NONE',
  'SSL_SERVER_M_VERSION' => '3',
  'SSL_SERVER_M_SERIAL' => '852C3619E98BC708',
  'SSL_SERVER_V_START' => 'Nov  6 09:18:18 2013 GMT',
  'SSL_SERVER_V_END' => 'Nov  6 09:18:18 2014 GMT',
  'SSL_SERVER_S_DN' => 'emailAddress=info@easy-network.it,CN=www.payfolder.com,OU=EasyNetwork,O=Easynetwork,L=Cagliari,ST=IT,C=IT',
  'SSL_SERVER_I_DN' => 'emailAddress=info@easy-network.it,CN=www.payfolder.com,OU=EasyNetwork,O=Easynetwork,L=Cagliari,ST=IT,C=IT',
  'SSL_SERVER_A_KEY' => 'rsaEncryption',
  'SSL_SERVER_A_SIG' => 'sha1WithRSAEncryption',
  'SSL_SESSION_ID' => '38c5ec55a0cebfd8f8080e2cfd9e1fc462c4f3d844387e0501d3582a734c1a73',
  'SSL_SESSION_RESUMED' => 'Resumed',
  'HTTP_HOST' => 'www.payfolder.com',
  'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:25.0) Gecko/20100101 Firefox/25.0',
  'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
  'HTTP_ACCEPT_LANGUAGE' => 'it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3',
  'HTTP_ACCEPT_ENCODING' => 'gzip, deflate',
  'HTTP_REFERER' => 'https://www.payfolder.com/agency/list',
  'HTTP_COOKIE' => 'PHPSESSID=ujoef1j980fh63ltdlbpl2ggp3; _csrf=ccf06370c932a642d59ecacf81a3062951e8b02b985f9f0dd24d2138f0de0feds%3A40%3A%2282565a51117a5cd3f3658f38fe73abe5723f7641%22%3B; _identity=a3772873a9f751b8de1bd923a8a1a2273acaeb39881501232d6f1fd3d01e346fs%3A58%3A%22%5B%221%22%2C%22a%3A2%3A%7Bs%3A5%3A%5C%22token%5C%22%3BN%3Bs%3A9%3A%5C%22tokentime%5C%22%3BN%3B%7D%22%2C2592000%5D%22%3B',
  'HTTP_CONNECTION' => 'keep-alive',
  'PATH' => '/usr/local/bin:/usr/bin:/bin',
  'SERVER_SIGNATURE' => '
Apache/2.4.6 (Ubuntu) Server at www.payfolder.com Port 443

',
  'SERVER_SOFTWARE' => 'Apache/2.4.6 (Ubuntu)',
  'SERVER_NAME' => 'www.payfolder.com',
  'SERVER_ADDR' => '172.31.8.120',
  'SERVER_PORT' => '443',
  'REMOTE_ADDR' => '94.39.70.155',
  'DOCUMENT_ROOT' => '/var/www/payfolder/frontend/web',
  'REQUEST_SCHEME' => 'https',
  'CONTEXT_PREFIX' => '',
  'CONTEXT_DOCUMENT_ROOT' => '/var/www/payfolder/frontend/web',
  'SERVER_ADMIN' => 'giorgiomodoni@easy-network.it',
  'SCRIPT_FILENAME' => '/var/www/payfolder/frontend/web/index.php',
  'REMOTE_PORT' => '63931',
  'REDIRECT_QUERY_STRING' => 'ViewAgenzia%5Bid%5D=5&ViewAgenzia%5Bnome%5D=&ViewAgenzia%5Bcomune%5D=&ViewAgenzia%5Bmain_name%5D=&ViewAgenzia%5Benabled%5D=&ViewAgenzia%5Bstato%5D=',
  'REDIRECT_URL' => '/agency/list',
  'GATEWAY_INTERFACE' => 'CGI/1.1',
  'SERVER_PROTOCOL' => 'HTTP/1.1',
  'REQUEST_METHOD' => 'GET',
  'QUERY_STRING' => 'ViewAgenzia%5Bid%5D=5&ViewAgenzia%5Bnome%5D=&ViewAgenzia%5Bcomune%5D=&ViewAgenzia%5Bmain_name%5D=&ViewAgenzia%5Benabled%5D=&ViewAgenzia%5Bstato%5D=',
  'REQUEST_URI' => '/agency/list?ViewAgenzia%5Bid%5D=5&ViewAgenzia%5Bnome%5D=&ViewAgenzia%5Bcomune%5D=&ViewAgenzia%5Bmain_name%5D=&ViewAgenzia%5Benabled%5D=&ViewAgenzia%5Bstato%5D=',
  'SCRIPT_NAME' => '/index.php',
  'PHP_SELF' => '/index.php',
  'REQUEST_TIME_FLOAT' => 1385223139.052,
  'REQUEST_TIME' => 1385223139,
);

$_COOKIE = array (
  'PHPSESSID' => 'ujoef1j980fh63ltdlbpl2ggp3',
  '_csrf' => 'ccf06370c932a642d59ecacf81a3062951e8b02b985f9f0dd24d2138f0de0feds:40:"82565a51117a5cd3f3658f38fe73abe5723f7641";',
  '_identity' => 'a3772873a9f751b8de1bd923a8a1a2273acaeb39881501232d6f1fd3d01e346fs:58:"["1","a:2:{s:5:\\"token\\";N;s:9:\\"tokentime\\";N;}",2592000]";',
);

$_SESSION = array (
  '__flash' => 
  array (
  ),
  '__returnUrl' => '/',
  '__id' => '1',
  'user.deadlinePsw' => 1383692400,
  'config.maxSessionTime' => '600',
  'config.expirePsw' => '30',
  'menu' => 
  stdClass::__set_state(array(
     'content' => 
    stdClass::__set_state(array(
       'status' => 'OK',
       'data' => 
      stdClass::__set_state(array(
         '1' => 
        stdClass::__set_state(array(
           'id' => '1',
           'menu_name_long' => 'Gestione Agenzie',
           'menu_name_short' => 'Agenzie',
           'order' => '1',
           'link' => NULL,
           'submenu' => 
          stdClass::__set_state(array(
             '1' => 
            stdClass::__set_state(array(
               'id' => '1',
               'menu_name_long' => 'Lista Agenzie',
               'menu_name_short' => 'Lista',
               'order' => '1',
               'link' => 'agency/list',
            )),
             '3' => 
            stdClass::__set_state(array(
               'id' => '3',
               'menu_name_long' => 'Agenzie Pending',
               'menu_name_short' => 'Pending',
               'order' => '2',
               'link' => 'site/test2',
            )),
          )),
        )),
         '2' => 
        stdClass::__set_state(array(
           'id' => '2',
           'menu_name_long' => 'Gestione Operatori',
           'menu_name_short' => 'Operatori',
           'order' => '2',
           'link' => NULL,
           'submenu' => 
          stdClass::__set_state(array(
             '2' => 
            stdClass::__set_state(array(
               'id' => '2',
               'menu_name_long' => 'Lista Operatori',
               'menu_name_short' => 'Lista',
               'order' => '1',
               'link' => 'site/test2',
            )),
          )),
        )),
      )),
    )),
     'http_code' => 200,
  )),
);

@cebe
Copy link
Member

cebe commented Nov 23, 2013

This error results from creating an url with nested array parameters.
Looks like the problem is that Sort::createUrl() uses $_GET to build the url which in your case contains array parameters that are then given to urlManager.

We shoud add a check for array() in UrlRule::291 to fix this.

@gimox
Copy link
Contributor Author

gimox commented Nov 23, 2013

yes, nedd a check for array fix to permit the pretty url with grid.

cebe added a commit that referenced this issue Nov 23, 2013
* master:
  Fixes #1248: url manager didn't handle array parameters well.
  travis: speed up composer
  fixes #1306
  fixed travis and composer issue
  fixed array helper test
  fixed Sort test
  some clarification on model docs
  fixed Sort::params to be retrieved from Request instead of $_GET
  revokeAll() implementation for PhpManager
  revokeAll() implementation for DbManager
  added abstract function revokeAll()
  indentation fix
  fixes #1303: Security::decrypt now returns null w/o error when null is passed as $data
  Added link to new RBAC page
  added link to forum thread
  Basic information about RBAC
  RBAC documentation
  added revokeAll() test
  refactored redis AR Query::scalar()

Conflicts:
	.travis.yml
@gimox
Copy link
Contributor Author

gimox commented Nov 27, 2013

not working jet.

if i insert some var it not get errors but i have not a pretty url.

if i insert two parameters in url i get an error

Url rules:
'operators/<id:\d+>/get/<ViewUserAgenzia[nome_indirizzo]:\w+>/agency/<ViewUserAgenzia[comune]:\w+>/comune'=>'Operators/operators/view', // view

Error

 Warning – yii\base\ErrorException    
preg_match(): Compilation failed: two named subpatterns have the same name at offset 87

    1. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlRule.php at line 215
    210211212213214215216217218219220   


            if ($this->host !== null) {
                $pathInfo = strtolower($request->getHostInfo()) . '/' . $pathInfo;
            }

            if (!preg_match($this->pattern, $pathInfo, $matches)) {
                return false;
            }
            foreach ($this->defaults as $name => $value) {
                if (!isset($matches[$name]) || $matches[$name] === '') {
                    $matches[$name] = $value;

    2. yii\base\Application::handleError()
    3. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlRule.php – preg_match() at line 215
    4. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlManager.php – yii\web\UrlRule::parseRequest() at line 190
    5. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/Request.php – yii\web\UrlManager::parseRequest() at line 136
    6. in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/Application.php – yii\web\Request::resolve() at line 69
    7. in /var/www/payfolder/vendor/yiisoft/yii2/yii/base/Application.php – yii\web\Application::handleRequest() at line 288
    8. in /var/www/payfolder/frontend/web/index.php – yii\base\Application::run() at line 18
    131415161718    

        require(__DIR__ . '/../config/main.php'),
        require(__DIR__ . '/../config/main-local.php')
    );

    $application = new yii\web\Application($config);
    $application->run();

@qiangxue
Copy link
Member

Could you show what is $this->pattern at line 215 in UrlRule.php?

@cebe cebe reopened this Nov 27, 2013
@gimox
Copy link
Contributor Author

gimox commented Nov 27, 2013

the line is:

'operators/<id:\d+>/get/<ViewUserAgenzia[nome_indirizzo]:\w+>/agency/<ViewUserAgenzia[comune]:\w+>/comune'=>'Operators/operators/view', // view

@qiangxue
Copy link
Member

Nope, I'm asking about the value at line 215, not the one you initially set it. They are different.
FYI, your rule is incorrect because the param name can only be alphanumeric chars. But I still want to know how we can show better error message.

@gimox
Copy link
Contributor Author

gimox commented Nov 27, 2013

it's difficult now reconstruct the line 215 because i create the UrlRule.php dinamically.
So i try now....
about alphanumeric... so i did it now to test it.

@qiangxue
Copy link
Member

just log a message before line 215...

@gimox
Copy link
Contributor Author

gimox commented Nov 28, 2013

this is the log of $this->pattern at line 215 of urlRule.php

2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^home$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^error$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^login$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^logout$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^resetlogin$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^thecoffeetime$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^stops$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^changepsw$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^getpv/(?P<id_regione>\d+)$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^getct/(?P<id>\d+)$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^getpvt$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [application] ****#^agency/list/(?P<ViewAgenzia>[nome]:\w+)/cod/(?P<ViewAgenzia>[nome]:\w+)/agency$#u
2013/11/28 11:18:08 [195.130.246.121] [error] [yii\base\ErrorException] exception 'yii\base\ErrorException' with message 'preg_match(): Compilation failed: two named subpatterns have the same name at offset 60' in /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlRule.php:216
Stack trace:
#0 [internal function]: yii\base\Application->handleError(2, 'preg_match(): C...', '/var/www/payfol...', 216, Array)
#1 /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlRule.php(216): preg_match('#^agency/list/(...', 'agency/list', NULL)
#2 /var/www/payfolder/vendor/yiisoft/yii2/yii/web/UrlManager.php(190): yii\web\UrlRule->parseRequest(Object(yii\web\UrlManager), Object(yii\web\Request))
#3 /var/www/payfolder/vendor/yiisoft/yii2/yii/web/Request.php(136): yii\web\UrlManager->parseRequest(Object(yii\web\Request))
#4 /var/www/payfolder/vendor/yiisoft/yii2/yii/web/Application.php(69): yii\web\Request->resolve()
#5 /var/www/payfolder/vendor/yiisoft/yii2/yii/base/Application.php(288): yii\web\Application->handleRequest(Object(yii\web\Request))
#6 /var/www/payfolder/frontend/web/index.php(18): yii\base\Application->run()

@gimox
Copy link
Contributor Author

gimox commented Nov 28, 2013

i think the problem is this.

^agency/list/(?P<ViewAgenzia>[nome]:\w+)/cod/(?P<ViewAgenzia>[nome]:\w+)/agency$#u

so i send ViewAgenzia>[nome] and ViewAgenzia[id]
but it arrive as ViewAgenzia>[nome] it take the last params.

@cebe
Copy link
Member

cebe commented Nov 28, 2013

the generated regex includes [] which are special characters in regex and so are not recognized as part of the name.

@qiangxue
Copy link
Member

As @cebe said, you should not use square brackets in the parameter names. Only word characters are allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants