Joomla在安裝的時(shí)候會(huì)安裝幾個(gè)Application(應(yīng)用程序),每一個(gè)應(yīng)用程序的負(fù)責(zé)不同的模塊。
Joomla在安裝的時(shí)候會(huì)安裝幾個(gè)Application(應(yīng)用程序),每一個(gè)應(yīng)用程序的負(fù)責(zé)不同的模塊:
上面的Administrator,Site和Installion是主要的應(yīng)用程序,每一個(gè)應(yīng)用程序類都繼承自 \\Joomla\\Application\\AbstractApplication這個(gè)虛基類。其最終的類名為:
繼承關(guān)系圖如下:
Joomla Framework Abstract Application
|
|
|---> Base Application (adds some CMS Specific functions)
|
|
|---> Web Application (adds some generic web application functions)
| |
| |
| |---> JApplicationCms (things specific for running the CMS)
| |
| |---> JApplicationAdministrator
| |
| |---> JApplicationSite
| |
| |---> InstallationApplicationWeb
|
|
|---> CLI Application
|
|
|---> Daemon Application
通過(guò)$app = JFactory::getApplication();可以得到當(dāng)前的應(yīng)用程序?qū)ο螅到y(tǒng)會(huì)自動(dòng)的基于當(dāng)前的運(yùn)行環(huán)境返回正確的類。也就是說(shuō)在前臺(tái)使用上面的代碼得到的$app對(duì)象實(shí)際是JApplicationSIte類的一個(gè)實(shí)例,在后臺(tái)則得到是JApplicationAdministrator類的一個(gè)實(shí)例。
除了能夠做瀏覽器應(yīng)用外,Joomla也可以做CLI命令行應(yīng)用。建立自己的命令行應(yīng)用需要基礎(chǔ)Joomla 的JApplicationCli類,一個(gè)簡(jiǎn)單的范例如下:
/**
* A command line cron job to attempt to remove files that should have been deleted at update.
*
* @since 3.0
*/
class DeletefilesCliextends JApplicationCli
{
/**
* Entry point for CLI script
*
* @return void
*
* @since 3.0
*/
public function doExecute()
{
// Import the dependencies
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
// We need the update script
JLoader::register('JoomlaInstallerScript', JPATH_ADMINISTRATOR .'/components/com_admin/script.php');
// Instantiate the class
$class =new JoomlaInstallerScript;
// Run the delete method
$class->deleteUnexistingFiles();
}
}
// Instantiate the application object, passing the class name to JCli::getInstance
// and use chaining to execute the application.
JApplicationCli::getInstance('DeletefilesCli')->execute();
完整的代碼請(qǐng)查看 Joomla安裝目錄 cli\deletefiles.php
Joomla也可以做守護(hù)進(jìn)程,官方資料顯示只需要繼承 JApplicationDaemon 類,但本人目前沒(méi)有找到具體的案例代碼
更多建議: