What Means Call to a Member Function on Boolean and How to Fix

What means Call to a member function on boolean and how to fix

Generally this error happens when a non-existent property of a controller is being used.

Tables that do match the controller name do not need to be loaded/set to a property manually, but not even they exist initially, trying to access them causes the controllers magic getter method to be invoked, wich is used for lazy loading the table class that belongs to the controller, and it returns false on error, and that's where it happens, you will be calling a method on a boolean.

https://github.com/cakephp/.../blob/3.0.10/src/Controller/Controller.php#L339

In your case the problem is that User (singular, for entities) doesn't match the expected Users (plural, for tables), hence no matching table class can be found.

Your custom method should go in a table class instead, the UsersTable class, which you should then access via

$this->Users

You may want to reread the docs, entities do not query data (unless you are for example implementing lazy loading), they represent a dataset!

Fatal error: Uncaught Error: Call to a member function on bool

Checking for the correct value of the $user variable should fix the error.

...
function image()
{
$user = $this->loadModel("user");

if(!$user || !$user->check_logged_in()){ // Here
header("location:" . ROOT . "login");
die;
}

$data['page_title'] = "Upload";
...

Then on $user is false condition will be
!false || !false->check_logged_in() which will lead to true.

Otherwise on $user is User:
!(object User) || !(object User)->check_logged_in() will call User::check_logged_in() method.

Fatal error: Call to a member function getWelcome() on boolean

Check http://freegento.com/doc/d7/d92/class_mage___core___model___layout.html#4c2f3ed0733b1d16c6b9d1d13898574f

When the block can't be found, the getBlock returns false instead of an object, and the error is thrown when you try to call getWelcome on this.

(definition of getBlock in case the link doesn't work):

{
if (isset($this->_blocks[$name])) {
return $this->_blocks[$name];
} else {
return false;
}
}

Add an if statement to check if the block exists before trying to operate on it.

error 500 with Call to a member function on bool

If your load() method returns false when the data isn't found, then you should be checking for this before you try any further operations on this value.

I've also changed the test to be

if($data !== false) {

so that if your method returns some other value which looks like false (0, null etc), then this will ensure it only picks up false...

if(is_numeric($param['id'])) 
{
$id = $param['id'];
//check if data exist
$data = $data->load($id);
if($data !== false) {
echo 'Data with id:'.$id.' exist';
}
else {
echo 'Cursor is empty. Data with id:'.$id.' doesnt exist!';
}
die();
}
else {
$f3->reroute('/');
}

How to fix this 'Call to a member function row() on boolean' error?

I think the problem is with the query:

SELECT * from sma_sales  desc limit 1 where customer_id = '$id'

Try something like this:

SELECT * from sma_sales where customer_id = '$id' order by `sales_date` desc limit 1

You need to use the ORDER BY clause to do the sorting.

Also, make sure you escape the $id before including it inside the query. Have a look at this.

Another suggestion is that, you could check whether the $result is set or not. Because in case of errors, it would return NULL. Read more about it here.



Related Topics



Leave a reply



Submit