How to call a module static function from another module in PrestaShop 1.7+ - module

I'm trying to call static function of module named: Mymodule from another module like this: Mymodule::doThis()
But got error:
Fatal error: Class 'Mymodule' not found
I know, I can use code:
include_once _PS_MODULE_DIR_.'mymodule/mymodule.php',
but I want to know if I can use class autoloading or other elegant way to achieve this

You can try this :
Mymodule::getInstanceByName('doThis');
more explanation here :
Get name of module in PrestaShop front controller

Related

Creating and using a custom module in Julia

Although this question has been asked before, it appears that much has changed with respect to modules in Julia V1.0.
I'm trying to write a custom module and do some testing on it. From the Julia documentation on Pkg, using the dev command, there is a way to create a git tree and start working.
However, this seems like overkill at this point. I would like to just do a small local file, say mymodule.jl that would be like:
module MyModule
export f, mystruct
function f()
end
struct mystruct
x::Integer
end
end # MyModule
It appears that it used to be possible to load it with
include("module.jl")
using MyModule
entering the include("module.jl"), it appears that the code loads, i.e. there is no error, however, using MyModule gives the error:
ArgumentError: Package MyModule not found in current path:
- Run `import Pkg; Pkg.add("MyModule")` to install the MyModule package.
I notice that upon using include("module.jl"), there is access to the exported function and struct using the full path, MyModule.f() but I would like the shorter version, just f().
My question then is: to develop a module, do I need to use the Pkg dev command or is there a lighter weight way to do this?
In order to use a local module, you must prefix the module name with a ..
using .MyModule
When using MyModule is run (without the .), Julia attempts to find a module called MyModule installed to the current Pkg environment, hence the error.

Has Crystal got static methods?

Is it possible to do static methods in modules as in Ruby ?
module Test
self.def test
puts "test"
end
end
Test::test
I get a expecting token 'EOF', not 'end' if the call is in the same file ( as shown in the exemple ) and a expecting token 'CONST', not 'test' if I place the call in a different file.
What am I doig wrong ? Is there static methods in modules in Crystal ?
The correct syntax for class methods is def self.test, not self.def test. Class methods are called using Test.test, not Test::test.

Class not found in behat featurecontext.php

after running, i am getting
Fatal error: Cannot declare class JsonApiContext because the name is already in use in C:\behat\newapi\vendor\features\bootstrap\FeatureContext.php on line 13
can anyone please help me on same ?
Thanks
If you change the extends inheritance with a different class do you still get the error message?
Have you tried with "implements" instead of "extends"?
You need to use JsonApiContext.
In your FeatureContext.php it shall look like
class FeatureContext extends JsonApiContext ....

From a module, consult a file in another module

For some reason, in my Prolog module I want to be able to consult a file, but like if it was consulted from another module (e.g. user).
Say I have a file named myfile.pl containing:
foo(1).
Normally, if in module mymodule I execute consult(myfile), what I have is a new predicate mymodule:foo/1.
I would like to be able to consult the file from module mymodule but the resulting predicate be like user:foo/1.
Is this possible?
Did you tried to call consult(user:myfile) from within your mymodule module?

Yii generates error "Unable to resolve the request <controller/action>"

After logged in successfully, Yii does not executing any page.
Showing an error:
Error 404 Unable to resolve the request "membersdet/index"
Here membersdet is controller Id and index is an action.
Make sure the filename of your controller is EXACTLY "MembersdetController.php". It is case sensitive.
I guess you were developing on local machine under Windows OS and server runs on *nix system. That's normal issue for novice developers, that they forget about case sensitive file system in *nix.
It is because of wrong controller file name given or may be actionIndex() method is not in your controller.
I have had a similar problem and got it solved. In this case the file was correctly named but the class name was wrongly spelled. When these two do not correspond, you could get this error too.
Check case sensitive exactly your controller: MembersdetController
Check alias (common in config/main.php) map with namespace in your controller
Yii::setAlias('#tienn2t', dirname(dirname(__DIR__)) . '/tienn2t');
In MembersdetController.php file
<?php
namespace tienn2t\controllers;
use Yii;
use yii\web\Controller;
class MembersdetController extends Controller{
public function actionIndex(){
echo 1;die;
}
}
There is not enough information in the question, but maybe you have an incorrect .htaccess or if you don't have an htaccess at all you should use the url:
http://host/index.php?r=membersdet/index
Make sure you have MembersdetController in /protected/controllers/ and this class "is a" CController and has a public method named actionIndex().
Check errorHandler block in your config file.
I had fix this error like this
'errorHandler' => [
'errorAction' => 'error/index',
],
By the way you should have appropriate ErrorController in your module and /error/index.php
file in view folder.
Hope will help you.