Bluz\Crud\Table::readOne PHP Method

readOne() public method

Get record from Db or create new object
public readOne ( mixed $primary ) : Row
$primary mixed
return Bluz\Db\Row
    public function readOne($primary)
    {
        if (!$primary) {
            return $this->getTable()->create();
        }
        $row = $this->getTable()->findRow($primary);
        if (!$row) {
            throw new NotFoundException("Record not found");
        }
        return $row;
    }

Usage Example

Example #1
0
 public function readOne($primary)
 {
     $filesArray = unserialize(Session::get('files'));
     $path = Config::getModuleData('menu', 'full_path');
     if ($filesArray) {
         foreach ($filesArray as $file) {
             $filename = $path . $file->getFullName();
             if (is_file($filename)) {
                 unlink($filename);
             }
         }
     }
     Session::delete('files');
     return parent::readOne($primary);
 }