Search code examples
phpclassexpressnamespacesconcrete5

Namespace issue with Concrete5 Express List on Single Page


I'm trying to follow the tutorial for retrieving express entries as per this link:

https://documentation.concrete5.org/developers/express/creating-read...

However, I'm greeted with the following error message:

"Class 'Application\Controller\SinglePage\Concrete\Core\Express\EntryList' not found"

My code is as follows:

<?php  
namespace Application\Controller\SinglePage;
use PageController;
use Express;
class Search extends PageController
{
    private $cruise;
    public function view()
    {
        $entity = Express::getObjectByHandle('cruise');
        $list = new Concrete\Core\Express\EntryList($entity);
        $results = $list->getResults();
        $this->set('results', $results);
    }
}

Could anyone point me in the right direction?


Solution

  • The problem is in this line:

    $list = new Concrete\Core\Express\EntryList($entity);
    

    You can either do:

    $list = new \Concrete\Core\Express\EntryList($entity); // Notice the backslash
    

    Or you can import the EntryList class:

    <?php  
    namespace Application\Controller\SinglePage;
    use PageController;
    use Express;
    use Concrete\Core\Express\EntryList;
    
    class Search extends PageController
    {
        private $cruise;
        public function view()
        {
            $entity = Express::getObjectByHandle('cruise');
            $list = new EntryList($entity);
            $results = $list->getResults();
            $this->set('results', $results);
        }
    }