Related
I have following file structure
As default the url created for accessing the module content is for example
http://127.0.0.1/tmc/user/default/viewMessage
and for other controller it comes out to be
http://127.0.0.1/tmc/user/booking/index
The problem is I want to write a rule in my urlManager so that both controllers remain accessible AND i do not see default word in url as in first example.
However if i write following rules I am able to eliminate the default word but now other controllers in same module wont work. any help in this regard is appreciated
'<module:\w+>/<action:\w+>/<id:(.*?)>' => '<module>/default/<action>/<id>',
'<module:\w+>/<action:\w+>' => '<module>/default/<action>',
My current Url Manager is as follow
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'/' => 'site/index',
'login' => 'site/login',
'user' => 'user/default/',
'<view:[a-zA-Z0-9-]+>/' => 'site/page',
),
),
Follow this Link for config settings
Refer this Link
//inside protected/modules/admin/AdminModule.php
class AdminModule extends CWebModule
{
//goes to TaskController instead of DefaultController
public $defaultController = 'Task';
...
Now your Yii application will routes to the “TaskController” if you request
index.php?r=admin
//same as requesting
index.php?r=admin/task
I'm trying to setup hybrid auth on the Yii user management addon, the docs are here https://github.com/thyseus/yii-user-management/blob/master/user/docs/hybridauth.txt
according to this step
Take the modules/user/vendors/index.php, rename it to 'hybridauth.php' and place it
beside your application index.php bootstrap script. This will be your hybrid auth
entry script.
for this, there is NO index.php file in modules/user/vendors/index.php but there is one in modules/user/vendors/hybridauth/index.php which i renamed to hybridauth.php and put it in http://localhost/dev/ content of the hybridauth.php are
require_once( "protected/modules/user/vendors/hybridauth/Hybrid/Auth.php" );
require_once( "protected/modules/user/vendors/hybridauth/Hybrid/Endpoint.php" );
Hybrid_Endpoint::process();
now for this
Place the hybrid auth configuration file into your application
protected/config/hybridauth.php.
i took my modules/user/vendors/hybridauth/config.php and put it in protected/config/ and renamed config.php to hybridauth.php. the content looks like this
return
array(
"base_url" => Yii::app()->createAbsoluteUrl('/').'/hybridauth.php',
"providers" => array (
...........
"Google" => array (
"enabled" => true,
"keys" => array (
"id" => "ID",
"secret" => "SECRET",
),
),
"Facebook" => array (
"enabled" => true,
"keys" => array (
"id" => "ID",
"secret" => "SECRET",
),
"scope" => "email,user_birthday" // https://developers.facebook.com/docs/reference/login/
),
),
// if you want to enable logging, set 'debug_mode' to true then provide a writable file by the web server on "debug_file"
"debug_mode" => false,
"debug_file" => "",
);
problem is when i click say on the facebook icon on my login page, it shows my main page. (index.php)
here is the link it directs too
http://localhost/dev/index.php/hybridauth.php?hauth.start=Facebook&hauth.time=1388044835
when i remove the index.php from the url
http://localhost/dev/hybridauth.php?hauth.start=Facebook&hauth.time=1388044835
i get this error
You cannot access this page directly.
any idea what i'm doing wrong? Thanks
This sound like a routing problem in your configuration:
you might want to add a route for hybridauth.php and make sure it is only accessable by GET
for example :
'components'=>array(
......
'urlManager'=>array(
'showScriptName' => false,
'urlFormat'=>'path',
'rules'=>array(
'hybridauth'=>array('user/hybridauth/index', 'verb'=>'GET', 'urlSuffix'=>'.php'),
....
),
),
),
if anyone having the same problem, here is how i solved it:
by changing the base_url to point to the actual php file:
"base_url" => Yii::app()->getBaseUrl(true).'/hybridauth.php',
If you use YUM User Managment try to import
Yii::import('application.modules.profile.models.*');
on YumUserAuthController because profile cannot be found.
i'm new to yii and downloaded this extension
https://github.com/mishamx/yii-user
i've uploaded all the necessary files into the protected/ folder
but i keep getting this error. what am i missing?
Alias "user.UserModule" is invalid. Make sure it points to an existing PHP file and the file is readable.
/Applications/XAMPP/xamppfiles/htdocs/dev2/framework/YiiBase.php(322)
i edited my config/main/php which now looks like this
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// Define a path alias for the Bootstrap extension as it's used internally.
// In this example we assume that you unzipped the extension under protected/extensions.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../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 site',
'theme'=>'bootstrap', // requires you to copy the theme under your themes directory
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.modules.user.models.*',
'application.modules.user.components.*',
),
'modules'=>array(
// uncomment the following to enable the Gii tool
'gii'=>array(
'class' => 'system.gii.GiiModule',
'password' => 'gii', //Enter Your Password Here
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters' => array('127.0.0.1','::1'),
'generatorPaths' => array('bootstrap.gii'),
),
'user'=>array(
# encrypting method (php hash function)
'hash' => 'md5',
# send activation email
'sendActivationMail' => true,
# allow access for non-activated users
'loginNotActiv' => false,
# activate user on registration (only sendActivationMail = false)
'activeAfterRegister' => false,
# automatically login from registration
'autoLogin' => true,
# registration path
'registrationUrl' => array('/user/registration'),
# recovery password path
'recoveryUrl' => array('/user/recovery'),
# login form path
'loginUrl' => array('/user/login'),
# page after login
'returnUrl' => array('/user/profile'),
# page after logout
'returnLogoutUrl' => array('/user/login'),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'class' => 'WebUser',
),
'bootstrap' => array(
'class' => 'bootstrap.components.Bootstrap',
),
// 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=DBNAME',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
),
'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',
),
*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'admin#******.com',
),
);
?>
and this is my config/console.php file
<?php
// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
// preloading 'log' component
'preload'=>array('log'),
// application components
'components'=>array(
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=*****',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
),
'modules'=>array(
'user'=>array(
# encrypting method (php hash function)
'hash' => 'md5',
# send activation email
'sendActivationMail' => true,
# allow access for non-activated users
'loginNotActiv' => false,
# activate user on registration (only sendActivationMail = false)
'activeAfterRegister' => false,
# automatically login from registration
'autoLogin' => true,
# registration path
'registrationUrl' => array('/user/registration'),
# recovery password path
'recoveryUrl' => array('/user/recovery'),
# login form path
'loginUrl' => array('/user/login'),
# page after login
'returnUrl' => array('/user/profile'),
# page after logout
'returnLogoutUrl' => array('/user/login'),
),
)
);
if you are working with a linux enviroment, it's possible that your files do not have enough previlage to run files under users module directory.
try this to know if the problem is from here
chmod -R 777 /protected/modules/user/
not sure which version of yii-user you are using, but first download the latest version from here and follow the setting changes from that page too.
make sure you unzip all the files into protected/modules/user (NOTE: the modules and user folder doesn't exist so you will have to make one)
once done, insert items into zii.widgets.CMenu array (protected/views/layouts/main.php)
array('url'=>Yii::app()->getModule('user')->loginUrl, 'label'=>Yii::app()->getModule('user')->t("Login"), 'visible'=>Yii::app()->user->isGuest),
array('url'=>Yii::app()->getModule('user')->registrationUrl, 'label'=>Yii::app()->getModule('user')->t("Register"), 'visible'=>Yii::app()->user->isGuest),
array('url'=>Yii::app()->getModule('user')->profileUrl, 'label'=>Yii::app()->getModule('user')->t("Profile"), 'visible'=>!Yii::app()->user->isGuest),
array('url'=>Yii::app()->getModule('user')->logoutUrl, 'label'=>Yii::app()->getModule('user')->t("Logout").' ('.Yii::app()->user->name.')', 'visible'=>!Yii::app()->user->isGuest),
I don't know why, but I had also same issue after I loaded last version of yiibooster 4.0.1 version my issue solved by changing all "bootstrap" aliases with "booster" in all part of my application.
As example
'bootstrap' => array(
'class' => 'ext.yiibooster.components.Bootstrap',
),
with
'booster' => [
'class' => 'ext.yiibooster.components.Booster',
],
Also don't forget to use filter methods in all actions:
public function filters(){
return [
'accessControl',
'postOnly + delete',
['booster.filters.BoosterFilter - delete'],
];
}
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?
I have installed 1.1.9 Yii framework.Then I made copy paste user module in my application folder and made changes to my main.php file.After all the configuration when I browsed the app and used user/login to login into my application, it showed error like this
Alias "user.UserModule" is invalid. Make sure it points to an existing PHP file.
I have checked my main.php files many times.But why it is showing error like this?any help,suggestions will be highly appriciable.
Here is my main.php file code.
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
#user module starts
'application.modules.user.models.*',
'application.modules.user.components.*',
#user module ends
),
'modules'=>array(
'user'=>array(
'returnUrl'=>array('/site/index'),
),
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'XXXX',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
'loginUrl'=>array('/user/login'),
),
// 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=XXXX',
'emulatePrepare' => true,
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'tablePrefix'=> 'tbl_',
),
'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',
),
*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster#example.com',
),
);
I got the error. The user module should be made copy paste under protected directory.Not any other directory.
Do you have a custom user module class? Based on 'application.modules.user.models.*', it seems like you do. In that case I think you'll need to set the class in the module declaration as well.