Trying to access locally http://mysite.dev/gii but I'm getting:
Gii Unable to resolve the request "gii/index"
Here is my config/localdev.php file:
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>false,
// If removed, Gii defaults to localhost only.
'ipFilters'=>array('127.0.0.1','::1'),
),
If I use this address:
http://mysite.dev/gii/default/login
But this a password protect one, and we defined as false.
We may think that localdev.php is NOT being applied, but I've echo "hello" inside the conditional that loads it, and it appeared".
Note:
Inside Yii framework there is a .htaccess file with:
deny from all
I don't see the reason for this behavior.
Can I have your help please ?
Update regarding the comments:
Here's the localdev.php requiring main.php
return CMap::mergeArray(
require_once(dirname(__FILE__).'/main.php'),
array(
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>false,
'ipFilters'=>array('127.0.0.1','::1'),
),
),
Here's the URL on main.php
'components'=>array(
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>'=>'<controller>/index',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
),
'showScriptName'=>false,
),
IF we should add those:
'rules'=>array(
'gii'=>'gii',
'gii/<controller:\w+>'=>'gii/<controller>',
'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>',
Should I add this and place all that it's on main.php rules OR, can we precisely add just those rules here on localdev.php ?
You should add the routes that service Gii to your app configuration as mentioned in the manual.
Related
I have one question:
my website would be localhost/carfinancing/index.php
I have different index.php page right now which is in HTML5 template and Yii is installed in "application" directory.
When I copy paste this directory then localhost/carfinancing/application/web/ shows my yii index page and localhost/carfinancing/application/web/online-car-loan-application shows another page.
Is there way for yii index file to show: localhost/carfinancing/application and for another page, to show: localhost/carfinancing/online-car-loan-application ?
I mean to remove the '/web/' word from the url?
It looks like you have 2 questions here. I will work on answering both.
1 Your HTML5 template should be a view file in the views/[controller name]
Since Yii2 is an MVC framework it is designed to have all requests come to a controller which then provides a view. If you are placing files in web to be viewed directly you are losing out on the benefits of MVC.
2 In order to remove the web/ directory from the URL, you will need to use the url manager.
Add the urlManager in the component of the config/web.php
$config = [
...
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
You will also want to setup your .htaccess as follows:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Then move everything out of the public_html directory, and put everything that is in the web directory back in public_html.
Reference this article if you are still having issues: http://fellowtuts.com/yii/hide-or-remove-basicweb-from-url-in-yii-2-0/
I am trying to translate my URL, depending on the language selected by the user, e.g.:
www.example.com/en/discover or
www.example.com/fr/decouvrir
Obviously I want the two URL to point to the same page (where PHP handles the translation with a dictionary). I was wondering if there was a smart way in the htaccess file to do this "automatically" without having the write the rule for all the pages? For the moment I would do
RewriteRule ^en/discover$ discover.php?lang=en [NC,L]
RewriteRule ^fr/decouvrir$ discover.php?lang=fr [NC,L]
but this solution is not really the easiest if there are a lot of pages and if I want to add another language.
Thanks a lot for your help
You should pass all arguments to single php file (dispatcher), whitch would translate route and then include needed file. Something like:
.htaccess
RewriteRule ^(.*)/(.*)$ index.php?lang=$1&include=$2 [NC,L]
PHP
// This is really bad code, just an example
$dictionary = array(
'en' => array(
'discover' => 'discover'
),
'fr' => array(
'decouvrir' => 'discover'
)
);
echo $dictionary[$_GET['lang']][$_GET['include']];
In file config main.php:
'/my-acc/<slug:.*>' => 'user/profile/<slug>',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
But, when I create URL:
Yii::app()->controller->createUrl('user/profile', array('slug'=>'acc1');
Returns the result mydomain/user/profile?slug=acc1, without mydomain/my-acc/acc1.
Can somebody help me?
I think this should works:
'my-acc/<slug>' => 'user/profile',
Try this in urlManager rules
'my-acc/<slug:[a-zA-Z0-9-_]+>' => 'user/profile',
Modify regular expression according to your need.
To allow only digits
'my-acc/<slug:\d+>' => 'user/profile',
To allow string (without -,_)
'my-acc/<slug:\w+>' => 'user/profile',
if the above two answer works ,then ignore , other wise try this ,
have you added .htaccess file in this path ? , move the .htacess file where the root directory( .index.php file exist )
www
- index.php
- .htaccess
and in main.php file
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
...,
),
I've got urlManager rules:
...
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'page/page/show',
...
all fine.
When I enter to address
/nasha-glavnaya-zagolovok
it opens the page i need
But if I try to open page
/pages/nasha-glavnaya-zagolovok
it also opens the page I need
But content of pages are same.
How i can redirect (with 301 header) from route to pattern if any rule in urlManager mathced?
i cannot give you the complete answer, but you can work make it work like this...
you can use a rule that sends the request to an action which job is just to redirect using CController::redirect()
replace this
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'page/page/show',
with this
'/<slug:(nasha-glavnaya-zagolovok)>' => 'page/page/show',
'/pages/<slug>' => 'site/redirect',
and redirect the user to /$slug in the 'site/redirect' action
update: you can make it work by writing a new url rule which extends CBaseUrlRule, not sure if you care to take the time to do that if this is the only redirect you want to do though
I need to redirect help.mydomain.com/a-page to /pages/a-page without using Nginx or Apache redirects and only through Rails 3 routes.
The key here is the help subdomain determining that /pages/ should be dropped from the route although the view is under the /views/pages/
Any help is appreciated.
Try this:
match "/:page_name" => redirect("/pages/%{page_name}"), :constraints => { :subdomain => /help/ }