开发者

Propel 1.6 - Question About Includes

Any ideas how to avoid adding 20 different require() statements to each one of my CI controllers?

As a follow up to my previous question about integrating Propel with my project, a more involved problem. I am trying to include a generated class into my application controller. Here is the code:

require_once('PolicytypeQuery.php');

class PolicyType extends CI_Controller {

    function PolicyType() {
        parent::get_instance();
    }


    function index() {
        $data = array();
        $data['policytypes'] = PolicytypeQuery::create()->find();

        $this->load->view('policytype_view',$data);
    }

}

The generated class depends on some base class, and I am getting an error that indicates that this base class is not already included somewhere:

[Sat Aug 13 16:22:56 2011] [error] [client 97.97.177.2] PHP Fatal error:
Class 'BasePolicytypeQuery' not found in
/var/lib/IPV/util/build/classes/vault/PolicytypeQuery.php on line 16

I would think that generated code would have the necessary require() statements also generated. However, it doesn't appear so:

/**
 * Skeleton subclass for performing query and update operations on the 'policytype' table.
 *
 *
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 * @package    propel.generator.vault
 */
class PolicytypeQuery extend开发者_JS百科s BasePolicytypeQuery {

} // PolicytypeQuery

Is there a Propel generator option to add require() statements into generated code? Or maybe I'm not autoloading Propel correctly in my project. To that end, I followed this tutorial on integrating Propel with CodeIgniter:

http://codeigniter.com/wiki/Using_Propel_as_Model/

Per step 3, I am including Propel in autoloaded libraries. Should this be resolving my issue?


Yes, it should.

PHP has a facility called autoloading classes. I don't know propel, but if it properly uses __autoload, you should not need to use any require anymore.


Propel has its own autoloader, which you should use.

At your initialisation phase in CI, you should initialise Propel thus (see step 2 in the CI link):

Propel::init('/path/to/database-conf.php');

That file, database-conf.php, is generated by the convert-conf command, together with an autoloader classmap, called classmap-database-conf.php. The former includes the latter - once you have done that your Propel classes will all load automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