5

Can I use Yii's Activerecord (model) classes without Yii? It looks like it have lots of dependencies. I want to use ORM and Validation mechanism of Yii in my own project.

Syed Ekram Uddin
  • 2,907
  • 2
  • 29
  • 33
Tahir
  • 59
  • 2
  • Try using yiilite.php – gSorry May 21 '15 at 21:51
  • 1
    If you are looking for only ORM. Why Yii? Look for other options http://www.doctrine-project.org/projects/orm.html Also review DaraMaper Vs ActiveRecord http://stackoverflow.com/questions/2169832/data-mapper-vs-active-record Last thing I like to suggest is https://laravel.com if you want go with the future. This would be the best php framework out there. Also if Yii is your choice Go for Yii2 – Syed Ekram Uddin May 12 '16 at 13:39

6 Answers6

13

Yii's ActiveRecord Classes have lots of dependent classes, hence you'll not be able to use only those classes. For every error you get you end up including all the dependent classes.

If you want to use the ORM for your project, then why don't you use some of the best ORMs available for PHP? And moreover you'll be 100% sure that nothing is broken.

Some of the PHP ORMs that you can use are:

  1. Propel
  2. PHPActiveRecord
  3. Doctrine
  4. Redbean

For more information, look at some of the following SO Questions:

  1. Good PHP ORM
  2. Redbean Vs Doctrine
desertnaut
  • 57,590
  • 26
  • 140
  • 166
Vinod Tigadi
  • 859
  • 5
  • 12
3

I will say better if you don't and write something your own by taking the idea from Yii or best will be use Yii itself, because CActiverecord is core part of Yii extending CModel and CComponent if you try to extract it from Yii you will find in the end that you copied almost everything.

Kuldeep Dangi
  • 4,126
  • 5
  • 33
  • 56
3

your question seems to be impossible to answer. You can't extract a PHP class from Yii without use the whole framework. Frameworks like Symphony, offers to you some components that you can use and don't need to use whole framework. There are a project ORM on PHP, I have never used it, but you can do a experience: http://www.phpactiverecord.org/

desertnaut
  • 57,590
  • 26
  • 140
  • 166
1

Well, you can extract it, I'd advise you do that from Yii2 (it will be easier as it needs just a container to hold component instances). Yii is extremely light, modular framework where you can load only the base components so why not load the whole thing? If you however want to use only the AR with own routing, import the Yii autoloader and then try to use the models. I expect it to work.

However you will need whole separate app to generate models with gii for example.

ddinchev
  • 33,683
  • 28
  • 88
  • 133
1

Its best not to use it separately as Activerecord has lots of dependent classes with in the framework. you can look at the code and build your own validations like in Yii or you can choose popular ORM's like Proper or Doctorine. they got very good documentation.

http://propelorm.org/

https://www.doctrine-project.org/

Azraar Azward
  • 1,586
  • 2
  • 12
  • 16
0

You cannot really use ActiveRecord class without the whole framework. ActiveRecord is not an independent class and heavily relies on other components of the framework, e.g. database, cache, schema, etc...

The extraction process will look more like trying to re-implement the framework components required for the class to function.

If you are interested in ORM and validation mechanisms of Yii framework, I believe you should dig deeper into the core of yii and create your own "ActiveRecord" class implementing the ORM + validation.

desertnaut
  • 57,590
  • 26
  • 140
  • 166