How to create custom MySQL queries in CakePHP?

前端 未结 2 429
渐次进展
渐次进展 2020-12-16 05:30

I am trying to create my own MySQL queries in Cakephp.

This is my LocationsController.php:



        
2条回答
  •  -上瘾入骨i
    2020-12-16 06:13

    Location Controller should be:

    loadModel("Location");
            $this->LocationModel->getLocations(); // I will strongly discourage using get()
        }
    }
    

    Location Model should be:

    query("SELECT * FROM locations;"); // if table name is `locations`
            return $this->query("SELECT * FROM Location;"); // if table name is `Location` since your public name is `Location`
        }
    }
    

提交回复
热议问题