Non-object when adding code into html - php

I am getting the following error:
Fatal error: Call to a member function error() on a non-object in /home/gamepla3/public_html/football/result.php on line 177
The line for this is
<?php echo $form->error("homescore"); ?>
I'm failing to see how this could be the case?
The thing worked fine before I added working code into my html document so it looked better.
Now I can't get it working??
EDIT.
When the code is not within HTML, it works fine.
Once I have it within the HTML, it throws back an error?
Has anyone seen anything like this before?

var_dump($form);
Well, this just require a little & simple debug logic
Confirm $form is a Form object, try this
$class_methods = get_class_methods('form');
foreach ($class_methods as $method_name)
{
echo "$method_name\n";
}
does error is a defined method for Form object?
Based on your comment, the error is not a define method for object Form, so
$form->setError('homescore');
$errors = $form->getErrorArray();
// or $errors = $form->getError();

Related

Call to a member function render_social_icons() on a non-object

i have received a Fatal error from logs its repeating same error.
I don,t understand what to do please help me out on this.
Eroor logs:
PHP Fatal error: Call to a member function render_social_icons() on a
non-object in content-single.php on line 190
Code :
<div class="fusion-sharing-box share-box">
<h4>
<?php echo __('Share This Story, Choose Your Platform!', 'Avada'); ?></h4>
<?php
echo $social_icons->render_social_icons( $sharingbox_soical_icon_options );
?>
Create an object of class then use it in cotent-single.php file.Before that you have to include file for that specific class.
$social_icons= new <Some class>;
$social_icons->render_social_icons( $sharingbox_soical_icon_options );
You have to share cotent-single.php that will give more idea.
$social_icons isn't what you're expecting it to be.
You're treating $social_icons as an object when you try to call the render_social_icons() method and it's generating an error because it isn't one.
Where are you defining $social_icons? Was the code copied/pasted from elsewhere? Without seeing more code it's difficult to help devise a solution beyond suggesting that you trace it back and find out where $social_icons is being defined.

PHP Fatal Error Call to Undefined. Stop it breaking page?

Please forgive me if this is a duplicate question. I have searched but cant come up with an answer.
I am getting a PHP fatal error: call to undefined in my Wordpress site.
I know why this is, I am calling a method in my template file that is defined in a plugin - if the plugin isnt installed, then the template throws the error.
Is there any way I can encapsulate this method so that if it fails, the fatal error doesnt stop the rest of the page loading?
Many thanks.
You can check if the function is defined before calling it.
<?php
if (function_exists('plugin_function')) {
plugin_function();
} else {
error_log('plugin is not activated');
die();
}
?>

Undefined index error in Cakephp

I am running an Ajax tutorial example and a line gives error in controller file. What I'm doing is if a field is blank and user blurs out of it an error will display below the field.
Here is the whole function in MessagesController.php
public function validate_form()
{
if($this->RequestHandler->isAjax())
{
$this->request->data['Message'][$this->request->params['form']['field']] = $this->request->params['form']['value'];
$this->Message->set($this->request->data);
if($this->Message->validates())
{
$this->autoRender = FALSE;
}
else
{
$error = $this->validateErrors($this->Message);
$this->set('error', $error[$this->request->params['form']['field']]);
}
}
}
The error line is this:
$this->request->data['Message'][$this->request->params['form']['field']] = $this->request->params['form']['value'];
And error is this
Undefined index: form [APP\Controller\MessagesController.php, line 30]
Actually the tutorial was based on previous version of Cake but I have made proper changes compatible with current version but still error shows. Can someone please tell me what might be wrong in this line or elsewhere in the code. Thanks a lot.
$this->request->params does not contain a form index.
I think you should be looking at your $this->request->data?
$this->request->params has only information about your request: the action, the controller, any named parameters and so on.
The error you get is actually normal.
Add comment with link to tutorial.

Fatal error: Call to a member function assistance required

