Invalid Alias in Yii - php

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.

Related

link a bootstrap to a certain module

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.

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';
}

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

Problem related to Creation of folder inside the application folder and access its classes in Zend-Framework?

I have following structure in my Zend-Project :
-application
- PDF
- configs
- controllers
- models
- views
- Bootstrap.php
-library
-public
-tests
I have created a new folder PDF inside application folder. And I have write some classes inside it[PDF].
What I want is to access this classes inside the indexAction() of the IndexController, but it showing an error like :
"Class 'Application_PDF_FormDocument' not found in D:\xampp\htdocs\zendapp\application\controllers\IndexController.php on line 13"
What may be the possible reason?
Please provide some help.....
Thanks In Advance......
I agree with ChanibaL regarding the naming of your classes. you should be naming it PDF_FormDocumnet.
Next, in application.ini, regerster the namespace:
autoloaderNamespaces[] = "PDF_"
Lastly, in your index.php make sure you are adding it to the include path:
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH),
get_include_path(),
)));
That should do the trick
If you have a standard autoloader in your application, the class name should be PDF_FormDocument (no Application_ part!) in the file application/PDF/FormDocument.php
If this doesn't help by itself try adding
protected function _initAutoload() {
$autoloader=new Zend_Application_Module_Autoloader(array(
'namespace' => 'PDF',
'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'PDF'
));
to application/Bootstrap.php

Categories