Testing a form with missing elements gives me an error with is ErrorController.php - php

I'm doing some testing to my login form but I notice that If I dont send all the expected parameters, I get this error:
Fatal error: Call to a member function hasResource() on a non-object in C:\demo\application\controllers\ErrorController.php on line 47
for example this test code gives me error:
public function testLoginPage ()
{
$this->request->setMethod('POST')->setPost(
array('username' => 'foobar');
$this->dispatch('/usuario/login');
}
But if I send all the elements everything works as expected:
public function testLoginPage ()
{
$this->request->setMethod('POST')->setPost(
array('username' => 'foobar','password' => 'secret');
$this->dispatch('/usuario/login');
}
Is this normal? I dont understard why I get an error on ErrorController.php, where is the connection?
(I thought that maybe is something that not loading, but why is it working when all elemnts are?)
Any help understanding this will be appreciated.
Thanks
Update:
I just change to an incorrect password for db database in the application.ini and that gives me the same error. Now I dont even think is the form but maybe some call at the bootstart that is depending to the Zend_Auth identity. But what means that Fatal error: Call to a member function hasResource() on a non-object? how to load that object?

Read the error message you get. You're calling hasResource() on a non-object in ErrorController.php. Your error controller is broken, but that's not really the issue here.
The issue is that there's an exception being thrown somewhere (possibly in your form, bootstrap, or anywhere really) which triggers the error controller. Fix or disable the error handler to get the exception message and stack trace to find out your problem.
To disable the error handler
$front = Zend_Controller_Front::getInstance();
$front->setParam('noErrorHandler', true);

Related

Call to undefined method Mail::setMessageType()

I have a website and it has a member registry (Way of Life). It uses phpmailer which I am not very familiar with. When you enter data and click register, it returns this:
Fatal error: Call to undefined method Mail::setMessageType() in
/home/u536535282/public_html/classes/phpmailer/phpmailer.php on line
989
The lines that this is referring to are shown below:
$this->error_count = 0; // reset errors
$this->setMessageType();
if (!$this->AllowEmpty and empty($this->Body)) {
throw new phpmailerException($this->lang('empty_message'), self::STOP_CRITICAL);
}
If someone colud tell me what i need to change, I would appreciate it, as it would get my site going again

Zend_forward error Cannot redeclare class Bootstrap

When I call (in my AdminController) the _forward function, i get this error
Fatal error: Cannot redeclare class Admin_Boot in /www/application/modules/admin/Boot.php on line 33
Actually, my website's structure is:
#Application/
|--Bootstrap.php
|--#modules
|----#admin
|------Boot.php
|------#controllers
|------#view
|----#default
|------Boot.php
|------#controllers
|------#view
(I have not placed everything, but the most important is here)
So, if I call the admin module, I'm gonna call Bootstrap.php, and after, Admin_Boot.php ...
All it's ok, it's just the _forward function who cause me some trouble ...
I need help
If you are using Zend_Loader::loadFile(), think to set the third argument to TRUE;
Zend_Loader::loadFile("Boot.php", $dirs, true);

Is this an uncatchable fatal error?

I'm writing an application, where I thought all the errors were being handled, including fatal ones.
But now I found one error that results in a white screen, and the error only shows up in the webserver log.
$nonExistentVar + 1; // Notice error, gets caught and pretty error is displayed
$existentVar->nonExistentMethod(); // Fatal error, gets caught and pretty error is displayed
$nonExistentVar->nonExistentMethod(); // White screen, error can be seen in nginx.error.log
Is the last error uncatchable? Or what could the problem be?
I'm using Silex, not sure if that matters.
The way I understand it, exceptions can be caught but fatal errors cannot. I am curious to know how you are 'catching' the fatal error in example #2?
Why not use a php is_a() test to see if $nonExistentVar is of the correct class before attempting to call the method? Or possibly in conjunction with method_exists() if you still don't know if a class has a given method available.
Try putting only the last line:
$nonExistentVar->nonExistentMethod();
That works for me, as Symfony\Component\Debug\ExceptionHandler sends the response immediately upon encountering the first Error:
public function handle(\Exception $exception)
{
if (class_exists('Symfony\Component\HttpFoundation\Response')) {
$this->createResponse($exception)->send();
} else {
$this->sendPhpResponse($exception);
}
}

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 ..

Magento 1.3.2.2: Fatal error: Call to a member function getUsername() on a non-object

In Magento 1.3.2.2 we get a fatal error:
Fatal error: Call to a member function getUsername() on a non-object in
.../app/design/adminhtml/default/default/template/page/header.phtml on line 31
During an order confirmation, Magento should make a transition to the success page. But we are getting that error instead.
An Admin header is shown with this error. If I refresh, I get to the success page where I should have been taken if everything was ok.
This error happens because header.phtml on line 31 has entry:
$this->getUser()->getUsername();
But getUser() method didn't return valid object. This method pretty simple and looks like this:
return Mage::getSingleton('admin/session')->getUser();
So, you should debug only one place: app/code/core/Mage/Admin/Model/Session.php
Only one method setUser() object to session
public function login($username, $password, $request = null) {
...
$this->setUser($user);
If user object loads and valid it is mean that you have problem with session it self:
check how cookies sets
cookies path and created time
It is not easy find the problem remotely without debugging. So I wish you success.
I had the same error and solved it as follows:
Backup the var folder as (var-back)
Create a new var directory
Backup the locks folder as (locks-back) {if available}
Create the locks directory
Refresh the URL

Categories