I'm using the Foundationize custom build of Yii2, which is a couple of years old but in general seems to run just fine.
However, when I've come to run the gii tool for generating new models etc. the routing is ignored and my application's index page is simply reloaded.
The URL I'm trying to access is http://localhost/web/index.php?r=gii
I have this line in my index.php
defined('YII_ENV') or define('YII_ENV', 'dev');
and my config/web.php contains the following
if (YII_ENV_DEV) {
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
'allowedIPs' => [$_SERVER['REMOTE_ADDR']], // always allow on current server
];}
Am i missing a step somewhere? I tried the 'basic' setup from the main Yii site and that seemed to work fine on the same server. Thanks in advance.
For some reason it was the routing that was broken in this install
instead of
http://localhost/web/index.php?r=gii
I used
http://locahost/web/index.php/gii
and it was all fine
I think you modified your configure ( in config/web.php)
'components' => [
'urlManager' => [
'class' => 'yii\web\UrlManager', //clase UrlManager
'showScriptName' => true, // to remove index.php
'enablePrettyUrl' => true //for Friendly url
],
],
If you use the advanced template, try
http://localhost/mysitename/frontend/web/index.php/gii
Or
http://localhost/mysitename/frontend/web/index.php?r=gii
Related
i'm trying to implement mdmsoft/yii2-admin with advanced template with this pull request
but when i try add route to menu get error "Route "x" not found."
if i try force add route via database the menu show an empty array.
for this you need to create one inside config/main.php
'urlManager' => [
'enablePrettyUrl' => true,
'rules' => [
'test/' => site(ControllerName)/test(actionName),
]
];
Let me know was this helpful or not.
I have the following url manager path
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:(\w|-)+>/' => 'site/index',
'<module:api\w+>/<controller:\w+>/<action:(\w|-)+>' => '<module>/<controller>/<action>',
],
]
What am looking for is all urls not rendered via api module paths to run via site/index but all other paths having api/* to be executed via module paths.
The above works for urls like /login, /auth but when i run urls like
/administrative/uom
It fails
SO basically i want all urls to be redirrected via site/index but all urls having api as the prefix like api/auth/login to be run via their respective controllers.
I have added an api module which should handle this.
What else do i need to add to make this work?
When adding rules always start from more detailed to less detailed. And you added general rule for controller only so no URL with action is matched. Do this
'rules' => [
'api/<controller:\w+>/<action:[\w\-]+>' => 'api/<controller>/<action>',
'<controller:[\w\-]+>/<action:[\w\-]+>' => 'site/index',
'<controller:[\w\-]+>/' => 'site/index',
],
I have an old website, now I have written it with new version of yii framework and I want change the urls, but because of SEO problems I want to keep my old urls.
Now when the user enters www.mysite.pre/car/details/10908 I want application renders www.mysite.pre/site/show_detail/10908 how could I handle it in yii2 Routing?
Assuming you have got this action in your SiteController class
public function actionShow_detail($id) {}
Add this in your configuration file:
// ...
'components' => [
// ...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
// ...
'car/details/<id:\d+>' => 'site/show_detail',
],
],
],
More details and information about Yii 2 routing can be found in "Routing and URL Creation" section of The Definitive Guide to Yii 2.0.
I am building my website with Yii2 advanced template. The URL is rewritten into
localhost:9001/projectyii/page/index/#/demo
(page is controller, index is action, /#/demo is just a route for AngularJS on frontend)
Everything works fine on my localhost. When I upload it into my server, whenever if I hit the URL has prefix example.com/projectyii/, it will throw the following exception
ReflectionException
Class yii\web\urlManager does not exist
1. in /home/scott/public_html/projectyii/vendor/yiisoft/yii2/di/Container.php at line 415
406407408409410411412413414415416417418419420421422423424 * #return array the dependencies of the specified class.
*/
protected function getDependencies($class)
{
if (isset($this->_reflections[$class])) {
return [$this->_reflections[$class], $this->_dependencies[$class]];
}
$dependencies = [];
$reflection = new ReflectionClass($class); // error here
I notice that there are some other websites that have been running on same server already (they are all using Yii 1.1.13) and they have been working without problem, such as
example.com/project1/
example.com/project2/
...
it's just failed just this new site in Yii2.
The setting is under of components on /frontend/config/main.php is
'urlManager' => [
'class' => 'yii\web\urlManager',
'baseUrl' => $baseUrl,
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
]
The error told that it could not find the urlManager class, but the class does exist, the namespace is fine because I DO NOT modify anything on the vendors folder where contains that urlManager class.
I do not understand what I am missing here. Any help is appreciated! Thanks
Linux like other unix systems are case sensitive you should use:
'class' => 'yii\web\UrlManager', instead of urlManager
I'm following the method described here to have my control panel in backend folder.
The problem is I don't want to create two assets folders so I want to set assetManager baseUrl property in my backend/config/main.php but I'm enable to get the URL of the backend in the config. I don't want it hard coded because I need the code to be portable.
What can I do?
Thanks.
You can configure asset manager's baseUrl in /backend/config/main.php
'components' => array(
...
'assetManager' => array(
'class' => 'CAssetManager',
'baseUrl' => 'frontend.assets'
),
...