concrete5でパッケージから必要なモデルをロードする (~5.6.x)
Posted by admin at 17:55 日時 2014/07/16
パッケージで定義しているモデルなどをオートロードする方法のメモです。パッケージのコントローラーのon_startアクションでロードするのが良い。インストール時にも必要な場合は、install()メソッド内でも呼ぶのを忘れずに。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('C5_EXECUTE') or die("Access Denied."); | |
class ExamplePackage extends Package { | |
protected $pkgHandle = 'example'; | |
protected $appVersionRequired = '5.6.3'; | |
protected $pkgVersion = '1.0'; | |
public function getPackageDescription() { | |
return t('This is an example package.'); | |
} | |
public function getPackageName() { | |
return t('Example Package'); | |
} | |
public function on_start() { | |
// autoload | |
ExamplePackage::autoLoad(); | |
} | |
public function install() { | |
// autoload | |
ExamplePackage::autoLoad(); | |
// do basic install process | |
$pkg = parent::install(); | |
// import contents and settings | |
$ci = new ContentImporter(); | |
$ci->importContentFile($pkg->getPackagePath() . '/install.xml'); | |
} | |
protected static function autoLoad() { | |
// Load required classes | |
Loader::model('example_model','example'); | |
} | |
} |