+ add the feature of split css and js for every module.

This commit is contained in:
wangchunsheng
2011-02-14 14:21:38 +00:00
parent 031abf248f
commit 4acb87bdc0
+50
View File
@@ -298,6 +298,50 @@ class control
return false;
}
/**
* Get css code for a method.
*
* @param string $moduleName
* @param string $methodName
* @access private
* @return string
*/
private function getCSS($moduleName, $methodName)
{
$moduleName = strtolower(trim($moduleName));
$methodName = strtolower(trim($methodName));
$modulePath = $this->app->getModulePath($moduleName);
$css = '';
$mainCssFile = $modulePath . 'css' . $this->pathFix . 'common.css';
$methodCssFile = $modulePath . 'css' . $this->pathFix . $methodName . '.css';
if(file_exists($mainCssFile)) $css .= file_get_contents($mainCssFile);
if(file_exists($methodCssFile)) $css .= file_get_contents($methodCssFile);
return $css;
}
/**
* Get js code for a method.
*
* @param string $moduleName
* @param string $methodName
* @access private
* @return string
*/
private function getJS($moduleName, $methodName)
{
$moduleName = strtolower(trim($moduleName));
$methodName = strtolower(trim($methodName));
$modulePath = $this->app->getModulePath($moduleName);
$js = '';
$mainJsFile = $modulePath . 'js' . $this->pathFix . 'common.js';
$methodJsFile = $modulePath . 'js' . $this->pathFix . $methodName . '.js';
if(file_exists($mainJsFile)) $js .= file_get_contents($mainJsFile);
if(file_exists($methodJsFile)) $js .= file_get_contents($methodJsFile);
return $js;
}
/**
* Assign one var to the view vars.
*
@@ -384,6 +428,12 @@ class control
$viewFile = $this->setViewFile($moduleName, $methodName);
if(is_array($viewFile)) extract($viewFile);
/* Get css and js. */
$css = $this->getCSS($moduleName, $methodName);
$js = $this->getJS($moduleName, $methodName);
if($css) $this->view->pageCss = $css;
if($js) $this->view->pageJS = $js;
/* Change the dir to the view file to keep the relative pathes work. */
$currentPWD = getcwd();
chdir(dirname($viewFile));