link a bootstrap to a certain module - php

I have difficulty in connecting the bootstrap to a module. The bootstrap location is at: mainFolder/protected/extensions/bootstrap/theme/abound
protected/config/main.php
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
'modules'=>array(
'admin',
'consultant'=>array(
'preload'=>array('bootstrap'),
'components'>array(
'bootstrap'=>array(
'class'=>'bootstrap.theme.abound'
),
),
),
'candidate',
),
protected/modules/consultant/ConsultantModule.php
class ConsultantModule extends CWebModule
{
public function init()
{
$this->setImport(array(
'consultant.models.*',
'consultant.components.*',
));
Yii::app()->getComponent('bootstrap');
}
}
structure of the folder:
mainFolder
protected
config
**main.php**
extensions
bootstrap
assets
components
form
gii
theme
**abound**
widgets
modules
consultant
controllers
models
views
**ConsultantModule.php**
Error that I get when I run the code:
Property "ConsultantModule.0" is not defined.
Is it because the properties inside the module's consultant is wrong or the way I place the bootstrap is not correct? I can't figure out the problem.

Related

yii2 - RBAC - is it shared between backend and frontend?

I have just discovered and started using Role Based Access control.
Since I am using an advanced template for yii2, I am wondering if roles and permissions are shared between backend and frontend tiers or if they are separated.
For example
<?php
namespace app\commands;
use Yii;
use yii\console\Controller;
class RbacController extends Controller
{
public function actionInit()
{
$auth = Yii::$app->authManager;
// add "createPost" permission
$createPost = $auth->createPermission('createPost');
$createPost->description = 'Create a post';
$auth->add($createPost);
// add "author" role and give this role the "createPost" permission
$author = $auth->createRole('author');
$auth->add($author);
$auth->addChild($author, $createPost);
}
}
would author and createpost be available for both backend and frontend?
thank you!
The RBAC componet are base on common part .. typically if they are base on DB you use common models and shared the related db table ..
You can declare this element in component section of main.php in cofig area and if you do this in common dir this component si correctly shared between both the enviroment (frontend , backend) and eventually between all apps you distribute you projectc..
eg : common/config/main.php
'components' => [
.....
'authManager' => [
'class' => 'yii\rbac\DbManager',
'cache' => 'cache',
....
],
this mean they could be naturally shared between frontend and backend ..

Different interface layout for different level users in yii

I'm new to Yii. I'm developing a system with YII framework in PHP. How can I have a different layout for different module? I want the module A to have interface A, module B with interface B. But what I have know is that the interface login is the same for all module login. Can someone give me a light?
Update:
I found one way which is to include the:
$this->layout = $layout;
on the action function inside the controller before rendering the page. However, I found that it's not that efficient as on every action I need to repeat the line. Is there a way where we can do the setting on the config/main.php page? probably on this part:
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123',
'generatorPaths' => array('bootstrap.gii'),
),
'admin',
'consultant',
'client',
),
You can set variables for your module in your config like this:
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'123',
'generatorPaths' => array('bootstrap.gii'),
),
'admin' => array(
'layout' => 'your_layout' //The layout for this module
),
'consultant',
'client',
),
This way you can implement a default layout for every single module. Without having to add controller methods or variables.
For more info see the docs: here and here
try this:
class YourController extends Controller {
public $layout = 'your_layout';
}

Invalid Alias in Yii

I've created a module and in this module I have an Action. This is my module structure:
modules
admin
controllers
actions
In my main controller I have this code:
function actions()
{
return array(
'approveEntity' => array(
'class' => 'application.modules.admin.controllers.actions.ApproveEntityAction'
),
But when I run the page /pendingEntries/approveEntity
I get this error message:
Alias
"application.modules.admin.controllers.actions.ApproveEntityAction" is
invalid. Make sure it points to an existing PHP file and the file is
readable.
What is the correct "path" for my ApproveEntityAction.php file?
update
We are importing this:
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'application.controllers.plugins.*',
'application.components.widgets.*',
'application.helpers.*',
'application.forms.*',
First make sure that you have imported the path into your admin module file.
public function init() {
$this->setImport(array(
'admin.models.*',
'admin.components.*',
'admin.controllers.*' //importing all files situated in controllers directory
'admin.controllers.actions.*' //importing all files situated in actions directory
));
}
Then do like below:
public function actions(){
return array('approveEntity'=>'application.modules.admin.controllers.actions.ApproveEntityAction');
}
I think the key point was importing the directories that contain your action files.

YII Modules integration

I am new to YII frame work.
My directory structure is :
Protected >> Modules
I have 2 modules site, admin inside the modules folder
Each module have model, view, controller folders
Config is available inside the protected.
If i open siteurl/admin
then i need to call the admin controller inside the admin module
If i open siteurl/
then i need to calll the site controller inside the site module.
In config i can able to set the default controller. But depending on the url the controller need to change. How to implement this.
I tried the following code
'urlManager'=>array(
'urlFormat'=>'path',
//'showScriptName'=>false,
'rules'=>array(
'admin/' =>'admin/admin',
'admin/login' =>'admin/index/login',
'admin/logout' =>'admin/index/logout',
'admin/<controller:\w+>/<action:\w+>'=>'admin/<controller>/<action>',
I able to call either admin controller or site controller. How to do this. Please help me.
Example:
'rules' => array(
'admin/' => 'admin/admin',
//Call module "Admin" controller "Admin" action "Index" or Default action
'admin/<controller:\w+>/<action:\w+>' => 'admin/<controller>/<action>',
'' => "site/site/idex",
//If empty path call Modue site controller site action "index"
'<action:\w+>' => "site/site/<action>",
enter code here//If empty path call Modue site controller site action <action>
);

How to change Yii Error Handler on the fly?

In Yii's config.php we have this statement which declares which Controller is the default and only-one Error-Handler within the application:
'errorHandler' => array(
'errorAction' => 'site/error',
),
So, I need to have an actionError() under my SiteController, to get the errors previewed in my site, but this is not what I really need.
I am trying to change the Yii::app()->errorHandler->errorAction on the fly, throughout my custom-controllers who extend the base CController (Yii's base controller).
Till now, I have tried something like this:
<?php
class AdminController extends CController {
public $layout = '//layouts/admin';
public function init() {
parent::init();
Yii::app()->errorHandler->errorAction = '/admin/error';
}
}
But gives no results, nor hope. Note that I also have this URL configuration:
'/admin' => '/admin/home',
'/admin/<controller:\w+>' => '/admin/<controller>',
'/admin/<controller:\w+>/<action:\w+>/<id:\d+>' => '/admin/<controller>/<action>',
'/admin/<controller:\w+>/<action:\w+>' => '/admin/<controller>/<action>',
And this means I have a whole Controllers-Views group named admin, and they are stored in following directories:
protected/controllers/admin
protected/views/admin
So by that logic, I have ErrorController in both: admin and controllers root, and by the same structure in the views directory.
That's what I have tried, and I really appreciate help, so thank you all in advance!
You should try this :
Yii::app()->setComponents(array(
'errorHandler'=>array(
'errorAction'=>'/admin/error'
)
));
http://www.yiiframework.com/doc/api/1.1/CModule#setComponents-detail

Categories