Custom Helper Class not found in Prestashop module - class

I created a helper class in prestashop 1.6 module, in the override directory. I included the file in main module file but the class is not found in tpl files. I need it there to call one static method from smarty template.
Any ideas with this?
Thanks.

Related

TYPO3 10 Viewhelper class not found, Fluid error

There is some small detail I seem to be missing but I just can't find out what it is...
I get this error:
Error: The ViewHelper "<ugh:example>" could not be resolved. Based on your spelling, the system would load the class "TYPO3\Projectname\ViewHelpers\ExampleViewHelper", however this class does not exist.
I have my own extension called sitepackage, which works without issues.
In my ext_localconf.php I wrote
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['ugh'] = ['TYPO3\\Projectname\\ViewHelpers'];
Then there's the directory ViewHelpers inside Classes with the file ExampleViewHelper.php
<?php
namespace TYPO3\Projectname\ViewHelpers;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
// etc ...
I expect it to use like <ugh:example />
What am I missing? Is there something outside of this that I have to do?
I'm freaking out about this...
Your global configuration works, yet PHP is not able to find your TYPO3\Projectname\ViewHelpers\ExampleViewHelper.
I suspect that you have a spelling error or your autoloading information is out of date (assuming a composer-based installation, composer dump-autoload updates it) or you forgot to add your namespace to composer.json (see composer docs or a TYPO3 extension example here).
That said, the usual approach is to add ViewHelper namespaces to the Fluid template directly. See https://docs.typo3.org/m/typo3/book-extbasefluid/10.4/en-us/8-Fluid/8-developing-a-custom-viewhelper.html#importing-namespaces
Without composer
Use TYPO3 InstallTool "rebuild autoload information" or similar to build the class autoloading information. I think ext_emconf.php needs to contain the autoloading information, too.

Prestashop 1.7 Create new classes for modules and overrided controllers

I started with prestashop and I have an organizational problem in my code. I created several modules and new tables. I also overrided controllers in the myprestashop/override/ folder in which I want to use my tables, so I have to create new classes. But I don't know where to create classes in prestashop for as much access in my modules as in my overrided controllers.
For now I'm calling my classes create in my modules, in my overridded controllers. Although I know it's not the right solution.
require_once _PS_MODULE_DIR_.'my_module/classes/MyNewClass.php'
Would someone have the answer?
Thank you!!
Well your way is acceptable solution as PrestaShop doesn't have any autoloading capabilities for custom classes.
However what I like to do is use Composer in modules and use its autoloading capabilities for my classes and any libraries that the module might need.
Update
An example of composer usage in myexample module:
Module structure
modules/
myexample/
classes/
mynamespace/
myexample.php
composer.json
myexample.php
require_once __DIR__ . '/vendor/autoload.php';
class MyExample extends Module
{
// module code
}
composer.json
{
"autoload": {
"psr-4": {
"mynamespace\\": "classes/mynamespace"
}
}
}
Run composer install from module folder.
Now you can put classes under mynamespace folder (with proper namespace definition of course) and they get autoloaded anywhere your module is used (module controllers, models, hooks etc).
I noticed that below scheme works too in version 1.7.6, but I would ask experienced developers to point if this is correct approach.
I put my custom class file into /override/classes folder:
namespace CustomNamespace;
class CustomClass {
...
}
then in other places I just use the class:
use \CustomNamespace\CustomClass;
and my CustomClass works as expected

includeJsFiles not working in fluid ViewHelper in TYPO3

I need to add a custom js file in my backend module of TYPO3 v7.6 extension.I added the following code in my layout
<f:be.container includeJsFiles="{0:'{f:uri.resource(path:\'Js/Main.js\')}'}">
<!------------ Contents ------------>
</f:be.container>
No error but the js file is not included in page source.Any other method is there to implement my requirement?
I would assume the path to the JS-file is wrong.
With your declaration it is expected to be EXT:your_extension/Resources/Public/Js/Main.js in your extension (as statet in the core sources).
But when in doubt I would try some other pathes. (full references)

Joomla Plugin With Helper File

Is there a conventional way of making a helper file to a Joomla Plugin? Like class names (helper or plgNameHelper) and the way of calling it?
class Helper
{
public static function test()
{
// some code
}
public static function anotherTest()
{
// some code
}
}
Conventionally, helper files have been for modules, not plugins. However it is a good idea to make a template, if the plugin changes the page HTML.
There is no conventional way of making a helper file to a Joomla Plugin but you can create Joomla! Library which can help you to auto load your classes by registering prefix.
I suggest you to read this link.

Zend Framework 1.11: how to autoload a class that uses namespaces

I have a Zend Framework 1.11 application, and I want to use a package called RandomLib. The problem is, it doesn't have an autoloader, and I've tried reading the Zend documentation on using autoloaders, but I can't make sense of it.
I've placed the RandomLib folder in my library directory. What kind of code would I need in my Bootstrap.php file to autoload the class?
Starting in version 1.10.0, Zend Framework now allows loading classes from PHP namespaces. This support follows the same guidelines and implementation as that found in the ยป PHP Framework Interop Group PSR-0 reference implementation. Source
Put content of RandomLib/lib under library/RandomLib
In application.ini add autoloaderNamespaces[] = "RandomLib"
If you wish you can include namespace libraries directly in your Bootstrap.php file after you moved the library in "library/MyExternalLib"
protected function _initAutoLoader()
{
$loader = Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('MyExternalLib');
return $loader;
}