CodeIgniter, models, and ORM, how to deal with this?

后端 未结 10 833
谎友^
谎友^ 2021-02-03 19:11

I\'m starting with CodeIgniter and after several hours diving in Google I\'m a bit confused.

Let\'s try to explain my question with a easy example: I have a table \'car

相关标签:
10条回答
  • 2021-02-03 20:00

    What you want to do is create a library that extends the ActiveRecord class. Some people are ahead of you:

    http://codeigniter.com/wiki/ActiveRecord_Class/

    good mods in the thread, here:

    http://codeigniter.com/forums/viewthread/101987/

    If you're looking for ORM methods that are general to your app, just extend the ActiveRecord class. For my application, knowing the structure of a table allows me to scaffold (auto-generate) forms, and do other mapping. I do API-to-API mapping, so I include a GetStructure() method in MyActiveRecord and build other things from there.

    (RoR snickering can bugger off now)

    Edit: while I am a fan of the scope and power of Doctrine, I think it's demand for command-line usage places it beyond the spirit of CI. What's right for you is what's right for you, but if I'm going to use Doctrine, I might as well use Symfony, right? Or RoR, for that matter, right?? See where I'm gong with this? Right tool for the right time.

    0 讨论(0)
  • 2021-02-03 20:02

    Try with Doctrine, is a great ORM and can be easily integrated in CodeIgniter.

    0 讨论(0)
  • 2021-02-03 20:02

    I had good luck with using Propel with codeigniter.

    0 讨论(0)
  • 2021-02-03 20:04

    check out GAS ORM it sounds pretty good, handy and easy to use. some features of this ORM implementation for CodeIgniter:

    • Supported databases : cubrid, mssql, mysql, oci8, odbc, postgre, sqlite, sqlsrv. (including PDO, if you keep sync with CI repo)
    • Support multiple database connections.
    • Support multiple relationships.
    • Support composite keys (for key that define relationships).
    • Auto-create models from database tables and vice versa.
    • Auto-synchronize models-tables by creating migrations file.
    • Per-request caching.
    • Self-referential and adjacency column/data (hierarchical data).
    • Eager Loading to maximize your relationship queries (for performance manner).
    • Various finder methods (can chained with most of CI AR) and aggregates.
    • Validation and auto-mapping input collection with minimal setup.
    • Hooks points to control over your model.
    • Extensions to share your common function/library across your model.
    • Transactions and other CI AR goodness.
    • Included phpunit test suite to ensure most of API consistency.

    there is one form with spark support -> so it's easy to install

    0 讨论(0)
提交回复
热议问题