Phreezer.php里面的函数,
public function IncludeModel($objectclass) { Includer::RequireClass($objectclass, array("Model/","Reporter/") ); }
Query()方法里面有这句话
1 $custom = $this->GetCustomQuery($objectclass, $criteria);
调用了Phreezer.php里面的自身的方法GetCustomQuery();
public function GetCustomQuery($objectclass, $criteria) { $this->IncludeModel($objectclass); $sql = call_user_func( array($objectclass,"GetCustomQuery"),$criteria );
//上面这句话调用了用户自定义的GetCustomQuery方法,在Reporter.php里面 return $sql; }
PTestReporter.php的内容如下:
require_once("verysimple/Phreeze/Reporter.php"); class PTestReporter extends Reporter{ public $Id; public $Name; public $Time; static function GetCustomQuery($criteria) { $sql = "select `ptest`.`id` as Id ,`ptest`.`name` as Name ,`ptest`.`time` as Time from `ptest`"; // the criteria can be used or you can write your own custom logic. // be sure to escape any user input with $criteria->Escape() $sql .= $criteria->GetWhere(); $sql .= $criteria->GetOrder(); //echo $sql; return $sql; } }
*/
public static function RequireClass($classname, $classpath = "")
{
if (class_exists($classname)) return true;
// normalize this as an array
$classpaths = is_array($classpath) ? $classpath : array($classpath);
$attempts = "";
foreach ($classpaths as $path)
{
if (class_exists($classname)) break;
//$classname='PTest';
//$classpaths=array('Model/','Reporter/');
try
{
// append a directory separater if necessary
if ($path && substr($path,-1) != "/") $path .= "/";
Includer::IncludeFile($path . $classname . ".php"); //这里表示加载的页面,可是也没有说明可以加载Reporter.php的文件啊,
}
catch (IncludeException $ex) {$attempts .= " " . $ex->getMessage();}
}
if (!class_exists($classname))
{
// the class still isn't defined so there was a problem including the model
throw new IncludeException("Unable to locate class '$classname': " . $attempts);
}
}
Query语句这么写:
$ds=$this->Phreezer->Query('PTestReporter',$criteria);
未完待续。。。。。。