One of the new features of Dreamweaver CS5 is its ability to provide PHP code hinting, and not just for default language constructs: it has the ability to introspect existing code and classed to provide easy access to code hints.
Dreamweaver supports several common CMSs out of the box, such as Wordpress and Jomla, but ModX isn't one of them. Luckily, it's very easy to get Dreamweaver to begin code hinting for the ModX API, which is hugely useful if you are writing plugins or snippets.
There is an interface to set up Site Specific Code Hinting (as the feature is called) - just right click on any file in the Site panel, and choose "Site-Specific Code Hints". You can then select which PHP files should be scanned for functions and classes which will be hinted. Whatever you select is written into a special file in the site root called "dw_php_codehinting.config". However, in this case rather than a very verbose description of adding files within this dialog, I'll simply give you the contents you need for this file.
How to add the code hints
1. Create a file in the site root called "dw_php_codehinting.config". Paste the following contents inside it:
$(SITEROOT)/manager/includes/document.parser.class.inc.php
$(SITEROOT)/manager/includes/extenders/dbapi.mysql.class.inc.php
$(SITEROOT)/dw_php_codehinting.php
The first two lines simply act like includes - they tell Dreamweaver to load those PHP class files (which basically contain the ModX API classes) for every PHP page DW loads. However, it only loads the class definitions, it doesn't instantiate the classes - when we're creating plugins or snippets this is already done by the system in /index.php, and instantiating the DB API is done much further inside the code. Therefore to accommodate this, the last line of that file is where we begin to go a little off piste...
2. Create a file in the site root called "dw_php_codehinting.php". Paste the following contents inside it:
<?php
if (false) {
$modx = new DocumentParser();
$modx->db = new DBAPI();
}
?>
This seems like very odd code, and in truth, it is! Dreamweaver normally faithfully interprets PHP code in order to provide accurate code hinting, error hinting and introspection. But, there is a secret back door, a bit like a CSS hack, to allow PHP code to be executed by Dreamweaver but NOT by PHP on a web server. This structure is:
if (false) somethingThatOnlyDwWillDo();
Of course false will never == true in a production environment (and so would be nonsense code to write under normal circumstances) but Dreamweaver ignores this, and will actually run the code contained within the illogical if() statement. What we do here is instantiate the ModX API objects, making them available to Dreamweaver, which then goes on to read the class code and correctly code hint them.
3. Save and close both the files. It's probably a good idea to turn on cloaking for both files (In Site panel, select both files then right click and select Cloaking -> Cloak) to prevent them being uploaded to a live server.
4. To use, you just have to begin typing as you normally would - Dreamweaver will now hint all methods and properties of the API, e.g.


![]()

You can also use the if (false) technique within your own code to trick Dreamweaver into manipulating the way it code hints PHP.
Write a comment
Posts: 9
Reply #9 on : Thu July 01, 2010, 09:45:25
Posts: 9
Reply #8 on : Sat June 26, 2010, 01:27:56
Posts: 9
Reply #7 on : Sat June 26, 2010, 01:26:54
Posts: 9
Reply #6 on : Sat June 26, 2010, 01:26:31
Posts: 9
Reply #5 on : Sat June 26, 2010, 01:25:41
Posts: 9
Reply #4 on : Sat June 26, 2010, 01:22:35
Posts: 9
Reply #3 on : Thu June 17, 2010, 16:34:05
Posts: 9
Reply #2 on : Mon May 10, 2010, 18:56:57
Posts: 9
Reply #1 on : Mon May 10, 2010, 18:24:21