Petar Jovanovic
Petar Jovanovic

Reputation: 11

How to implement composer in yii 1?

Hello I have old project written in php framework Yii 1.1. Dependencies are added manually by uploading extensions in extension folder.

I want to make my project use composer to track third-party code into vendor directory. So "extensions" directory would not exist.

Existing extensions are not namespaced and are used manually in controllers: Yii::import('application.models.black_lists.domains');

So is this possible to achieve and how? Thanks

Upvotes: 1

Views: 2378

Answers (1)

benomite
benomite

Reputation: 868

You have to require the composer autoloader before any vendor is used in your code. To do so, you have to unregister Yii autoloader before you require the composer one

spl_autoload_unregister(array('YiiBase','autoload'));
require Yii::getPathOfAlias('application.vendor').DIRECTORY_SEPARATOR.'autoload.php';
spl_autoload_register(array('YiiBase','autoload'));

After this, you should be able to call any class in the vendor folder, the composer way.

new \Owner\Module();

Upvotes: 2

Related Questions