-3

Care to put light to the subject. Issue is that when I do what ever to code I find that code does not go further to retrieve data from table Sectors and table courses. I have applied find() I use CakePHP 4.x to make clear that it is latest version of CakePHP called Strawberry. I also do not understand that why does my code get affected while I apply simple code structure to run my code.

Take a look at code snippet to run a simple find query with CakePHP Strawberry.

$Sectors is not defined but I need to know a way to define and apply $Sectors variable so that I have given value for relative table structure.

Table Does not load because of a problem I do not understand yet but guys help me out I'll update my code and make use of real code that is to determine a structure for code that will work for CakePHP Strawberry.

code:

$this->loadModel('Sectors');
$this->loadModel('Courses');

$Sectors = $Sectors->find('all')->contain('Sectors', 'Courses');
pr($sectors);
$this->contain(['Sectors', 'Courses']);
$this->set(compact('sectors'));

To retrieve data from table so that I get data relation from Sectors and Courses table.

error:

Call to a member function find() on null

  • Are you using a framework ?? is `find` defined ?? – alithedeveloper Jan 30 '20 at 07:20
  • 2
    `$Sectors` is null, as the error message is pointing out. Where is it defined? – Jeto Jan 30 '20 at 07:41
  • thanks for your edit do that sure. – Prabhakar Siddhant Jan 30 '20 at 09:59
  • `$Sectors` doesn't exist, or is null – delboy1978uk Jan 30 '20 at 10:28
  • @alithedeveloper find in defined after load model i need to make find work in a way that i get result from both sectors and courses table does that make it clear for you guys to understand. – Prabhakar Siddhant Feb 11 '20 at 04:43
  • @Jeto $Sectors is a table defined in MySQL and i have called that table here to make a clear connection with variable $sectors. ask more i'll give detail reply to your question. i have not been able to solve that problem with given code snippet above. let me know what your point of view is regarding a solution to fetch query data from table with find query like: $sectors = $Sectors->find('all')->contain('Sectors', 'Courses'); – Prabhakar Siddhant Feb 11 '20 at 04:48
  • 1
    @delboy1978uk `$sectors` is defined at line 4 take a look i made an update to make code work as `$sectors` to `$Sectors` – Prabhakar Siddhant Feb 11 '20 at 04:55

1 Answers1

0

Answer is simple but problem is CakePHP would keep single model with multiple query but not multiple model with single query.