How to debug PHP MVC site in NetBeans - php

I need to debug MVC site (PrestaShop eshop solution) to find methods called on specific actions and tweak them. I tried to read the code, but I think that debugging is the only option.
I'm using Netbeans along with Apache. I've got set up a PHP project and enabled xdebug.
When I debug the project it starts at index.php. Pressing f5 will finish the debuggin no matter where I place the breakpoint. Pressing F7 seems to display everything that's being touched.
My question is: how do I debug the way I want? Meaning placing a breakpoint somewhere and waiting for it to be touched?

If you're looking for a specific method and you know the method name, in NetBeans, do a single left click on your project folder, then ctrl-F to open the "find" thingy. Type in your missing method and NB will tell you which file it's in so you can alter it.

Related

debugging a Yii web application using Zend Debugger in Eclipse

I have Zend debugger running successfully in Eclipse but I don't understand how to debug a Yii project. I.e, I can debug a single page PHP script but I don't know what the configuration options are supposed to be for a Yii web application.
For example, I was thinking the Controller file would be the file I would select to actuall debug but it says the file can't be found. I've attached a screen shot of what the options are.
I've used the Firefox Zend Debugger extension and that works great. Now, I just want to know how to do the equivalent of that in Eclipse.
The basic options are: File and URL
Have you debugged other applications using Eclipse? If so, it shouldn't be much different:
I'm usually debugging on /, meaning I login to the application, go wherever I need to, then prepare the debugged scenario (including breakpoints where appropriate). Next, I run a "general" debug session -> a new tab is opened on the browser. I ignore this tab and instead go back to the tab where I prepared the scenario I want to debug and continue there.
I usually go with marking / or /index.php as the "debug entry point" (or whatever the term is). If needed (I don't think I needed to with Yii), I would have config some "paths" that tell the IDE that "/" is translated/represented by HTDOCS. Again, I don't think I needed to with Yii (but I debugged little with Yii thus far).
I once had a blog post on debugging Drupal with PDT (which is Eclipse) and xDebug (which is an alternative to the Zend Debugger and essentially the same). You might find it useful: link.
Good luck!
When in a framework, work within the framework rules. If something's not working, don't try to review the code step-by-step. That's unproductive, because you will pass through dozens of encapsulated functions with no discernible order. Yii is built on a singleton pattern, which in my experience makes it just about impossible to know where you are or where you're going.

Aptana autocomplete shows only local stuff

I am trying out Aptana for general PHP development, i loaded an old CakePhp project to test the autocomplete and all i can get are the local functions and variable and absolutely none of the inherited ones, which kinda ruins the whole thing. Is there a setting i dont know about that fixes this?
apparently i needed to set up a "Nature" to PHP, the default was some eclipse.something version. Aptana reindexed the file and it works now.
The original poster was correct in adding PHP to the "Nature" of the project, however he did not provide how to do it. I also had the same problem and once I added PHP to the "Nature" selection list the autocomplete provided the options for inherited classess as well.
To add the PHP Nature:
Right click on your project in the Project Explorer View
Click on Properties
In the "Properties for project" window, select Project Natures in the left list box
In the Project Natures window, place a tick next to PHP
Click on OK button
that should get you the autocomplete list.
AJ
I haven't used aptana for PHP, but since it's based on Eclipse I assume the cake folder (in the same level as your app folder usually) needs to be added to your project path.
You can go into the properties of your project and either add it to the path or add it to the libraries.
I usually setup my project to point to the whole folder so I don't need need to do this step, but my Eclipse installation will pick up the inherited methods just fine.

Inside Eclipse PDT whats the purpose of "PHP include path" in project properties?

Was wondering when we right click on project folder in php explorer then there is an option "Php include path" it does not edit include_path property of php.ini . Hence even specifying include path using this option it does no different to project then whats its purpose of it??
Its is used to link two projects together within eclipse. If one project includes code from another project, eclipse is not aware of the connection and only evaluates the code with the project you are in. So if you try and use a function from another project for example, there would be no auto complete etc for that function.
By adding the second project to your include_path you are telling eclipse that you are using that project and all that projects classes, functions etc will be added to the auto complete and documentation prompt.
You are still required to connect the two by code.
The webserver (more accurate: The interpreter process created by the webserver) cannot know, that you even use an IDE to write your scripts, so its also impossible for it to know the project settings. If you execute it from within eclipse, it provides a custom php.ini, that contains the given include-path.

How do you find the block of code you are looking for in Magento?

I have been struggling with a stupid situation. A customer has asked me to alter his 'advanced search' page to add a few options. The URL of this page is like http://www.domainname.com/index.php/catalogsearch/advanced/
This is a Magento store and I have no experience with this framework. I tried to learn it but found the learning curve too steep to gain enough knowledge to finish the project on-time.
So I first made a small PHP tool that searches in all source files for a search term and reports back te number of hits. I used this tool to look for unique strings that appear on the advanced search page. But the text is nowhere to be found!
My next attempt was looking at the database to find the string. So I exported all DB data and copied the resulting queries into my code editor and searched again, and found nothing!
This is very awkward and is driving me mad. I cannot find the block of code that outputs the advanced search options!
'ANY' help would be MUCH appreciated.
Thanks,
Majid
So far I've been using the following tactics on a local dev box - don't try this on a live store obviously!:
Turn on Template Path Hints + Block Names in System -> Config -> Developer. This will get you to the phtml file that does the final render and also the block object type that it uses. Unless you've IP limited this, every visitor will see these!
Then in the phtml files to dig further you can easily Zend_Debug::dump($var) to inspect the variable/object in question and find the object type etc.
Search in your editor or grep through /app/code directories to find which files define the object type you've just found - although as it based on Zend the correct file path can be worked out most of the time from the object class.
Also
A handy trick is to deliberately insert an error in a php/phtml file, Magento gives you a nicely formatted error screen with a call stack which is interesting reading
echo() statements in the core files normally work pretty well, in the Magento set up they don't normally trigger the html headers to be sent at the wrong time
Use an IDE like Netbeans/Eclipse/Zend studio etc and put all the Magento code into your project, the resulting phpdoc information, 'open declaration' and code assist will save you hours of searching
Spend the time to get Xdebug working on your test server with an IDE that allows you to make use of it. The easiest one I've found to setup from scratch (on a Mac) is a local Mamp install with Netbeans as the IDE - the Netbeans site will walk you through this, once you've got this working well you can forget about most of the other tricks!
These are just the things I've tried so far - more suggestions please!
I've still not found a technique to debug config problems from XML issues in the multitude of XML files that Magento uses, problems here tend to fail silently and are really hard to track down as a result + the xml documentation is awful.
The URLs in Magento tell you where the template files are for a certain module.
For example, when you're looking for catalogsearch/advanced/, all template files are location in app/design/frontend/default/your-theme/.
Look inside that folder and it should be obvious. You will have a folder called catalogsearch and inside that a folder called advanced; inside which there are two files:
form.phtml
result.phtml

CodeIgniter with Eclipse PDT, is clean integration possible?

I am attempting to setup codeigniter with eclipse but am getting project errors. From what I understand this should be as simple as creating a new project in eclipse and pointing to the root directory of codeigniter. This properly loads up the codeigniter files but eclipse reports several errors. Looking into the files, it seems like the errors are coming from html files and/or files that print html. For instance, footer.php is showing up as having an error because there is a closing tag but no opening tag. Any suggestions on how to overcome this? At this point would code completion / debugging be too much to ask for as well?
UPDATE: so from what I am gathering from the response below (and searching around on the web) is that when using codeigniter with eclipse one can only take advantage of the code completion / editing features? I also noticed that I am getting NoClassDefFoundError when attempting to open some of the .php files in the eclipse project tree for editing. Surely I must be missing something and there is a way to achieve tighter integration with codeigniter and eclipse? (i would strongly prefer to stick with eclipse as opposed to switching ides) Or maybe this is an issue with my eclipse/pdt setup?
UPDATE 2: I just downloaded the latest eclipse version (galileo) and it seemed to fix all of these issues! except for debugging of course ...
you can achieve tighter integration by initializing the Ci core classes in CI_Base constructor which will also allow you to get auto complete for core classes check out these links:
http://www.gostomski.co.uk/codeigniter/getting-full-auto-complete-with-codeigniter-in-eclipse
http://hetal.wordpress.com/2009/09/04/working-with-eclipse-and-code-igniter/
you will get lots of html errors because the html has been broken into chunks
and is not a complete document
just ignore them thats what i do (there are settings somewhere that control what errors are validated against in eclipse)
i still use the php/html/js code completion and it works fine even with the errors
if you are using svn version control, add subclipse plugin, so you can do that from within eclipse too
Try Aptana.
The last time I checked I was able to do a step by step debug on it and did not see any errors in my project. It is also built on eclipse, so there is nothing new to learn.
For what it's worth, I have been able to get debugging to work using XDebug and the Netbeans IDE. If you cannot get debugging to work in Eclipse you might give Netbeans a try - if for no other reason, to have the ability to debug should you ever need to step through your application's code...

Categories