PHP code example of brocode / module-entityservices

1. Go to this page and download the library: Download brocode/module-entityservices library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brocode / module-entityservices example snippets


class UpgradeSchema implements UpgradeSchemaInterface
   {
       /**
        * @var SchemaBuilder
        */
       private $schemaBuilderFactory;
   
       /**
        * UpgradeSchema constructor.
        * @param SchemaBuilder $schemaBuilderFactory
        */
       public function __construct(SchemaBuilderFactory $schemaBuilderFactory) {
   
           $this->schemaBuilderFactory = $schemaBuilderFactory;
       }
   
       public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
       {
           $setup->startSetup();
           if (version_compare($context->getVersion(), '1.1.0', '<')) {
               $this->schemaBuilderFactory->create($setup)->withTable('entity')
                   ->withIntColumn('entity_id')->asIdentiy()->asUnsigned()->asNullable(false)->asPrimaryKey()->build()
                   ->withVarcharColumn('field_id)->asNullable(false)->build()
                   ->withIndex(['field_id'])->build()
                   ->withForeignKey('field_id, 'other_table', 'other_column')->actionNoAction()->build()
                   ->build();
           }
           $setup->endSetup();
       }
   }