我正在尋找將模塊系統實現到我的應用程序框架中的方法,模塊將是以某種方式更改設計的類文件,以便自動與用戶干預集成。在框架內創建模塊系統
我的框架是一個定製的框架,但非常類似於codeigniter,只是更輕一點。
我已經是模板文件中的想法是對模塊位置打電話,並有模塊自動加載和分析
<html>
<head>
<title>Welcome to my site</title>
</head>
<body>
<header>
....
<?php $this->call_modules('header') ?>;
</header>
<section>
<aside>
<?php $this->call_modules('sidebar') ?>;
</aside>
</section>
</body>
</html>
所以,下面的模塊將被調用,其內容將在那裏去地點:
/system/applications/admin/modules/header/a.php
/system/applications/admin/modules/header/b.php
/system/applications/admin/modules/sidebar/a.php
/system/applications/admin/modules/sidebar/b.php
所以這對我來說似乎將工作得很好,但問題是,我從來沒有建立一個模塊系統,我覺得這些都是鉤更入級。
在我的腦子裏,我基本上想要一個簡單的系統,由1類文件和模板,如果需要,CALSS文件很可能是這樣的:
class Module_HelloWorld extends Module
{
public static function info()
{
return array(
'name' => 'Hello Word',
'version' => '1.0.0',
'description' => 'Dispalys "hello World"',
'author' => 'Robert Pitt',
);
}
public function execute($context,$action)
{
//$context would be the current view at the point of execution for the view
//$action would be header/sidebar
}
}
所以我概括地說問題會是什麼是爲我的框架設計一個模塊系統的最佳方式,允許3Rd方模塊放在一個目錄中,然後從管理員安裝,而不需要太多的用戶干預?
感謝您的回覆,稍後我會看看我能想出什麼,儘管數據庫存儲不是我想要關閉的路徑。 – RobertPitt 2011-05-13 12:21:44
@RobertPitt,它可能適用於你的場景,在一個類和模塊之間有一對一的對應關係,但是數據庫對我來說很合適。 – 2011-05-13 19:04:45