yiisoft / yii2-gii

Yii 2 Gii Extension
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
203 stars 192 forks source link

Can't access the page when the table related contains underscores #49

Closed ruffiem closed 8 years ago

ruffiem commented 9 years ago

I fooled around and created 3 tables :

test_with_underscore test_underscore testnoscore

The generators creates the files correctly for all 3 tables but when I try to access the page, only testnoscore shows up. The other two show an error, for test_underscore it will be :

An Error occurred while handling another error:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request: spa/error' in /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/base/Controller.php:122
Stack trace:
#0 /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('error', Array)
#1 /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/web/ErrorHandler.php(80): yii\base\Module->runAction('spa/error')
#2 /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/base/ErrorHandler.php(101): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#3 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#4 {main}
Previous exception:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "testUnderscore".' in /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/base/Module.php:461
Stack trace:
#0 /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('testUnderscore', Array)
#1 /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#2 /usr/local/var/www/wip/mrvyii/web/index.php(12): yii\base\Application->run()
#3 {main}

Next exception 'yii\web\NotFoundHttpException' with message 'Page not found.' in /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/web/Application.php:96
Stack trace:
#0 /usr/local/var/www/wip/mrvyii/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 /usr/local/var/www/wip/mrvyii/web/index.php(12): yii\base\Application->run()
#2 {main}

The DB is MySQL and the table scheme has 3 elementary columns (id, col1, col2).

samdark commented 9 years ago
  1. Please provide SQL to create schema and add some data.
  2. Please provide data you've entered into forms.
  3. Please provide URL of the page accessed.
ruffiem commented 9 years ago

Hey Sam,

Here we go :

Tables

CREATE TABLE `test_with_underscore` (
  `idtest` int(11) NOT NULL,
  `coltest` varchar(45) DEFAULT NULL,
  `coltest1` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`idtest`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `testnounder` (
  `idtest` int(11) NOT NULL,
  `coltest` varchar(45) DEFAULT NULL,
  `coltest1` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`idtest`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `test_underscore` (
  `idtest` int(11) NOT NULL,
  `coltest` varchar(45) DEFAULT NULL,
  `coltest1` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`idtest`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Model generator

Data from automation :

CRUD generator

Example for test_with_underscore : sample

Links

Data

No sample data.

samdark commented 9 years ago

Thanks!

ruffiem commented 9 years ago

I can take care of it if you want ^^

samdark commented 9 years ago

Yes, that would be great.

ruffiem commented 9 years ago

I'm on it. Were you able to reproduce the issue ? Or anyone else out there ?

samdark commented 9 years ago

I haven't tried yet.

wildgras commented 9 years ago

I have the same issue. Is there a solution for this?

ashkarpetin commented 8 years ago

I couldn't reproduce the bug. I presume he is using wrong controller IDs in url: testUnderscore must be test-underscore and testWithUnderscore must be test-with-underscore.

ghost commented 7 years ago

Hi... i have the same issue do i have to add underscore in controller and view folder?

Here is my stack trace:

`yii\base\InvalidRouteException: Unable to resolve the request "tfinxmlsri/index". in C:\xampp\htdocs\facturas_seted\vendor\yiisoft\yii2\base\Module.php:532 Stack trace:

0 C:\xampp\htdocs\facturas_seted\vendor\yiisoft\yii2\web\Application.php(102): yii\base\Module->runAction('tfinxmlsri/inde...', Array)

1 C:\xampp\htdocs\facturas_seted\vendor\yiisoft\yii2\base\Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))

2 C:\xampp\htdocs\facturas_seted\web\index.php(12): yii\base\Application->run()

3 {main}

Next yii\web\NotFoundHttpException: Página no encontrada. in C:\xampp\htdocs\facturas_seted\vendor\yiisoft\yii2\web\Application.php:114 Stack trace:

0 C:\xampp\htdocs\facturas_seted\vendor\yiisoft\yii2\base\Application.php(380): yii\web\Application->handleRequest(Object(yii\web\Request))

1 C:\xampp\htdocs\facturas_seted\web\index.php(12): yii\base\Application->run()

2 {main}`

MaksimKiselev commented 7 years ago

@jeicd 's right!

The controller id must be delimiter with - symbol, because here https://github.com/yiisoft/yii2/blob/master/framework/base/Module.php#L631 controller id will be exploded and will uppercased first letter.

If you wanna use camelCase in your routes, you can write url rules like this 'testWithUnderscore/<action:\w+>' => 'test-with-underscope/<action>',

If you wanna use camelCase in path to your views, just set viewPath in controller like this:

$this->viewPath = $this->module->getViewPath() . DIRECTORY_SEPARATOR . 'testWithUnderscore';

or you can override getViewPath method.

to @sucoec @wildgras @ruffiem