Saturday 27 May 2017

php - Trying to get property of non-object MySQLi result

I have been working on to write a custom module in Drupal 7 and got the same error:



Notice: Trying to get property of non-object



My code is something like this:


function example_node_access($node, $op, $account) {
if ($node->type == 'page' && $op == 'update') {
drupal_set_message('This poll has been published, you may not make changes to it.','error');
return NODE_ACCESS_DENY;
}
}

Solution:
I just added a condition if (is_object($sqlResult)), and everything went fine.


Here is my final code:


function mediaten_node_access($node, $op, $account) {
if (is_object($node)){
if ($node->type == 'page' && $op == 'update') {
drupal_set_message('This poll has been published, you may not make changes.','error');
return NODE_ACCESS_DENY;
}
}
}

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...