PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 19, 2022

[FIXED] Prestashop install and use vendor from composer

 February 19, 2022     composer-php, prestashop, prestashop-1.6     No comments   

Issue

I'm developing a Prestashop (PS) module but I want use composer to install some dependencies.

I found some problems to perform this task. First of all, how include autoload class inside vendor to use the package? and second how use it in my module?

Could you provide me an example?


Solution

Just include the autoload.php file in you module file:

<?php

require_once('vendor/autoload.php');

class MyModule extends Module
{
   ...
}

Since your module file will (and should be) always be loaded first, this should be ok.

I believe there shouldn't be any conflicts between two such modules that use composer autoload, because the generated autoloaders have unique class names and the ComposerAutoload class used during registering autoloader is somehow unregistered after the process.

The file structure:

/modules/mymodule/mymodule.php
/modules/mymodule/composer.json
/modules/mymodule/vendor/autoload.php

Edit:

If you're making a custom website (not just the module), I'd advise to use single composer root in root directory:

/composer.json

Then I'd add require ../vendor/autoload.php in custom config file (check /config/config.inc.php which custom config files are loaded)



Answered By - gskema
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing