Yii 1.1.7 - cannot find gii page - php

I want to use Gii in Yii. My protected/config/main.php for my first webapp has this part uncommented, as instructed in the Yii documentation to enable Gii (123.45.67.123 is my public IP address from the computer I am trying to access):
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123456',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('123.45.67.123','127.0.0.1','::1'),
),
),
I also have the urlManager enabled in my protected/config/main.php by uncommenting the below:
// uncomment the following to enable URLs in path-format
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
When I go to my Yii site, for example, www.example.org, the basic Yii page is loaded fine. When I do www.example.org/gii, I get a 404. When I go to www.example.org/index.php?r=gii, I get a 404. Why is my Gii page not found? I am using CentOS 5.6.

Try:
http://www.example.org/index.php/gii
It seems you have the same rules as I do for url. If http://www.example.org brings you to your main yii webapp page then the above link should work.
You were going to http://www.example.org/gii which is incorrect.

Im using urlManager like this for gii
'urlManager'=>array(
'urlFormat'=>'path',
'cacheID' => false,
//'caseSensitive' => true,
'showScriptName' => false,
'urlSuffix' => '/',
'rules'=>array(
'gii'=>'gii',
'gii/<controller:\w+>'=>'gii/<controller>',
'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>',
...
and it doesn't conflict with routes for other site pages

Can you post your entire urlManager block with #briiC.lv's code incorporated? It should work, it's pretty much the same as mine:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array( // remove gii for production:
'gii'=>'gii',
'gii/<controller:\w+>'=>'gii/<controller>',
'gii/<controller:\w+>/<action:\w+>'=>'gii/<controller>/<action>',
'site/index'=>'/',
'<controller:\w+>'=>'site/<controller>',
'<filter:(proj|dept)>/<id:\d+>'=>'site/',
),
'showScriptName'=>false,
),
If it still doesn't work, you might also want to post/link to your complete main.config file.

Have you tried with the urlManager desactivated? Just to see if gii itself it's working

If you have mod rewrite enabled and want to place the following in your htaccess file
php_value upload_max_filesize 1M
DirectoryIndex index.php
Options +FollowSymlinks
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
and add the following to the 'urlManager' array in your config/main.php file:
'showScriptName'=>false,
Will remove the index.php from your url and make sure to only display urls in the form of domain.com/controller/action

I wasn't able to access www.example.org/gii until I added the following in my vhost config
<Directory /path/to/web/root>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

i have just had the same problem with the URL and Gii and i found out that i had written not the right IP Address. When i changed to the right one from the Network Statistics and then added the IP to the ipFilters of GII.
Hope that helps!

Related

How can I hide the index.php file for yii in apache/.htaccess/mod_rewrite?

I have this htaccess file:
RewriteEngine on
#if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
And I'm using Yii 1.1.15 (this site was taken from 1.1.13 version but such version is not available anymore for download, so I'm using it in a 1.1.15 framework install - althought it has no problem as far as I can see), having a conf/main.php file like:
<?php
return array(
'basePath'=>dirname(dirname(__FILE__)),
'name'=>'Grand Duval - Códigos premiados',
'defaultController'=>'participantes/create',
'language'=>'es',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'mypassword',
'ipFilters'=>array('127.0.0.1', '::1'),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=mydatabase',
'emulatePrepare' => true,
'username' => 'sbuser',
'password' => 'dbpassword',
'charset' => 'utf8',
),
'errorHandler'=>array(
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster#example.com',
),
);
The important part here is:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
Such config is intended - and does work like that - to generate absolute urls like http://www.mydomain.dev/controller/action for controller controller and action action.
I have the problem with the .htaccess file: If I try to hit http://www.mydomain.dev/controller/action, the url is not found. However if I hit http://www.mydomain.dev/index.php/controller/action it is found. It looks that .htacccess has no effect at all (It is the exact same if I delete the .htaccess file).
Q: what am I doing wrong?
I think you need to enable mod_rewrite try:
a2enmod rewrite
Then just restart your server.
I found the answer. After ensuring that mod_rewrite was active for my other sites I asked myself: Is my .htaccess being recognized?
So i wanted to force a 500 error by corrupting my .htaccess file:
RewriteEngine on
# if a directory or a file exists, use it directly
TryToForceA500
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
And no error was triggered! So I asked myself -again-: Why isn't it being recognized? and checked my site .conf file and found:
AllowOverride none
And changed to:
AllowOverride all
(this is just a dev server, so that setup is fine for me)
And then the file was recognized and worked!

