PHP code example of spwashi / smphp
1. Go to this page and download the library: Download spwashi/smphp 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/ */
spwashi / smphp example snippets
$application = $this->app;
$dataLayer = $application->data;
# Instantiate a Model that we'll use to find a matching object (or throw an error if it doesn't exist)
$_sam_model = $dataLayer->models->instantiate('users');
$_sam_model->properties->id = 1;
# The Model PersistenceManager is an object that gives us access to standard ORM methods
## find, save, create, mark_delete (haven't implemented DELETE statements yet)
$modelPersistenceManager = $dataLayer->models->persistenceManager;
/** @var Model $sam */
# This would throw an error if the Model could not be found
$sam = $modelPersistenceManager->find($_sam_model);
if($sam->properties->first_name->value !== 'Samuel'){
$modelPersistenceManager->mark_delete($sam);
}else{
$sam->properties->first_name = 'Mr. Samuel';
$modelPersistenceManager->save($sam);
}