1

I have done setup for mongodb on my system with Yii2 basic.

I have also installed the extension for mongodb (yii2-mongodb) inside a directory /vendor/yiisoft and checked for the permissions.

Now I am testing the connection with a controller and model but I am getting the following error.

PHP Fatal Error – yii\base\ErrorException Class

'yii\mongodb\ActiveRecord' not found

Is there anything that needs to be installed?

Ajay
  • 18,086
  • 12
  • 59
  • 105
Swap
  • 41
  • 5
  • Did you install yii2-mongodb using composer? – Bizley May 22 '17 at 07:01
  • Yes I installed it using composer and on updating composer I am getting error i.e your requirements could not be resolved to an installable set of packages. – Swap May 22 '17 at 07:33
  • So it looks like you have not installed it. Probably you are missing MongoDB PHP extension. – Bizley May 22 '17 at 07:35
  • I am using PHP Version 7 and MongoDB extension version :1.2.8 is enabled. – Swap May 22 '17 at 09:05

2 Answers2

1

Have you install yii2/mongodb by composer ^^?

composer require --prefer-dist yiisoft/yii2-mongodb

Or your try follow this official Yii2 document step by step maybe can help you up :)!

Job5505
  • 21
  • 6
  • You cannot directly copy the library file to the vendor directory, the composer autoloader can't detect the library. Erm i saw you say that you using composer and on updating composer getting error right? Can you paste the error here let us see maybe can help you up – Job5505 May 22 '17 at 07:42
  • Here is the error : Your requirements could not be resolved to an installable set of packages.Potential causes: - A typo in the package name - The package is not available in a stable-enough version according to your minimum-stability setting see for more details. – Swap May 22 '17 at 09:14
  • @user2531706 sorry for late reply, I face this 'minimum-stability' problem before, on that time I have do many research. You can backup your whole project then delete the 'vendor' folder then run `composer update` to reinstall all package again. This how before I solve my problem. – Job5505 May 22 '17 at 09:37
  • This works for me http://stackoverflow.com/questions/43408604/php7-install-ext-dom-issue – Swap May 22 '17 at 09:43
1

In this case I tried following command before updating composer to fulfill the packages that need to update the composer

sudo apt-get update
sudo apt-get install php7.0-xml

most likely you are missing mbstring too . If you get the error install this package as well.

sudo apt-get install php-mbstring

then run

composer require --prefer-dist yiisoft/yii2-mongodb
composer update

Will work!!!

Swap
  • 41
  • 5