2015-01-20 20 views
0

我的文件夹结构如下:Smarty的整合到定制的PHP MVC

config/ 
controller/ 
core/ 
lib/ 
    smarty/ 
    All Smarty Files 
model/ 
views/ 
index.php 

我的MVC会将所有网络流量通过的index.php其中包括autloading下面的代码:

function __autoload($class){ 
    $file = sprintf('%smodel/%s.class.php',__SITE_PATH,$class); 
    if(is_file($file)){ 
    include $file; 
    return; 
    } 
    $file = sprintf('%smodel/%s.php',__SITE_PATH,$class); 
    echo $file; 
    if(is_file($file)){ 
    include $file; 
    return; 
    } 
} 

保持在介意你被迫使用不支持命名空间或SPLAutoloading的PHP版本,你将如何改变__autoload函数或Smarty与你的网站打好关系(工作)?

我的具体问题是,当smarty_internal_smartytemplatecompiler.php试图包含一个文件时,它正在查看模型文件夹而不是smarty文件夹。我想我可以将Smarty转移到模型上,但这看起来并不“正确”。

回答

1

由于您使用的是不支持命名空间的< 5.3,所有的Smarty类都以“smarty_”为前缀?如果是这样,你可以添加一个条件到你的__autoload()函数,检查类名是否以“smarty_”开头,如果是,则告诉它搜索smarty文件夹:

if(strpos($class, "smarty_") === 0){ 
    $file = sprintf('%slib/smarty/%s.php',__SITE_PATH,$class); 
    if(is_file($file)){ 
    include $file; 
    return; 
    } 
}