Warnung: file_put_contents(/home/www/web1/html/php_dev/test.txt) [function.file-put-contents]: failed to open stream: Permission denied in /home/www/web1/html/php_dev/sys/lib.activity.php (Zeile 58)
Probleme mit Pear DB_NestedSet [Archiv] - PHP-Scripte PHP-Tutorials PHP-Jobs und vieles mehr

- Ad -
php-resource




Archiv verlassen und diese Seite im Standarddesign anzeigen :
Probleme mit Pear DB_NestedSet


 
bweichel
13-01-2005, 11:35 
 
Ich wollte folgendes Script Beispiel von Pear ausprobieren.


<?php /** $Id: TreeMenu_example.php,v 1.5 2003/12/30 17:07:37 jrust Exp $ */ ?>
<html>
<title>DB_NestedSet using TreeMenu Output class</title>
<body>
<div style="font-weight: bold;">DB_NestedSet using the TreeMenu Output class</div>
<div>
<?php
/**
* Tests the DB_NestedSet class using the TreeMenu renderer
* Requires that you have HTML_TreeMenu installed
*
* @author Jason Rust <jrust@rustyparts.com>
*/
// {{{ mysql dump

/**
* Dump of the example mysql table and data:
#
# Table structure for table `nested_set`
#

CREATE TABLE `nested_set` (
`id` int(10) unsigned NOT NULL default '0',
`parent_id` int(10) unsigned NOT NULL default '0',
`order_num` tinyint(4) unsigned NOT NULL default '0',
`level` int(10) unsigned NOT NULL default '0',
`left_id` int(10) unsigned NOT NULL default '0',
`right_id` int(10) unsigned NOT NULL default '0',
`name` varchar(60) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `right` (`right_id`),
KEY `left` (`left_id`),
KEY `order` (`order_num`),
KEY `level` (`level`),
KEY `parent_id` (`parent_id`),
KEY `right_left` (`id`,`parent_id`,`left_id`,`right_id`)
) TYPE=MyISAM;

#
# Dumping data for table `nested_set`
#

INSERT INTO `nested_set` VALUES (5, 5, 1, 1, 1, 10, 'Root A');
INSERT INTO `nested_set` VALUES (7, 7, 1, 1, 1, 4, 'Root B');
INSERT INTO `nested_set` VALUES (6, 5, 1, 2, 2, 5, 'Sub1 of A');
INSERT INTO `nested_set` VALUES (1, 5, 2, 2, 6, 9, 'Sub2 of A');
INSERT INTO `nested_set` VALUES (2, 5, 1, 3, 3, 4, 'Child of Sub1');
INSERT INTO `nested_set` VALUES (3, 5, 1, 3, 7, 8, 'Child of Sub2');
INSERT INTO `nested_set` VALUES (4, 7, 1, 2, 2, 3, 'Sub of B');
# --------------------------------------------------------

#
# Table structure for table `nested_set_locks`
#

CREATE TABLE `nested_set_locks` (
`lockID` char(32) NOT NULL default '',
`lockTable` char(32) NOT NULL default '',
`lockStamp` int(11) NOT NULL default '0',
PRIMARY KEY (`lockID`,`lockTable`)
) TYPE=MyISAM COMMENT='Table locks for comments';

*/

// }}}
// {{{ set up variables

require_once('DB/NestedSet.php');
require_once('DB/NestedSet/Output.php');
$dsn = 'mysql://xxx:xxx@localhost/test';
$params = array(
'id' => 'id',
'parent_id' => 'rootid',
'left_id' => 'l',
'right_id' => 'r',
'order_num' => 'norder',
'level' => 'level',
'name' => 'name',
);

$nestedSet =& DB_NestedSet::factory('DB', $dsn, $params);
// we want the nodes to be displayed ordered by name, so we add the secondarySort attribute
$nestedSet->setAttr(array(
'node_table' => 'nested_set',
'lock_table' => 'nested_set_locks',
'secondarySort' => 'name',
)
);
// get data (important to fetch it as an array, using the true flag)
$data = $nestedSet->getAllNodes(true);

// }}}
// {{{ manipulate data

// add links to each item
foreach ($data as $id => $node) {
$data[$id]['link'] = 'http://example.com/foo.php?' . $node['id'];
}

// }}}
// {{{ render output

$params = array(
'structure' => $data,
'textField' => 'name',
'linkField' => 'link',
'options' => array('icon' => 'folder.gif', 'expandedIcon' => 'folder-expanded.gif'),
);

