Answer the question
In order to leave comments, you need to log in
How to make automatic insertion of categories in doctrine tree from xml?
Hello!
There is an xml, a file for unloading goods from 1c, categories of goods are specified in the form level0=name, level1=name and so on.
Structure of a DB
Now I write a parser for entering in a database. Created doctrine entities. With all entities it is clear, except for categories.
Here's how it works with an example in the tree documentation
/** Inserting node in different positions **/
<?php
$food = new Category();
$food->setTitle('Food');
$fruits = new Category();
$fruits->setTitle('Fruits');
$vegetables = new Category();
$vegetables->setTitle('Vegetables');
$carrots = new Category();
$carrots->setTitle('Carrots');
$treeRepository
->persistAsFirstChild($food)
->persistAsFirstChildOf($fruits, $food)
->persistAsLastChildOf($vegetables, $food)
->persistAsNextSiblingOf($carrots, $fruits);
$em->flush();
/**
Tree example:
/Food
/Vegetables
/Onions
/Carrots
/Cabbages
/Potatoes
/Fruits
**/
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question