I have taken over a website to complete.
The website works fine.
for some reason I get the following error:
Fatal error: Call to a member function navigate() on a non-object in C:\xampp\htdocs\studio.php on line 224
This is the code for the page at line 224:
if(!empty($_GET['nav']))
{
$params = null;
$params['listOrder'] = 'id desc';
$$_GET['nav']->navigate($params); <<<This is line 224
}
Any assistance will be greatly appreciated.
$$_GET['nav'] refers to an object dynamically, this object is not instanciated at the point of calling navigate(), or the variable passed to $_GET['nav'] does not correspond to a defined variable.
My problem has been resolved. after a strenuous search I found a phantom piece of code that was where it should not have been. Thank you all for your assistance. The code was:
$user = $_SESSION['usr'];

Fatal error: Call to a member function getPk() on a non-object (P4A, MySQL)

I'm Not too sure on what this error is, from looking around, it must be something to do with the database declarations. I'm trying to make a drop down box on my Widget, by selecting different fields of the database, different masks will be selected and will allow for different widgets to be made on later pages.
The part of my code where i think the error is, is:
$this->build("p4a_db_source", "login")
->setTable("meetingrooms")
->addJoin("login.meetingrooms",
"login.meetingrooms.MeetingRoom = login.meetingrooms.MeetingRoom",
array('position'=>'Ident'))
->addOrder("position")
->load();
$this->setSource($this->login);
$this->firstRow();
$this->build('p4a_field','location')
->setSource('login')
->setLabel('location')
->setValue('Please Select...')
->setType('select')
->setWidth(60);
$this->weight->label->setWidth(60);
I know its a similar question to my previous one, but its a different code entirely, but this one should be much easier to fix.
Thanks for the help.
The Stacktrace (Fatal error: Call to a member function getPk() on a non-object in C:\xampp\htdocs\p4a\p4a\objects\widgets\field.php on line 468) isn't indicating the line at which the error is occurring so i'm unsure where exactly the problem is originating from,
The rest of the code (including previous) is:
class main_dashboard_mask extends P4A_Base_Mask
{
public function __construct()
{
parent::__construct();
$this->setTitle("Dashboard");
$this->build('p4a_field','MeetingRooms');
$this->MeetingRooms->setLabel("This is the meeting room label");
$this->build('p4a_button', 'continue')
->setLabel('Continue?')
->implement("onclick", $this, "change");
$this->build('p4a_field','booking')
->setlabel('Viewing?')
->setType('checkbox')
->setValue(true);
$this->booking->label->setTooltip('If you are booking a meeting room, check this box');
$this->build("p4a_db_source", "login")
->setTable("meetingrooms")
->addJoin("login.meetingrooms",
"login.meetingrooms.MeetingRoom = login.meetingrooms.MeetingRoom",
array('position'=>'Ident'))
->addOrder("position")
->load();
$this->setSource($this->login);
$this->firstRow();
$this->build('p4a_field','location')
->setSource('login')
->setLabel('location')
->setValue('Please Select...')
->setType('select')
->setWidth(60);
$this->weight->label->setWidth(60);
$this->Meetingrooms();
}
private function Meetingrooms()
{
$this->build('P4A_fieldset', 'widgetframe')
->anchor($this->location)
->anchorLeft($this->booking)
->anchorLeft($this->continue)
->setLabel('Meeting Room Bookings');
}
}
I think you are not getting the object. That is why it's giving error of non-object.
Just print the object on which you are calling the method getPk(). If it is valid object then
only call that method.
i got it, sorry i was looking in the right place but didn't see where i was wrong...
where before the code was ->
$this->setSource($this->login);
$this->firstRow();
$this->build('p4a_field','location')
->setSource('login') // <- this is the error(the Pk variable hasn't been set here)
->setLabel('location')
->setValue('Please Select...')
->setType('select')
->setWidth(60);
$this->weight->label->setWidth(60);
$this->Meetingrooms();
the fix is ->
->setSource($this->login)
Thanks for the assistance =]
Do you have a full stacktrace ? What line of code exactly generates this error ?
Anyway, you have to locate the code where $object->getPk() is called. The error means that you're trying to use a function ->getPk() on an $object that is null ..

Categories