app can't find module? - yii

I am working on a project. It was fine until I installed new windows on my PC. But now project is same and when I access
Yii::app()->controller->module
It returns null. It also returns null for: Yii::app()->controller->module->id. When I viewed config file it had admin module in it. I don't know why is it's returning null. Can't find a way out.
Module in config file is like:
'modules' => array(
// uncomment the following to enable the Gii tool
'admin',
'gii' => array(
'generatorPaths' => array(
'bootstrap.gii'
),
'class' => 'system.gii.GiiModule',
'password' => '1234',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters' => array('127.0.0.1', '::1'),
),
),

When you access Yii::app()->controller->module then it will return the module that current controller belongs to. It returns null if the controller does not belong to any module. Please make sure the current controller you accessed which is belong to any module you configured.
You can see this link: http://www.yiiframework.com/doc/guide/1.1/en/basics.module to work with Module.
If you want to see which modules are loaded then use:
print_r(Yii::app()->getModules());
You are not 'in' a module and want to get a specific module (like admin module): you can do
Yii::app()->getModule('admin');

Related

How to create a module that changes other modules' behaviors

I want to create a module for SocialEngine that changes the signup behavior by adding the option to signup using phone number and sending text message to the user's phone and letting them confirm it. I guess I need to add code in the file application/modules/User/Form/Signup.php. For example, I can add a new field as follows:
$this->AddElement('Text', 'sms', [
'class' => 'signup-name',
'label' => 'Phone Number',
'required' => true,
'validators' => [
['StringLength', true, ['min'=>11, 'max'=>11]]
]
]
);
$this->sms->getValidator('StringLength')->setMessage('Phone must be 11 digits');
However, I don't want to manually add the code. I need to add the functionality by installing the plugin and disable it by removing or disabling the plugin. How can I do that?
Do I need to mess with installation php scripts and do file operations like overwriting files or is there a better way to separate my files completely, meanwhile making them serve as a complement for a given module?

using yii rest api with default URL GET format rather than PATH format

I have a problem with a yii rest api. I configured it to work following the tutorial on the yii framework page, but after that i realised that my api works BUT NOT some big PORTIONS of my PAGE since it is based on the GET URL format rather than PATH which is required by the rest api.
So in my config/main.php i have the following setting
'urlManager' => array (
'urlFormat' => 'path',
'rules' => array (
'student/<id:\d+>/<title:.*?>' => 'student/view',
'students/<tag:.*?>' => 'student/index',
array (
'apistudent/register',
'pattern' => 'api/<model:\w+>',
'verb' => 'POST'
),
'<controller:\w+>/<action:\w+>' => '<controller>/<action>'
)
),
I also have a controller named ApiStudentController with a method called actionRegister().
So as already stated the api works normally but my page does not since i set the urlFormat to be 'path'.
The question is... how can i use the rest api but without the PATH url format and rather the default get url format (index.php?r=apistudent/register)?
I too faced the same problem in yii 1.x. I just need my API controller alone in old GET format rather than in PATH format (as i changed my websites URLs in PATH format). Finally i got it worked with a small hack in script file
$app = Yii::createWebApplication($env->configWeb); //store the app
//Change the UrlFormat for urlManager to get if a get request is given instead of a path format one.
if (isset($_GET['r'])) {
Yii::app()->urlManager->setUrlFormat('get');
}
$app->run(); //run the app
I dont know whether this solves your problem. But this can give you an idea. Happy Coding!

How to load module functions in custom Drupal theme

I'm not familiarly working with Drupal module. I installed,configured vegas module. There no problem in module. My actual question is how to i fetch module's PHP function in my custom.
For instance, vegas module only work on existing theme but it not working on my current theme (A known issue). I printed all images from inside vagas module and it gave me expected result.
print_r($backgrounds);
Array
(
[0] => Array
(
[src] => http://localhost/drupal/sites/default/files/vegas/slider1.jpg
)
[1] => Array
(
[src] => http://localhost/drupal/sites/default/files/vegas/slider1_0.jpg
)
[2] => Array
(
[src] => http://localhost/drupal/sites/default/files/vegas/slider1_1.jpg
)
)
My bad part is i cannot print that array inside my custom theme. How to get it.
Only the functions defined in module's .module file can be invoked from the theme. Please check if the function you are trying to use is in any other file of module.

Catalyst Framework HTML::Formhandler shows vadiate errors, when using HTML GET to Access the Site

I have an HTML::Formhandler Form on my Catalyst Framework. The Problem is, that I get an error-message in the Form, when I load the Form-Site with an HTML GET-Requelst.
has_field 'name' => (type => 'Text', required => 1);
So if I load the Site via: localhost:3000/form no errors occurs.
But if I load the Site via localhost:3000/form?foo=bar the form says: "Field required".
Any Idea how to solve this?
By default HTML::FormHandler determines whether to validate a from by the existence of params. If you don't want to do that, you can use the 'posted' flag in the ->process statement. If you want the query parameter to provide a default to the form, you need to pass it in via an init_object: init_object => { foo => bar }.

Yii multiselect widget

I have the following code that produces a jquery ech multiselect menu widget in Yii. (Eric Hynds multiselect).
I have downloaded the extension and unzipped in extensions folder
and my folder structure is My_lokal_Yii/protected/extensions/EchMultiSelect/EchMultiSelect
this is my view file code..
<?php $this->widget('ext.EchMultiselect.EchMultiselect', array(
'model' => $model,
'dropDownAttribute' => 'color',
'data' => $list,
'dropDownHtmlOptions'=> array(
'style'=>'width:378px;',
),
));?>
and in config/main.php i have imported the extension as
'import'=>array(
'application.models.*',
'application.components.*',
'application.extensions.EchMultiselect.*'
),
But i am getting error that "Alias "ext.EchMultiselect.EchMultiselect" is invalid. Make sure it points to an existing PHP file and the file is readable."
I have given all the permissions for the EchMultiselect file.
Please help me in this.. Thank you.. I tried a lot but did't get the exact result..
my folder structure is
My_lokal_Yii/protected/extensions/EchMultiSelect/EchMultiSelect
but in your config/main.php, there is:
... 'application.extensions.EchMultiselect.*'
------------------------------------^
It lacks the capital letter "s" and therefore the exact path/naming to/of your extension, I had the same "problem" with it ;-) , maybe it helps...
Greetings