I am trying to digest one of cakephp tutorials and yesterday I stuck. The sample website is called Jobfinds, so I have table name "jobs".
Here is the code from JobsController :
<?php
namespace App\Controller;
use App\Controller\AppController;
class JobsController extends AppController{
public $name = 'Jobs';
/*
* Default Index Method
*/
public function index() {
//Set Query Options
$options = array(
'order' => array('Jobs.created' => 'asc' ),
'limit' => 4
);
//Get Job Info
$jobs = $this->Jobs->find('all', $options);
$this->set('jobs', $jobs);
}
}
?>
This code is in index.ctp but it doesn't show anything but it should.
<?php foreach($jobs as $job) : ?>
<p><?php echo $job['jobs']['title'];
?> </p>
<?php endforeach; ?>
When I put for example
<?php echo "something"; ?>
Then 'something' is being displayed so I figured that there must be just a small mistake that is does not fetch data from the table. I was trying for too long. I'm starting loosing my hair because of that. This tutorial is pretty awesome but there is used cakephp 2.x and I am using 3.x. so on every step I need to change something and up till now I succeeded but I stuck with this for good. Anyone can see where is the culprit? Why it doesn't fetch data from the table?
I have no errors in debug LOGS.
print_r($job) inside loop gives as below
Cake\ORM\Entity Object ( [id] => 1 [category_id] => 7 [user_id] => 1 [type_id] => 1 [company_name] => Tech Guy Computer Services [title] => Senior Graphic Designer [description] =>
Lorem ipsum dolor sit amet(more description in lorem ipsum
[city] => Burlington [state] => MA [contact_email] => contact@employer.com [created] => Cake\I18n\FrozenTime Object ( [time] => 2014-07-14T00:00:00+00:00 [timezone] => UTC [fixedNowTime] => ) [[new]] => [[accessible]] => Array ( [*] => 1 ) [[dirty]] => Array ( ) [[original]] => Array ( ) [[virtual]] => Array ( ) [[errors]] => Array ( ) [[invalid]] => Array ( ) [[repository]] => Jobs )
Cake\ORM\Entity Object ( [id] => 2 [category_id] => 7 [user_id] => 1 [type_id] => 1 [company_name] => Tech Guy Computer Services [title] => UX Designer [description] =>