YII URL how to generate new URL

I have one site in which I want URL like SiteURL/about.html.
I have changed code in config/main.php but when I login to site then gets session expired when I navigate to any other page.
If comment this code 'showScriptName'=>false in config/main.php file, then its work fine and now my login session is saved and us not expired however now my URL is becoming like this SiteURL/index.php/about.html
But I want URL like about.html.
I have also one another controller for game option which URL is like: http://www.demo.com/index.php/Games/info/9.html but I want URL like SiteURL/black-hook.html in this "black-hook" is the name of the game.
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>FALSE,
'rules'=>array(
'<action>'=>'site/<action>',
'<view>'=>'array('site/page')',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
),
),
*SiteURL = http://www.demo.com
First to get .html appended to your pages you need to use fake url suffix option in urlManager
This can be done by adding 'urlSuffix' =>'.html' to your urlManager config like this
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'urlSuffix'=>'.html',
'rules'=>array(
'<action>'=>'site/<action>',
'<view>'=>'site/page',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>'
),
),
Secondly for hiding index.php (called the entry script) in your URL in addition to changing configuration here you need to change configuration in your apache/nginx server.
Create the file /.htaccess with the following content and save it
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
Next verify if the AllowOveride All is there for your app directory in your apache configuration file You can also add the above configuration directly to your apache configuration file using Directory element without using .htaccess .
Note: For this to work you need to have rewrite engine enabled in apache config, You can do so with the following set of commands
a2enmod rewrite
Finally Restart apache2 after
/etc/init.d/apache2 restart
or
service apache2 restart

Yii2 Custom url management. Getting 400 error

