Skip to content

Instantly share code, notes, and snippets.

@scoumbourdis
Created May 18, 2019 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scoumbourdis/d296573d2d747d6b3387916c8beb60f6 to your computer and use it in GitHub Desktop.
Save scoumbourdis/d296573d2d747d6b3387916c8beb60f6 to your computer and use it in GitHub Desktop.
A quick example of a custom model with a custom query
<?php
use GroceryCrud\Core\Model;
use Zend\Db\Sql\Sql;
class customModel extends Model {
public function customInsert($insertId)
{
$sql = new Sql($this->adapter);
$select = $sql->select()
->columns(['customer_id'])
->from('customers');
$select->where([
'customers.customer_id = ?' => $insertId
]);
$row = $this->getRowFromSelect($select, $sql);
if ($row === null) {
return false;
}
$sql = new Sql($this->adapter);
$update = $sql->update('customers');
$update->where([
'customer_id = ?' => $insertId
]);
$update->set([
'customer_name' => 'Patata'
]);
$statement = $sql->prepareStatementForSqlObject($update);
return $statement->execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment