Created
May 18, 2019 16:18
-
-
Save scoumbourdis/d296573d2d747d6b3387916c8beb60f6 to your computer and use it in GitHub Desktop.
A quick example of a custom model with a custom query
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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