How do I access the fields in my controller?

My method looks like this now:

 public function navigate(){

		$this->loadModel('Mealplans');
		$this->set('mealplans', $this->Mealplans->find('all'));
		$this->set(compact('mealplan')); 
		$mealplan->event_date = date_create();
		$this->set('event_date', $mealplan->event_date);
		$mealplan->end_date = date_create();
		$this->set('end_date', $mealplan->end_date);

	}

It shows that I added
$this->set(compact('mealplan'));

Now I get the error:
compact(): Undefined variable: mealplan

I’m at work now so I can’t work on the code but when I get home, I’m going to try putting everything in the template instead of the controller.

please don‘t get me wrong, but wouldn‘t it may help you, if you

  1. set up all your tables in your database with all relations properly named according to cakes conventions.
  2. bake all the code with your console (bake all…)

and then see what is missing and where you need help?

$this->loadModel('Mealplans');
$this->set('mealplans', $this->Mealplans->find('all'));

This is fine. Your template will have a variable called $mealplans which you can iterate over to do something with each mealplan.

$this->set(compact('mealplan')); 
$mealplan->event_date = date_create();
$this->set('event_date', $mealplan->event_date);
$mealplan->end_date = date_create();
$this->set('end_date', $mealplan->end_date);

You have never created a variable called $mealplan, so none of these will do anything useful. What are you actually trying to do? What’s the problem you’re trying solve? What are you trying to accomplish by setting the event and end date of a mealplan to today’s date?

I fixed it! In the template, I’m using

$event_date = date("Y-m-d", strtotime($mealplan->event_date));
$end_date = date("Y-m-d", strtotime($mealplan->end_date));

I can’t see in your code where you are only showing the meal plans belonging to the logged in user. Did you want to show all meal plans - the whole table? There is no where condition and you are passing the whole dataset. I am also guessing you are not looping in your template so you’re just showing the first record.

I think you need to add a few dummy users to your database, set them up with their own meal plans, and for testing have a couple with the same plan to ensure it will handle that too. I’m getting the feeling there is still a point-and-click approach to programming here. There is no doubt you are using code you don’t understand, specifically the set(compact()) as Zuluru pointed out, and which I went to pains to explain how both of those work.

I am just concerned the end-user’s data isn’t being secured.

I set the user id to 1 at the start of the code
<?php
$session = $this->request->getSession();
$user_id = $session->read(‘User.id’);

if (empty($user_id) || !isset($user_id) || $user_id == "" || $user_id == "0" || $user_id == "NULL"){ 
$user_id = 1;} ?>

I haven’t tested it out with other user ids yet.