Loading custom classes in CodeIgniter?

前端 未结 4 1571
醉话见心
醉话见心 2021-01-02 00:49

Just starting to use CodeIgniter, and I\'d like to import some of my old classes for use in a new project. However, I don\'t want to modify them too much to fit into the CI

4条回答
  •  暖寄归人
    2021-01-02 01:30

    Libraries are easy to write but they have a few restrictions. Constructors can only take an array as a parameter and it's assumed that only one class will exist per file.

    You can include any of your own classes to work with them however you want, as this is only PHP ofc :)

    include APPPATH . 'classes/foo.php';
    $foo = new Foo;
    

    Or set up an __autoload() function in your config.php (best place for it to be) and you can have access to your classes without having to include them.

提交回复
热议问题