3
無法在Kohana中啓動項目。我從github克隆了它,而不是在配置文件中設置我的數據庫信息,並得到錯誤:無法重新聲明類。Kohana:無法重新聲明類
我有2個方法自動加載函數。
public static function auto_load($class, $directory = 'classes')
{
// Transform the class name according to PSR-0
$class = ltrim($class, '\\');
$file = '';
$namespace = '';
if ($last_namespace_position = strripos($class, '\\'))
{
$namespace = substr($class, 0, $last_namespace_position);
$class = substr($class, $last_namespace_position + 1);
$file = str_replace('\\', DIRECTORY_SEPARATOR, $namespace).DIRECTORY_SEPARATOR;
}
$file .= str_replace('_', DIRECTORY_SEPARATOR, $class);
if ($path = Kohana::find_file($directory, $file))
{
// Load the class file
require_once $path;
// Class has been found
return TRUE;
}
// Class is not in the filesystem
return FALSE;
}
/**
* Provides auto-loading support of classes that follow Kohana's old class
* naming conventions.
*
* This is included for compatibility purposes with older modules.
*
* @param string $class Class name
* @param string $directory Directory to load from
* @return boolean
*/
public static function auto_load_lowercase($class, $directory = 'classes')
{
// Transform the class name into a path
$file = str_replace('_', DIRECTORY_SEPARATOR, strtolower($class));
if ($path = Kohana::find_file($directory, $file))
{
// Load the class file
require_once $path;
// Class has been found
return TRUE;
}
// Class is not in the filesystem
return FALSE;
}
我已嘗試添加class_exists()要求()之前,但它不工作&我應該怎麼做,以啓動一個項目?
你能給與'class_exists()'使用完整的代碼示例? –