I have add the following code in custom-config.php of yii
'modules' => array(
'admin' => array(
'modules' => array(
'slider',
'siteSettings' =>[
'defaultController' => 'default',
],
'menu' =>[
'defaultController' => 'index',
],
'page' =>[
'defaultController' => 'index',
],
'partner' =>[
'defaultController' => 'index',
],
'blog' =>[
'defaultController' => 'index',
],
'feature' =>[
'defaultController' => 'index',
],
'user' =>[
'defaultController' => 'index',
],
'testimonial' =>[
'defaultController' => 'index',
],
'subscription' =>[
'defaultController' => 'index',
]
),
'defaultController' => 'dashboard',
),
),
But when I am trying to access site.com/admin it shows This page isn’t working. My php version is 7.4 and it is running in apache.
Please suggest me a solution.
Related
i want to specify that i have almost no experience with php and yii framework
I am trying to setup a classified ads website with yii ,but after i did some seo audit i realised that almost all of my category pages have duplicates like this :
example.com/category?slug=cars -this url is a duplicate that i don't want
example.com/category/cars -this is the url that i want to have
This is my urlManager code :
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'search' => 'site/search',
'contact' => 'site/contact',
'<controller:conversation>/<action:delete>' => '<controller>/<action>',
'<controller:conversation>/<action:reply>/<conversation_uid:[a-z0-9_\-]+>' => '<controller>/<action>',
'<controller:account>/<action:invoices>/<page:\d+>' => '<controller>/<action>',
'<controller:account>/<action:conversations>/<page:\d+>' => '<controller>/<action>',
'<controller:listing>/<action:index|update|package|preview>/<slug:[a-z0-9_\-]+>' => '<controller>/<action>',
'page/<slug:[a-z0-9_\-]+>' => 'pages/index',
'<controller:category>/<action:location|map-view|get-map-location>' => '<controller>/<action>',
[
'pattern' => 'category/<slug:[a-z0-9_\-]+>/<page:\d+>',
'route' => 'category/index',
],
[
'pattern' => 'category/<slug:[a-z0-9_\-]+>',
'route' => 'category/index',
],
[
'pattern' => 'category/map-view/<slug:[a-z0-9_\-]+>/<page:\d+>',
'route' => 'category/map-view',
],
[
'pattern' => 'category/map-view/<slug:[a-z0-9_\-]+>',
'route' => 'category/map-view',
],
[
'pattern' => 'store/<slug:[a-z0-9_\-]+>/<page:\d+>',
'route' => 'store/index',
],
[
'pattern' => 'store/<slug:[a-z0-9_\-]+>',
'route' => 'store/index',
],
'<url:.+/>' => 'site/redirect'
],
],
If you need any further detailes or specific code ask me and i will try to provide !
Thanks
There are two types of users in the application I am developing. Users (table users.sql) for frontend users and AdminUsers (table admin_users.sql) for administration.
In CakePHP3, I solved this problem as follows with AuthComponent in AppController:
public function initialize()
{
parent::initialize();
// ...
//user login
if (!empty($this->request->params['prefix']) AND
$this->request->params['prefix'] == 'admin'
) {
$this->setAdminLogin();
}else{
$this->setUserLogin();
$this->Auth->allow();
}
// ...
}
//frontend users
public function setUserLogin()
{
$this->loadComponent('Auth', [
'authorize' => ['Controller'],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
],
'loginRedirect' => [
'controller' => 'Users',
'action' => 'edit'
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'login'
],
'authError' => false,
'authenticate' => [
'Xety/Cake3CookieAuth.Cookie' => [
'userModel' => 'Users',
'scope' => ['Users.active' => 1],
'fields' => ['username' => 'email','password' => 'password'],
],
'Form' => [
'userModel' => 'Users',
'scope' => ['Users.active' => 1],
'fields' => ['username' => 'email','password' => 'password'],
'passwordHasher' => [
'className' => 'Fallback',
'hashers' => ['Default']
]
],
],
'storage' => ['className' => 'Session', 'key' => 'Auth.User']
]);
}
//admin users
public function setAdminLogin()
{
$this->loadComponent('Auth', [
'authorize' => ['Controller'],
'loginAction' => [
'controller' => 'AdminUsers',
'action' => 'login',
],
'loginRedirect' => [
'controller' => 'AdminHelps',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'AdminUsers',
'action' => 'login'
],
'authError' => false,
'authenticate' => [
'Form' => [
'userModel' => 'AdminUsers',
'scope' => ['AdminUsers.active' => 1],
'fields' => ['username' => 'email','password' => 'password'],
'passwordHasher' => [
'className' => 'Fallback',
'hashers' => ['Default']
]
],
],
'storage' => ['className' => 'Session', 'key' => 'Auth.AdminUser']
]);
}
How can I do the same thing in CakePHP4 version with Authentication plugin? How can I create multiple user login?
I have this auth in me appController
$this->loadComponent('Auth', [
'authorize' => ['Controller'],
'authenticate' > [
'Form' => [
'fields' => [
'username' => 'username',
'password' => 'password'
],
'finder' => 'auth'
]
],
'loginRedirect' => [
'controller' => 'Centros',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'login',
'home'
]
]);
But i want use other auth in other login, i tried this but always return false but idk why.
$this->loadComponent('Auth', [
'authorize' => ['Controller'],
'authenticate' > [
'Form' => [
'userModel'=>'Personas',
'fields' => [
'username' => 'username',
'password' => 'password'
],
'finder' => 'auth'
]
],
'loginRedirect' => [
'controller' => 'Usuarios',
'action' => 'index'
],
'logoutRedirect' => [
'controller' => 'Personas',
'action' => 'login',
'home'
]
]);
In the latter case, if I change personas for user it works but not with personas.
how to change default language from en to another language
$config = [
'on beforeAction' => function ($event)
{
Yii::$app->language = 'fa';
},
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'language' => '/fa',
'components' => [
'jdate' => [
'class' => 'jDate\DateTime'
],
'mycomponent' => [
'class' => 'app\components\MyComponent',
],
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '******',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'urlManager' => [
'class' => 'codemix\localeurls\UrlManager',
// Disable index.php
'languages' => ['fa', 'en'], // List all supported languages here
'showScriptName' => true,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
// '' => 'site/index/fa',
// '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
// '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'params' => $params,
];
this is my $config in web.php
i want set default to 'fa' in root site !
my site automatic change lang to 'en' in first time in any browser!
i try to change lang with
'on beforeAction' => function ($event)
{
Yii::$app->language = 'fa';
},
but that is dosent correct work!
Remove this ridiculous 'on beforeAction' thing and just set
'language' => 'fa', // NOT '/fa'!
سلام
ویدئو های آقای صیف زاده رو مشاهده کردین؟
لینک زیر آموزش های ویدئویی ایشون هست . در شماره های 17 و 18 و 19
این موضوع رو آموزش دادن.
https://drive.google.com/drive/folders/0B4ZlNlar4Ij6XzJrbVZOejRCcGM
HI I just discovered Yii framework and I need some guidelines to implement this...
Yii2 RBAC - Official Guide
...in my RESTful app. I know I have to override the method [checkAccess][3]() in my controllers but I can't found any example. My API has token based Beare autentication and sessions are disabled (stateless).
In your controller:
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => CompositeAuth::className(),
'authMethods' => [
HttpBearerAuth::className(),
],
];
// add CORS filter
$behaviors['corsFilter'] = [
'class' => Cors::className(),
'cors' => [
'Origin' => ['*'],
'Access-Control-Request-Method' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
'Access-Control-Request-Headers' => ['*'],
],
];
// avoid authentication on CORS-pre-flight requests (HTTP OPTIONS method)
$behaviors['authenticator']['except'] = ['options', 'login', 'signup'];
$behaviors['access'] = [
'class' => AccessControl::className(),
'only' => [
'update',
'delete',
'view',
'index',
],
'rules' => [
[
'actions' => [
'update',
'delete',
'view',
'index',
],
'allow' => true,
'roles' => ['#'],
],
],
];
$behaviors['verbFilter'] = [
'class' => VerbFilter::className(),
'actions' => [
'signup' => ['POST'],
'login' => ['POST'],
'update' => ['PUT'],
'delete' => ['DELETE'],
'view' => ['GET'],
'index' => ['GET'],
],
];
return $behaviors;
}