08-06-2023, 02:38 PM
I'm a beginner in cakephp. I want to create a custom query and retrieve data from a table in cakephp. I have a table called key_uniqueword in the database.
Here is my code:
MODEL:
key_uniqueword.php
<?php
class key_uniqueword extends AppModel{
var $name = 'key_uniqueword';
public function get()
{
$this ->query("SELECT * FROM key_uniqueword");
}
}
Controller:
ReadingManualsController.php
<?php
class ReadingManualsController extends AppController{
var $name = 'ReadingManuals';
function index(){
$this ->set('results',$this ->key_uniqueword-> get());
}}
view:
index.ctp
<!DOCTYPE html>
<?php
foreach($results as $result)
{
//display results here
}
?>
But I'm getting this error message.
Error: Call to a member function get() on a non-object
File: F:\xampp\htdocs\18\cake\app\Controller\ReadingManualsController.php
Line: 22
How can I correct this?
Here is my code:
MODEL:
key_uniqueword.php
<?php
class key_uniqueword extends AppModel{
var $name = 'key_uniqueword';
public function get()
{
$this ->query("SELECT * FROM key_uniqueword");
}
}
Controller:
ReadingManualsController.php
<?php
class ReadingManualsController extends AppController{
var $name = 'ReadingManuals';
function index(){
$this ->set('results',$this ->key_uniqueword-> get());
}}
view:
index.ctp
<!DOCTYPE html>
<?php
foreach($results as $result)
{
//display results here
}
?>
But I'm getting this error message.
Error: Call to a member function get() on a non-object
File: F:\xampp\htdocs\18\cake\app\Controller\ReadingManualsController.php
Line: 22
How can I correct this?