PHP code example of wernerdweight / dobee

1. Go to this page and download the library: Download wernerdweight/dobee 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/ */

    

wernerdweight / dobee example snippets


	

	$dobee = new \WernerDweight\Dobee\Dobee('path/to/configuration/file.yml','path/to/strore/generated/entities','Your\\Namespace\\To\\Generated\\Entities');


		$options = [
			'--dump',	/// outputs SQL for changes to be made to the database
			'--force'	/// forces changes to the database and regenerates php classes
            '--generate-entities'   /// forces regeneration of entity classes even if no changes were made to the model (must be used together with --force)
			/// no more options available at the moment
		];
		
		$dobee->generate($options);

	
		$db = $dobee->getProvider();

		/// FETCH SINGLE RESULT
		/// 'article' stands for entity name as configured in YAML configuration file
		/// 1 stands for ID of requested article
		$article = $dp->fetchOne('article',1);		/// will return either object of class Article or null

		/// sample of how to access properties of an Article (confront configuration above)
		echo $article->getTitle();
		echo $article->getAuthor()->getFirstName();	/// author is lazy-loaded from database when needed
		if(!is_null($article->getCategories())){	/// categories are lazy-loaded from database when needed
			foreach($article->getCategories() as $category){
				echo $category->getTitle();
			}
		}

		/// FETCH MULTIPLE RESULTS
		/// options are not mandatory - if omitted all items will be loaded form the database
		$options = array(
			'leftJoin' => array(
				'this.author' => 'author',
				'author.address' => 'adress'
			),
			'where' => array(
				'this.title' => array(
					'operator' => 'like',
					'value' => '%microbe%'
				)
				'this.id' => array(
					'operator' => 'gte',
					'value' => 4
				)
			),
			'order' => array(
				'this.title' => 'asc',
				'this.id' => 'desc'
			),
			'limit' => array(
				'firstResult' => 0,
				'maxResults' => 10
			)
		);

		$articles = $db->fetch('article',$options);