$output =& DB_NestedSet_Output::factory($params, 'TreeMenu');
// Create the javascript menu.
// You'll need to copy over the images directory and TreeMenu.js file that
// comes with HTML_TreeMenu into a web-accessible directory.
// Set the location of the images for the menu here
echo '<script src="TreeMenu.js" language="JavaScript" type="text/javascript"></script>';
$output->setOptions('printTree', array('images' => '/imagesAlt2'));
$output->printTree();

// Create the select list menu.
$output->printListbox();

// }}}
?>
</div>
</body>
</html>


Habe das Pear-Package DB_NestedSet und DB installiert. Jedoch kommt trotzdem noch folgende Fehlermeldung:


DB_NestedSet using the TreeMenu Output class

Warning: main(HTML/TreeMenu.php): failed to open stream: No such
file or directory in /usr/share/php/DB/NestedSet/TreeMenu.php on
line 22

Fatal error: main(): Failed opening required 'HTML/TreeMenu.php'
(include_path='.::/usr/share/pear') in /usr/share/php/DB/NestedSet/TreeMenu.php on line 22


Kann mir jemand sagen was ich falsch mache und geändert werden muss?

Besten Dank...

 
asp2php
13-01-2005, 11:42 
 
failed to open stream: No such file or directory in...
ist doch eindeutige Fehlermeldung, oder? Schau doch mal nach, was in Zeile 22 steht und überprüfe auf Existenz oder Zugriffsrecht.

 
bweichel
13-01-2005, 11:53 
 
Darin steht...


require_once 'HTML/TreeMenu.php';


In dem Verzeichnis gibt es auch keine solche Datei. Die Datei
TreeMenu.php liegt in /usr/share/php/DB/NestedSet/TreeMenu.php.
Aber ich glaube nicht das damit die gleichen Dateien gemeint sind,
oder?

Es gibt zwar ein Verzeichnis HTML, aber darin liegt nur ein Verzeichnis
Template. Woher bekomme ich die Datei TreeMenu.php für das HTML
Verzeichnis? Sorry, aber ich dachte das wäre bei der Pear installation
alles dabei gewesen.

 
Coragon Rivito
13-01-2005, 15:27 
 
