Doctrine, a package, and C5 version 8

Permalink
Sounds like the proper way to utilize the database in a package is to do so through doctrine, true? There is some documentation, however, not sure if it is applicable. Triedhttps://github.com/mainio/c5_entities_example,... however, results in errors and is likely not applicable for version 8. Any recommendations how to get something small up and running? Thanks

 
JohntheFish replied on at Permalink Reply
JohntheFish
Primary tables for blocks in a package should be declared with block db.xml (and similar for packaged attributes). Other tables in a package could be declared with a package level db.xml or with doctrine entities, or a mix of the 2. Its up to you what suits your application and your preferences..
NotionCommotion replied on at Permalink Reply
Thanks John,

When you referenced "db.xml", are you referring to Doctrine XML for ORM metadata or something specific to just C5? Looks like either XML or annotations are allowed. Typically, I use XML but will likely just use annotations. Unless C5 uses some sort of entity value schema, I am assuming the package controller needs to be able to modify the DB schema, true?
JohntheFish replied on at Permalink Reply
JohntheFish
Blocks and packages can have a db.xml file that is used by the core to create tables when installed. The best format for those files is the format based on doctrine, though a legacy c5 format is also supported.

https://documentation.concrete5.org/developers/packages/custom-datab...
NotionCommotion replied on at Permalink Reply
Thanks again John,

Are these Doctrine db.xml files located in the root directory similar to the legacy dbl.xml files?

Please confirm that these Doctrine db.xml files need not be named "db.xml", and any file which contains xmlns="http://www.concrete5.org/doctrine-xml/0.5" will be parsed.

If using Doctrine db.xml files, can entities be used to interact to the DB?

No need to create the traditional Doctrine bootstrap file, right?

Any reason I need to learn about Src namespace (capital S)?
JohntheFish replied on at Permalink Reply
JohntheFish
For a block, in the same dir as the block controller. For a package, in the same dir as the package controller.

See
https://documentation.concrete5.org/developers/working-with-blocks/c...

https://documentation.concrete5.org/developers/packages/custom-datab...
mlocati replied on at Permalink Best Answer Reply
mlocati
Some time ago I wrote https://github.com/mlocati/my_boats...
It's a simple package that uses Doctrine entities to store data
NotionCommotion replied on at Permalink Reply
Thanks mlocati, I am up and running. Sometimes a working example is the best approach. Well written and documented. Would be nice for the C5 documentation to have links to examples such as Boats.

Also, as an added bonus, I learned how to install single pages using xml, and no longer need to use my custom install approach.

private function installSinglePages($pkg)
    {
        //Change to use installXml.  See example athttps://github.com/mlocati/my_boats...
        foreach(self::SINGLE_PAGES as $route=>$properties) {
            $sp = SinglePage::add($route, $pkg);    //returns \Concrete\Core\Page\Page
            if($spProps=array_intersect_key($properties, self::PAGE_PROPERTIES)) {
                if(isset($spProps['cName'])) {
                    $spProps['cName']=t($spProps['cName']);
                }
                $sp->update($spProps);    //Returns null
            }
            if(!empty($properties['exclude_nav'])) {
                $sp->setAttribute('exclude_nav', true);    //Will not put in menu.  Returns Concrete\Core\Entity\Attribute\Value\PageValue
            }
        }