public function view($slug = null, $id = null)
    {
        //This allows backward compatibility for URLs like `/photo/11`
        if (empty($slug)) {
            $slug = $this->Photos->findById($id)
                ->contain([$this->Photos->Albums->getAlias() => ['fields' => ['slug']]])
                ->extract('album.slug')
                ->first();

            return $this->redirect(compact('id', 'slug'), 301);
        }

        $photo = $this->Photos->findActiveById($id)
            ->select(['id', 'album_id', 'filename', 'active', 'modified'])
            ->contain([$this->Photos->Albums->getAlias() => ['fields' => ['id', 'title', 'slug']]])
            ->cache(sprintf('view_%s', md5($id)), $this->Photos->getCacheName())
            ->firstOrFail();

        $this->set(compact('photo'));
    }
public function view($slug = null, $id = null)
    {
        //This allows backward compatibility for URLs like `/photo/11`
        if (empty($slug)) {
            $slug = $this->Photos->findById($id)
                ->contain([$this->Photos->Albums->getAlias() => ['fields' => ['slug']]])
                ->extract('album.slug')
                ->first();

            return $this->redirect(compact('id', 'slug'), 301);
        }

        $photo = $this->Photos->findActiveById($id)
            ->select(['id', 'album_id', 'filename', 'active', 'modified'])
            ->contain([$this->Photos->Albums->getAlias() => ['fields' => ['id', 'title', 'slug']]])
            ->cache(sprintf('view_%s', md5($id)), $this->Photos->getCacheName())
            ->firstOrFail();

        $this->set(compact('photo'));
    }
public function view ( $ slug = null , $ id = null ) { //This allows backward compatibility for URLs like `/photo/11` if ( empty ( $ slug ) ) { $ slug = $ this -> Photos -> findById ( $ id ) -> contain ( [ $ this -> Photos -> Albums -> getAlias ( ) => [ 'fields' => [ 'slug' ] ] ] ) -> extract ( 'album.slug' ) -> first ( ) ; return $ this -> redirect ( compact ( 'id' , 'slug' ) , 301 ) ; } $ photo = $ this -> Photos -> findActiveById ( $ id ) -> select ( [ 'id' , 'album_id' , 'filename' , 'active' , 'modified' ] ) -> contain ( [ $ this -> Photos -> Albums -> getAlias ( ) => [ 'fields' => [ 'id' , 'title' , 'slug' ] ] ] ) -> cache ( sprintf ( 'view_%s' , md5 ( $ id ) ) , $ this -> Photos -> getCacheName ( ) ) -> firstOrFail ( ) ; $ this -> set ( compact ( 'photo' ) ) ; }
Views a photo
@param string $slug Album slug
@param string $id Photo ID
@return \Cake\Network\Response|null|void
Views a photo