die TreeMenu.php in DB/NestedSet ist nur eine schnittstelle zum eigentlichen, separat zu installierendem
pear package HTML_TreeMenu (http://pear.php.net/package/HTML_TreeMenu) ...

class DB_NestedSet_TreeMenu extends DB_NestedSet_Output {

 
bweichel
13-01-2005, 16:29 
 
Ok, danke... mein TreeMenu funktioniert nun... jedoch möchte ich für meinen Shop eine Navigation die in keiner Select-Box steht. Kann man sich die einzelnen Menü`s irgendwo in der Vollendung ansehen?

Ich habe das TigraMenu ausprobieren wollen.


<?php
/**
* $Id: TigraMenu_example.php,v 1.2 2003/05/15 16:23:09 jrust Exp $
* This example shows how to use the TigraMenu output driver
*
* @author Daniel Khan <dk@webcluster.at>
*/

// This example assumes that you have allready set up DB_NestedSet and allready
// inserted nodes.

// First you have to get TigraMenu
// It's available for free at http://www.softcomplex.com/products/tigra_menu/
// Please read the docs for TigraMenu - they are nice and verbose and will help
// you to understand the params passed to the driver
// No - I'll do no JavaScript support ;)


/*
Content of test.php:
------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>{sitename}</title>

<script language="JavaScript" src="/js/menu_items.php">
<!--
//-->
</script>

<script language="JavaScript" src="/js/menu.js">
<!--
//-->
</script>

</head>
<body>

<b>Just testing</b>
<script language="JavaScript">

<!--
new menu (MENU_ITEMS1, MENU_POS1, MENU_STYLES1);
//-->

</script>
</body>
</html>


/*
Content of menu_items.php:
------------------------
*/

require_once('DB/NestedSet.php');
require_once('DB/NestedSet/Output.php');

// Choose a database abstraction layer. 'DB' and 'MDB' are supported.
$nese_driver = 'DB';

// Set the DSN - see http://pear.php.net/manual/en/core.db.tut_dsn.php for details
$nese_dsn = 'mysql://XXX:XXX@localhost/test';

// Specify the database columns which will be used to specify a node
// Use an associative array. On the left side write down the name of the column.
// On the right side write down how the property will be called in a node object
// Some params are needed
$nese_params = array
(
"STRID" => "id", // "id" must exist
"ROOTID" => "rootid", // "rootid" must exist
"l" => "l", // "l" must exist
"r" => "r", // "r" must exist
"STREH" => "norder", // "order" must exist
"LEVEL" => "level", // "level" must exist
"STRNA" => "name",
"STLNK" => "link" // Custom - specify as many fields you want
);

// Now create an instance of DB_NestedSet
$NeSe = & DB_NestedSet::factory($nese_driver, $nese_dsn, $nese_params);
if(PEAR::isError($NeSe)) {
echo $NeSe->getCode().": ".$NeSe->getMessage();
}

// Fetch the tree as array
$nodes = $NeSe->getAllNodes(true);

// Set the basic params
$params = array(
'structure' => $nodes,
'options' => array(
),
'textField' => 'name', // Use the name column for the menu names
'linkField' => 'link', // Use the link column for the links
'currentLevel' => 1 // Start the ouput with this level
);

// This array contains the options needed
// for printing out the menu.
$options = array
(
// The style properties for the top level
'rootStyles' => array(

'onmouseout' => array(
'color'=>'#FF0000',
'background'=>'#000000',
'textDecoration'=>'none',
'border'=>"1px solid #FFFFFF",
'fontSize' => '11px',
'fontFamily' => 'Verdana, Arial, Helvetica, sans-serif',
'fontWeight' => 'bold',
'textAlign' => 'center',
'padding' => '2px'
// Set any JavaScript compatible style params here
// Note that this properties also have to exist in
// the child menu.
// Set them to 'none' or other values there
// to get another output
),
'onmouseover' => array(
'color'=>'#FFFFFF',
'background'=>'#000000',
'textDecoration'=>'none'

),
'onmousedown' => array(
'color'=>'#FFFFFF',
'background'=>'#000000',
'textDecoration'=>'none'

)
),
'childStyles' => array(
'onmouseout' => array(
'color'=>'#000000',
'background'=>'#CCCCCC',
'textDecoration'=>'none',
'border'=>"1px solid #FFFFFF",
'fontSize' => '11px',
'fontFamily' => 'Verdana, Arial, Helvetica, sans-serif',
'fontWeight' => 'normal',
'textAlign' => 'left',
'padding' => '2px'
),
'onmouseover' => array(
'color'=>'#FFFFFF',
'background'=>'#EEEEEE',
'textDecoration'=>'none'

),
'onmousedown' => array(
'color'=>'#FFFFFF',
'background'=>'#EEEEEE',
'textDecoration'=>'none'

)
),
// Geometry sets the positioning and the
// proportions of the menu
// It can also be set for the top level and the sublevels
// Note that this properties also have to exist in
// the child menu.
// Please look at the fine TigraMenu docs
// They have nice pictures describing the properties below
// Special settings are explained here
'rootGeometry' => array(
'width' => '120',
'height' => '21',
'left' => '119',
'top' => '0',
'block_left' => '169',
'block_top' => '121',
'hide_delay' => '200'

),
'childGeometry' => array(

// If you use '*' the width is considered to be x * max chars within this submenu
// e.g. 6 * 12
// This is useful if you want that the menu auto sizes with the menu item name's length
// The item width will can not be smaller than the root items with.
// You will have to try different values depending on the font/size you use
// If you want fixed with just remove the '*'
// e.g. 'width' => '100'
'width' => '*6',
'height' => '21',
'left' => '0',
'top' => '20',

// Sets the horizontal offset between different levels
// In this case the first submenu level after the root will have no offset
// After that we will have -5 offset (overlapping) between the items
'block_left' => '0,-5',

// Sets the vertical offset between different levels
// In this case the first submenu level after the root will have 20px offset
// After that we will have -10px offset (overlapping) between the items
'block_top' => '20,10',
'hide_delay' => '2000'
),
'menu_id'=>1 // This is the menu id used to call the menu from JavaScript:
// new menu (MENU_ITEMS1, MENU_POS1, MENU_STYLES1);
);


// Now create the menu object, set the options and do the output
$menu =& DB_NestedSet_Output::factory($params, 'TigraMenu');
$menu->setOptions('printTree', $options);
$menu->printTree();


// Have fun!
?>


Jedoch kommt da folgenden Fehlermeldung:


Fatal error: DB Error: no such table in /usr/share/php/PEAR.php on line 843


Mir iss klar, dass hier die Tabelle fehlt, aber wie kann ich die im TigraMenu angeben?

- -

Alle Zeitangaben in WEZ +2. Es ist jetzt 04:02 Uhr.