public function get($primaryKey, $options = [])
    {
        $key = (array)$this->getPrimaryKey();
        $alias = $this->getAlias();
        foreach ($key as $index => $keyname) {
            $key[$index] = $keyname;
        }
        $primaryKey = (array)$primaryKey;
        if (count($key) !== count($primaryKey)) {
            $primaryKey = $primaryKey ?: [null];
            $primaryKey = array_map(function ($key) {
                return var_export($key, true);
            }, $primaryKey);

            throw new InvalidPrimaryKeyException(sprintf(
                'Record not found in endpoint "%s" with primary key [%s]',
                $this->getName(),
                implode($primaryKey, ', ')
            ));
        }
        $conditions = array_combine($key, $primaryKey);

        $cacheConfig = isset($options['cache']) ? $options['cache'] : false;
        $cacheKey = isset($options['key']) ? $options['key'] : false;
        $finder = isset($options['finder']) ? $options['finder'] : 'all';
        unset($options['key'], $options['cache'], $options['finder']);

        $query = $this->find($finder, $options)->where($conditions);

        if ($cacheConfig) {
            if (!$cacheKey) {
                $cacheKey = sprintf(
                    "get:%s.%s%s",
                    $this->getConnection()->configName(),
                    $this->getName(),
                    json_encode($primaryKey)
                );
            }
            $query->cache($cacheKey, $cacheConfig);
        }

        return $query->firstOrFail();
    }
public function get($primaryKey, $options = [])
    {
        $key = (array)$this->getPrimaryKey();
        $alias = $this->getAlias();
        foreach ($key as $index => $keyname) {
            $key[$index] = $keyname;
        }
        $primaryKey = (array)$primaryKey;
        if (count($key) !== count($primaryKey)) {
            $primaryKey = $primaryKey ?: [null];
            $primaryKey = array_map(function ($key) {
                return var_export($key, true);
            }, $primaryKey);

            throw new InvalidPrimaryKeyException(sprintf(
                'Record not found in endpoint "%s" with primary key [%s]',
                $this->getName(),
                implode($primaryKey, ', ')
            ));
        }
        $conditions = array_combine($key, $primaryKey);

        $cacheConfig = isset($options['cache']) ? $options['cache'] : false;
        $cacheKey = isset($options['key']) ? $options['key'] : false;
        $finder = isset($options['finder']) ? $options['finder'] : 'all';
        unset($options['key'], $options['cache'], $options['finder']);

        $query = $this->find($finder, $options)->where($conditions);

        if ($cacheConfig) {
            if (!$cacheKey) {
                $cacheKey = sprintf(
                    "get:%s.%s%s",
                    $this->getConnection()->configName(),
                    $this->getName(),
                    json_encode($primaryKey)
                );
            }
            $query->cache($cacheKey, $cacheConfig);
        }

        return $query->firstOrFail();
    }
public function get ( $ primaryKey , $ options = [ ] ) { $ key = ( array ) $ this -> getPrimaryKey ( ) ; $ alias = $ this -> getAlias ( ) ; foreach ( $ key as $ index => $ keyname ) { $ key [ $ index ] = $ keyname ; } $ primaryKey = ( array ) $ primaryKey ; if ( count ( $ key ) !== count ( $ primaryKey ) ) { $ primaryKey = $ primaryKey ? : [ null ] ; $ primaryKey = array_map ( function ( $ key ) { return var_export ( $ key , true ) ; } , $ primaryKey ) ; throw new InvalidPrimaryKeyException ( sprintf ( 'Record not found in endpoint "%s" with primary key [%s]' , $ this -> getName ( ) , implode ( $ primaryKey , ', ' ) ) ) ; } $ conditions = array_combine ( $ key , $ primaryKey ) ; $ cacheConfig = isset ( $ options [ 'cache' ] ) ? $ options [ 'cache' ] : false ; $ cacheKey = isset ( $ options [ 'key' ] ) ? $ options [ 'key' ] : false ; $ finder = isset ( $ options [ 'finder' ] ) ? $ options [ 'finder' ] : 'all' ; unset ( $ options [ 'key' ] , $ options [ 'cache' ] , $ options [ 'finder' ] ) ; $ query = $ this -> find ( $ finder , $ options ) -> where ( $ conditions ) ; if ( $ cacheConfig ) { if ( ! $ cacheKey ) { $ cacheKey = sprintf ( "get:%s.%s%s" , $ this -> getConnection ( ) -> configName ( ) , $ this -> getName ( ) , json_encode ( $ primaryKey ) ) ; } $ query -> cache ( $ cacheKey , $ cacheConfig ) ; } return $ query -> firstOrFail ( ) ; }
Returns a single record after finding it by its primary key, if no record is
found this method throws an exception.

### Example:

```
$id = 10;
$article = $articles->get($id);

$article = $articles->get($id, ['contain' => ['Comments]]);
```

@param mixed $primaryKey primary key value to find
@param array|\ArrayAccess $options options accepted by `Endpoint::find()`
@throws \Cake\Datasource\Exception\RecordNotFoundException if the record with such id could not be found
@return \Cake\Datasource\EntityInterface
@see \Cake\Datasource\RepositoryInterface::find()
Returns a single record after finding it by its primary key if no record is found this method throws an exception .