I am getting an HTTP 404 error when I try to rewrite my URL's in Yii with urlManager.
Here are two config formats I've tried in my main.php config file, one like 'pattern1'=>'route1' and the other in the new format array('route1', 'pattern'=>'pattern1'):
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'messageBulk'=>'message/apiBulk'
),
),
'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
array('message/apiBulk', 'pattern'=>'messageBulk')
),
),
What sort of urls are you looking to generate? Cos I'm a bit confused with the configurations you've got up there. At any rate, this is a template I use for my projects:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
// REST patterns
array('api/list', 'pattern'=>'api/v1/<model:\w+>', 'verb'=>'GET'),
array('api/view', 'pattern'=>'api/v1/<model:\w+>/check', 'verb'=>'GET'),
array('api/view', 'pattern'=>'api/v1/<model:\w+>/<id:\d+>', 'verb'=>'GET'),
array('api/create', 'pattern'=>'api/v1/<model:\w+>', 'verb'=>'POST'),
'<controller:\w+>/<id:\d+>/'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>/*'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>/*'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>/'=>'<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>/'=>'<module>/<controller>/<action>',
),
//'showScriptName'=>false,
),
I hope it helps you out.
Was writing the URL wrong, missing "index.php". Answer was in #ernie's comment.
What's the debug panel show? What URL are you trying to access with your rules? Does your yourwebsite.com/index.php/message/apiBulk work?
Related
On Yii 1.x
We found it quite difficult to implement a language selection option with Yii, so, we are using the following extension:
http://www.yiiframework.com/extension/langhandler/
Like so:
main.php URL Manager:
urlManager'=>array(
'class'=>'application.extensions.langhandler.ELangCUrlManager',
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<lang:(pt|en)>/<_c>/<_a>/' => '<_c>/<_a>',
),
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<controller:\w+>' => '<controller>/index',
),
When we click "en", instead of getting:
http://blabla.dev/experience/info/114?lang=en
We are getting:
http://blabla.dev/experience/info?lang=en
So the ID part of this url is being completely ignored.
Can anyone give us a hand here?
We have tried to change the rules to:
'<lang:(pt|en)>/<_c>/<_a>/<_i>/' => '<_c>/<_a>',
and a lot of other combinations, but that is just guessing.
I am newbie for Yii. I have created my separate login page in my controller. Here my question is "When
When session expires it will ask for re-login. and it will transfer to site/login page.
Instead of site/login I want to redirect it to xyz/login page. Where I have to change this?
change in the main.php
array(
// ......
'components'=>array(
'user'=>array(
'loginUrl'=>array('xyz/login'),
),
),
)
in your config/main.php,
'urlManager' => array(
...
'rules' => array(
'xyz/login' => 'site/login', // Add this
...
I've added bootstrap Extension To my yii webapp and installed as described in setup Guide. All Folders in Extension Folder are rwrwrw but i get the error written above. What could be the reason? I've already dumped the path from yii::Import and that path was correct.
Thanks!
Edit With Code
This is my config:
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
//Yii::setPathOfAlias('bootstrap', '/Users/gerritlober/Sites/yii/webapp/protected/extensions/bootstrap');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Carpool',
'theme' => 'bootstrap',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'xxx',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
'generatorPaths'=>array(
'bootstrap.gii',
),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// 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>',
),
),
/*
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),*/
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=carpool_dev',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'enableProfiling' => true,
),
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
array(
'class'=>'CWebLogRoute',
'categories' => 'system.db.*,GLWeb.*,application.*'
),
),
),
'bootstrap'=>array(
'class'=>'bootstrap.components.Bootstrap',
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster#example.com',
),
);
My bootstrap extension is in ./protected/extensions/bootstrap
I was having the same problem. I granted full(777) permission to the folder.
Try it.
Update Component By :
ext.bootstrap.src.components.Bootstrap',
EG: If you are extracted under extension then follow above command:
Syntax: ext.path_to.Bootstrap
You have two options. One, in your config/main.php file, or equivalent, add the following line:
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/yii-bootstrap');
Where you need to replace yii-bootstrap with whatever your bootstrap folder is actually called.
Or two, you can simply refer to the that bootstrap folder correctly in the first place. If your bootstrap installation is installed in /extensions/yii-bootstrap as mine is, then use this alias to load components:
ext.yii-bootstrap.components.Bootstrap
In short, your problem is likely you aren't defining the path to your installation correctly. Use one of the two above solutions so remedy that problem.
I am using MAMP pro with yii-1.1.12. and I am trying to install the latest version of yii-user-management.
My route for the webapp is
/Users/myname/Sites/yii-1.1.12/htdocs
I created the 'modules' folder and copied the yii-user-management into it:
htdocs > protected > modules
(modules and subfolders set to rewrite)
config/main.php
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'password',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
'modules' => array(
'user' => array(
'debug' => true,
)
),
),
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'class' => 'application.modules.user.components.YumWebUser',
'allowAutoLogin'=>true,
'loginUrl' => array('//user/user/login'),
),
'import'=>array(
'application.modules.user.models.*',
),
etc...
I have followed the instructions to the letter but when I call the user/install in the browser I get a 404 error.
http://yii.dev:8888/index.php/user/install
My page works okay http://yii.dev:8888/index.php/login (with or without index.php)
Very frustrating. Any help would be appreciated.
I just realized there's a problem with your config/main.php...
You have modules listed within modules:
'modules'=>array(
'gii'=>array(//...gii configuration...),
'modules' => array(
'user' => array(
'debug' => true,
)
),
It should just be:
'modules'=>array(
'gii'=>array(//...gii configuration...),
'user' => array(
'debug' => true,
)
),
Trying to work on a RESTfull API with yii (being the first project using yii)
Having problem with getting URLManager to properly route calls:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
'rules' => array(
'api/<controller>' => array('api/<controller>/list', 'verb' => 'GET'),
'api/<controller>' => array('api/<controller>/create', 'verb' => 'POST'),
),
),
Tried working with this (this is not the full snippet, I had dispatchers for PUT/DELETE etc..
But it did not work... Being desperate, I tried even something as simple as that:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
'rules' => array(
'tezt' => array('landing/beta', 'verb' => 'GET'),
'tezt' => array('landing', 'verb' => 'POST'),
),
),
whenever I remove one of the rules, it works, but when I put both the rules in, none of them works, I get exception
exception.CHttpException.404
exception 'CHttpException' with message 'Unable to resolve the request
"tezt".' in /yii-1.1.10/web/CWebApplication.php:280
Been banging my head agains this for 2 days now. Probably seen all the samples and tutorials on URLManager on the web (although could not find a straightforward and complete explanation of the rules). But, no joy.
Am I doing something wrong? Is it my box setup maybe?
I tried this and it worked:
'rules'=>array(
//API URLs
array('api/<controller>/index', 'pattern'=>'api/<controller:\w+>', 'verb'=>'GET'),
array('api/<controller>/create', 'pattern'=>'api/<controller:\w+>', 'verb'=>'POST'),
array('api/<controller>/view', 'pattern'=>'api/<controller:\w+>/<id:\d+>', 'verb'=>'GET'),
array('api/<controller>/update', 'pattern'=>'api/<controller:\w+>/<id:\d+>', 'verb'=>'PUT, POST'),
array('api/<controller>/delete', 'pattern'=>'api/<controller:\w+>/<id:\d+>', 'verb'=>'DELETE'),
//Other URLs
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
"api" is a module configured in modules section as
'api'=>array('defaultController' => 'default',),
In REST client, you have to specify controller name, even for default controller.
I am using Yii 1.1.10 but I think Yii supports RESTful URLs since 1.1.7.
try this
'api/<controller:\w+>' => array('api/<controller>/list', 'verb' => 'GET'),
is api a module?
For anyone else who stumbles on this, it didn't work because the rules were declared using the same keys, so the latter rule overrode the former.
In the future, declare the pattern in the rule configuration array:
array(
'route',
'pattern' =>'somePattern',
'verb' =>'...',
),
array(
'another/route',
'pattern' =>'anotherPattern',
'verb' =>'...',
),