Well, PHP times.
My client wants me to use Yii2 as the framework for his project.
I got it up and running. No problem. I used the advanced template via composer.
Set my web root to /frontend/web, etc.
NOW, i want to use this url format
website.com/messages/ or website.com/messages/tom... etc.
Right now the way is setup shows website.com/index.php?r=messages/index...
I found this documentation...
https://github.com/yiisoft/yii2/blob/master/docs/guide/url.md
But i can't seem to get it straight.
Here are my steps...
I configured my apache server to point to /usr/www/payroll/frontend/web/
I added to my web folder a .htaccess file with this content.
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
I also added the component 'urlManager' as in the directions. It seems to catch the request and modify it.
'components'=>[
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => 'false'
],
],
For example if I type website.com you can see it adds /site/index to the url. (without the url component active it simply adds /index.php?site/index)
So, obviously there's a modification perfomed to the url (via UrlManager) but I get 404 error
I am running out of ideas here. I am new to Php, Apache and Yii2. Any help, Greatly appreciated.
Thanks
To make pretty URL working on Yii 2.0 you need 2 things:
1: Edit /frontend/config/main.php (or the appropriate main config in your case) and add:
'components'=>[
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
],
],
2: Add a .htaccess file in YOUR WEB ROOT folder.
In yii 2.0 advanced this is NOT project root directory but instead:
/frontend/web
.htaccess example:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
just change 'showScriptName' => 'false' to 'showScriptName' => false and it will work
Ok, here is the solution.
In recents version of Apache (from 2.3.9), AllowOverride is set to NONE by default. Previous versions have AllowOverride set to ALL.
Yii2 assumes that AllowOverride will be set to ALL.
If you want to read the whole thread at Yii Forum, here is the link
http://www.yiiframework.com/forum/index.php/topic/53295-url-manager-for-seo-friendly-url-404-error-code/
Thank you for your help and messages!
For Yii2 basic, I just added the codes below to /myappfolder/config/web.php:
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName'=>false,
]
Also, added .htaccess in /myappfolder/web/ :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
This works well for me. Hope this helps others who have same problem. : )
If you want to use like this http://domain.com/controller_name/action_name , you only need to enable pretty url in your config file :
'components'=>[
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => 'false'
],
],
Now you can use urls as you wish `website.com/messages/ or website.com/messages/tom.
If you want to use query string in your url this is how it works now in Yii 2 website.com/message?id=12

Kohana 404 error: Requested URL not found

.
Hi everyone,
I'm working on a website for a school project.
Recently I've purchased me own webspace at Biberbit.com and wanted to upload my website.
When I upload it I see the following error on screen:
Kohana_HTTP_Exception [ 404 ]: The requested URL / was not found on this server.
My project uses the Kohana framework version 3.3.1
I already have the .htaccess file and the filenames/directory names are all lower case.
I am using the default route:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
Originally I thought it might have been the default_url in the bootstrap.php file so I've changed those lines to this:
Kohana::init(array(
'base_url' => '/',
'index_file' => FALSE,
));
I've looked for the solution on multiple websites and couldn't find one that works for me.
Can anyone think of something that I might be missing?
I'm also using URL::site() for my links so I don't think that's causing it.
You can check the error and/or website at http://www.biberbit.com
EDIT:
.htaccess as requested
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect hidden files from being viewed
<Files .*>
Order Deny,Allow
Deny From All
</Files>
# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]
The base_url is set wrong, it should be empty (as you are on the web root). Also depending on whether or not you have Linux, filenames must not be all lowercase but however you use them in the code. So Welcome.php and not welcome.php for the default controller.
Kohana_HTTP_Exception [ 404 ]: The requested URL / was not found on this server. exception is usually thrown when Kohana couldn't find corresponding action method to process a request.
Make sure you have Controller_Welcome class and action_index method in it.
Also you can inspect your Exception traceback and find what exactly caused an Exception. Most likely you'll see Exeption in SYSPATH/classes/Kohana/Controller.php file in if(!method_exists(...)) block.

Yii can't start gii

I am developing website with PHP Yii Framework and I am now stack, I need to start gii, but I can't do this. when i type www.example.com/index.php/gii or www.example.com/gii it gives me this error :
/gii/default/login // <- website redirects to here
This webpage has a redirect loop
The webpage at http://www.example.com/gii/default/login has resulted in too many redirects.
Clearing your cookies for this site or allowing third-party cookies may fix the problem.
If not, it is possibly a server configuration issue and not a problem with your computer.
I don't think that the error is because of modified htaccess and main configuration, but anyway here is main.php configuration file:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'site/page/<view:\w+>'=>'site/page',
'<controller:\w+>/<cact:\w+>/<action:\w+>'=>'<controller>/<cact>',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
and .htaccess :
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
#non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# 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 [L]
So can you help me, please?
To use this path: index.php?r=gii/default/login , you must turn OFF the url manager in /protected/config/main.php
Also check urlManager's rules. That was the issue for me:
'components' => array(
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
// ...
// will handle `gii/default/login` uri and makes infinite redirection loop circle
'<controller:\w+>/<action:\w+>/<sub_action:\w+>'=>'<controller>/<action>',
// ...
),
),
),
Check if the gii module in your configuration file is there and it is uncommented.
If gii is not in there you should add it within the module array.
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>***choose a password***
),
),
More info for gii here
Like FelikZ mentioned, this might be because you have created a third param in a rule that uses \w+ instead of the default \d+ and hence will match "gii" as the controller, "default" as the action and "login" as the ID (or sub action, or whatever is mentioned).
My rules looked like the following:
'<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
The fix is to add the following as the very first rule in order to make gii hit the right place:
'gii/<controller:\w+>/<action:[\w-]+>' => 'gii/<controller>/<action>',
Which should make your entire urlManager config look something like the following:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'gii/<controller:\w+>/<action:[\w-]+>' => 'gii/<controller>/<action>',
'<controller:\w+>/<action:\w+>/<id:\w+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
This problem occurs because of the two sessions of the OP, for example cookie PHPSESSID there two domains domain .site.ru and admin.site.ru two different sessions. Delete PHPSESSID cookies and login to gii

Categories