views:

626

answers:

4

So I've just recently made the step from ad hoc debugging with dump, print_r and echo to some more sophisticated methods and I'm having a struggle.

I work with Zend Framework, Aptana and Zend Debugger.

At this moment I'm trying to debug a custom controller and whatever I try I don't get to my breakpoint which I understand since there is authentication in between and using the menu...

QUESTIONS: How can I make my application break at the point of authentication, login in the browser, navigate to a certain uri and then continue debugging?

What are good places to set breakpoints in Zend Framework with MVC?

+1  A: 

Wouldn't it be easier to set up a constant such as:

define('MODE_DEBUG', 1);

Then check in the authentication process:

if($obj->myLoginMethod() || constant('MODE_DEBUG') == 1){

}

Noone will be able to inject into that constant and the worst thing that can happen is you end up leaving debug mode on my mistake...

Which you could put a check before the definition:

define('MODE_DEBUG', (false !== strpos($_SERVER['HTTP_HOST'], 'dev.mysite.com') ? 1 : 0));
Jay
that's quite a good idea and might solve half of my problems... I still would like to know how ppl debug applications written with zend framework...
tharkun
A: 

You want to change the current user's authentication details mid-way through a request?

I don't think this is possible. Zend Debugger is pretty much a read-only tool. Even if it were, you're assuming that whatever framework you're using can handle this. That would mean it would have to constantly try to synchronize it's internal state with changing input data.

I think instead of asking us how to solve this specific problem, you should be telling us why you need to change authentication. It sounds like you're launching a script in your debugger, which fails because you have no user session.

Zend Debugger has a browser toolbar (http://files.zend.com/help/Zend-Studio-Eclipse-Help/zend_debugger_toolbar.htm) that allows you to start a the debugger for your current page; the debugger will have all information that the browser would have sent: cookies, post data, etc. There's even a "debug next page" setting which helps you debug POST forms. It sounds like this is what you want.

Josh
I don't have Zend Studio and this toolbar only works with Zend Studio. I remember having done something like that already. The application was waiting for me to step in and over and out in the debugger and then I could navigate and resume debugging...
tharkun
+1  A: 

Maybe you just need to rethink the dump solution (I like the idea of using breakpoints but turned back after hiccups like your experienced and I use Zend Studio). To debug my applications I make use of Zend_Log and the firebug writer for Zend_Log. The firebug outputs the log to firebug (NB you must have the firephp extension for firefox installed as well). Store the logger in your registry and you can accomplish a lot of debugging without messing up your views with ugly dumps.

Akeem
that sounds pretty promising too, I'll give it a go!
tharkun
A: 

Ok so I played with zend debugger some more. (your question stirred up old demons) and I finally figured out the "proper" way to debug. To answer your initial question to debug after login I would say install the zend toolbar for firefox or IE. To the right of the Debug menu item there is a drop down with some options. One of the options is "next page". So you can go to your login screen select "Next Page" and then put in your credentials and submit and the NEXT page is what is debugged.

Akeem
can you update your first answer and delete this one, please!
tharkun
I can't use the zend toolbar since I don't have zend studio.
tharkun