Yii Activerecord without yii

Can I use the Yii Activerecord (model) classes without Yii? He seems to have a lot of addictions. I want to use ORM and the Yii validation mechanism in my own project.

+5
source share
6 answers

There are many dependent classes in the Yii ActiveRecord classes, so you cannot use only those classes. For each error, you end up with all the dependent classes included.

If you want to use ORM for your project, then why not use some of the best ORMs available for PHP? And what's more, you will be 100% sure that nothing is broken.

Some of the PHP ORMs you can use are:

For more information, check out some of the following SO questions:

Hope this helps.

+12
source

I will say better if you do not, and write something your own, taking the idea from Yii or best using Yii, because CActiverecord is the main part of Yii, extending the CModel and CComponent , if you try to extract it from Yii, in in the end you will find that you have copied almost everything.

+3
source

Your question seems impossible to answer. You cannot extract a PHP class from Yii without using the whole structure. Platforms like Symphony offer you some components that you can use and should not use the whole infrastructure. There is an ORM project in PHP, I have never used it, but you can make an experience ... http://www.phpactiverecord.org/ I hope this helps you, hugs.

+3
source

Well, you can extract it, I would advise you to do it with Yii2 (it will be easier, since only a container is required to store component instances). Yii is an extremely lightweight modular structure in which you can only load basic components, so why not download all of this? If you, however, want to use only AR with your own routing, import the Yii autoloader, and then try using models. I expect this to work.

However, you will need a whole separate application for creating models with gii , for example.

+1
source

yes, you can do this by defining yii as a dependency.

please check below link can help you :)

http://www.yiiframework.com/doc-2.0/guide-tutorial-yii-integration.html#using-yii-in-others

+1
source

You cannot use the ActiveRecord class without the whole structure. ActiveRecord is not an independent class and relies heavily on other components of the structure, for example. database, cache, schema, etc.

The extraction process will be more like trying to re-implement the infrastructure components needed for the class to function.

If you are interested in ORM mechanisms and Yii structure validations, I believe that you should delve into the yii kernel and create your own ActiveRecord class that implements ORM + validation.

Hope this answers your question.

0
source

Source: https://habr.com/ru/post/1205157/


All Articles