示例#1
0
文件: jsondb.php 项目: alakim/grains
 public function getValue($path)
 {
     $steps = explode("/", $path);
     $fPath = $this->root;
     $obj = null;
     foreach ($steps as $st) {
         if ($obj != null) {
             $a = get_object_vars($obj);
             $obj = $a[$st];
         } else {
             $fPath = $fPath . "/" . $st;
             if (file_exists($fPath)) {
                 if (!is_dir($fPath)) {
                     $obj = JSONDB::getObject($fPath);
                 }
             } else {
                 die("File " . $fPath . " does not exist");
             }
         }
     }
     if ($obj == null) {
         if (!is_dir($fPath)) {
             $obj = JSONDB::getObject($fPath);
         } else {
             $obj = JSONDB::getDirectory($fPath);
         }
     }
     //print_r($obj);
     return $obj;
 }
示例#2
0
文件: index.php 项目: alakim/grains
<!DOCTYPE html>
<html>
<head>
	<meta encoding="utf-8"/>
	<title>JSONDB Demo Page</title>
	<link rel="stylesheet" type="text/css" href="styles.css"/>
</head>
<body>
	<h1>JSONDB Demo Page</h1>
	<?php 
include 'jsondb.php';
$db = new JSONDB("data");
?>
	
	<?php 
$path = "persons/iii/name";
$val = $db->getValue($path);
?>
	<p><?php 
echo $path;
?>
: '<?php 
echo $val;
?>
'</p>
	
	<?php 
$path = "persons/iii/phone";
$val = $db->getValue($path);
?>
	<p><?php