Ok, I’m probably being really stupid here, but I’m trying to migrate to CakePHP 3.0 and having trouble actually retrieving a page from the database and displaying it.
My pages database contains my site pages with fields id, name, content and a few other things. I want to find the page by name (name is unique).
So, in my Pages controller I have this:
$pages = TableRegistry::get('Pages');
$query = $pages->findByName('home');
$this->set('page', $query->toArray());
Then, in my view, in version 2.x I would have used something like
echo $page['Page']['content'];
but in 3.0 this isn’t working. I looked through the documentation and tutorials, and they seem to be saying that I should have something like
echo $page->content;
but when I try that I get the error : Trying to get property of non-object
If I do a var_dump on $page, I get:
array (size=1)
0 =>
object(Cake\ORM\Entity)[149]
protected '_properties' =>
array (size=4)
'id' => int 1
'name' => string 'home' (length=4)
'title' => string 'Home' (length=4)
'content' => string '...page content...'... (length=681)
protected '_original' =>
array (size=0)
empty
protected '_hidden' =>
array (size=0)
empty
protected '_virtual' =>
array (size=0)
empty
protected '_className' => null
protected '_dirty' =>
array (size=0)
empty
protected '_new' => boolean false
protected '_errors' =>
array (size=0)
empty
protected '_invalid' =>
array (size=0)
empty
protected '_accessible' =>
array (size=1)
'*' => boolean true
protected '_registryAlias' => string 'Pages' (length=5)
What am I doing wrong? Thanks for any help. Apologies again that this is a very basic question; I’m just totally stuck on it!