1

This doesn't work, results in undefined variables in order-details.php

public function getJobById($jobId)
{
    $orderDetails = $this->jobModel->getJobById($jobId);
    $payments = $this->paymentModel->getAllPaymentsForJobOrder($jobId);
    $this->loadOrderDetailsPage();
}

public function loadOrderDetailsPage()
{
    include './order-details.php';
}

This works as expected:

public function getJobById($jobId)
{
    $orderDetails = $this->jobModel->getJobById($jobId);
    $payments = $this->paymentModel->getAllPaymentsForJobOrder($jobId);
    include './order-details.php';
}

I'm not sure I understand why.

herondale
  • 729
  • 10
  • 27
  • 1
    This is a *very* strange way to structure your code. But I suppose you could pass your variables to your second function as function arguments. Basically they're undefined because you're in the context of a new function, and those variables are only in the scope of the first function. I suspect whatever functionality goal you have would likely be better achieved some other way though, on a larger scope than what's presented here in this small example. – David Nov 22 '17 at 00:27
  • @David I see. Basically I'm trying to imitate the MVC behavior, and before, I've had a function that was solely for displaying a view. Honestly I'm not sure if that's the right way to do it or I should just load the view directly in the function, without using a second function solely for just displaying it. – herondale Nov 22 '17 at 00:30
  • You are getting MVC all wrong... [See this](https://stackoverflow.com/questions/5863870/how-should-a-model-be-structured-in-mvc/5864000#5864000) – IROEGBU Nov 22 '17 at 00:34
  • @IROEGBU How so? The code above is in my controller, not in my model, if that's what you meant based on the link you gave. – herondale Nov 22 '17 at 00:36

0 Answers0