Thursday Jul 24, 2008

Custom code folding in PHP editor improved

Last week I wrote article about code folding in PHP editor. Yesterday I have improved a little the custom fold. Now it allows to define, whether the fold will be by default collapsed and also the description of the fold.

From the picture should be clear that the custom fold is defined via element <editor-fold>, which can have two optional attributes. The attribute defaultstate with the value collapsed, says that the fold is collapsed when the file is opened. If you don't use this attribute, then the fold will not be collapsed after opening file by default. The second attribute is desc, where you can define a description of the fold. This description is displayed, when the fold is collapsed.

Because writing the open element can take time, you can create a code template for this.

  • Go to the Tools -> Options and in Editor category select Code Templates tab.
  • Select PHP in  Language combobox.
  • Press New button and enter an abbreviation for the code template. I have choosen cusf.
  • In the Expanded Text tex area write:

    <editor-fold defaultstate="collapsed" desc="${cursor}">

  • Close the Option dialog

The exresion ${cursor} marks the position, where cursor in editor is placed after expanding the code template.

Now when you write cusf and press TAB, then the text cusf is replaced with the defined template.

Friday Jul 18, 2008

Code Folding in PHP editor

What is code folding? I have looked for a definition and I have found this at wikipedia:

Code folding is a feature of some text editors, source code editors and IDEs that allows the user to selectively hide and display sections of a currently-edited file as a part of routine edit operations. This allows the user to manage large regions of potentially complicated text within one window, while still viewing only those subsections of the text that are specifically relevant during a particular editing session.

The PHP editor, like other editors in NetBeans, provides this functionality. By default no fold is collapsed. The setting you can specify in general editor options (Tools -> Options -> Editor).  On the picture below you can see which folds are supported in PHP and how they are mapped in editor options.

When you collapse a fold, you can see the hidden content, if you place the mouse cursor over the fold description.

The PHP editor also supports custome folds, which are defined by user. At the line, where you want to start the fold, place comment //<editor-fold> and at line where the fold should end place //</editor-fold>. Content between these tags, will be folded. These folds can be also nested.


The functionality, which provides the custome folds, is available from today. It is available in development builds or you have to wait until NetBeans 6.5 Milestone 2 will be published.


Monday Jul 14, 2008

Howto check xdebug installation

Petr in one of his recent entries mentions how to install xdebug in Ubuntu. I would like to add a very simple test how to verify that xdebug is properly installed on any supported platform. Naturally the most straightforward test would be to use debugger in NetBeans PHP IDE. Definitely, but maybe you haven't installed NetBeans yet, so I've decided for different approach - just write a very lightweight test listening to a connection on port 9000 (default one for xdebug). Which language to choose? Not much important but why not PHP? So, here we go:

screesnhot: verification code testing proper installation of xdebug

Now if we have a code (let's choose filename like "dbgtest.php") we can use it. Two simply steps should be enough to verify that xdebug was properly installed:

  1. run the code from command line (e.g. /usr/bin/php dbgtest.php)
  2. start debug session for arbitrary file from within a browser window (e.g. http://localhost/index.php?XDEBUG_SESSION_START=mysession)
If xdebug is properly installed then script started in step 1. should print message like "connection established: Resource id #5". If no message is printed and the script is still running, then xdebug isn't installed properly or uses different port or whatever else. So, kill the running process and investigate where the problem is, but this is the other story.


Thursday Jul 10, 2008

How to set up NetBeans to view .htaccess in Project or Files view

A few days ago I run in an issue that by default NetBeans doesn't show files which starts with dot, which is exactly the case of .htaccess file. This is the tip how to do it.

Go to the Options->Miscellaneous->Files and the content of Ingnored Files Pattern field replace with:

\^(CVS|SCCS|vssver.?\\.scc|#.\*#|%.\*%|\\.(cvsignore|svn|DS_Store)|_svn)$|~$|\^\\.(?!htaccess$)

If you have already .htaccess in the project and the file is not still displayed, then close the project and open again. There is issue #139582, which is entered against the project.


Sunday Jul 06, 2008

Ubuntu, PHP, NetBeans - part II

In my last entry I have described, how to install PHP, Apache and MySQL in Ubuntu 8.04 from Ubuntu repositories. NetBeans IDE is written in Java, so before installing NetBeans you have to install Java. This entry is about how to install Java environment in Ubuntu.

You can find a few Java environment like openJDK, Cacao or Kaffe in the default Ubuntu repositories. I have tried to run NetBeans on top of openJDK withouth a problem, I haven't try Cacao or others. I suggest to use Sun Java, because NetBeans are tested mainly with Sun Java.

You can download JRE (Java Runtime Environment) or JDK (Java Development Kit) from Sun web.  For running NetBeans, JRE is enough. NetBeans supports the latest two releases, so today Java 1.5 and Java 1.6 are supported. Java 1.6 uses native look and field and on the pictures below you can compare how NetBeans looks, if there are running on top of Sun Java 1.5 and Sun Java 1.6 .

There steps how to install Sun Java 1.6 :

  1. From Application menu choose Add/Remove... item



  2. The Add/Remove Application dialog is open. In Show combo box select All Available Applications.



  3. Write "Sun Java" in the Search box and Sun Java 6 Runtime should be displayed.



  4. Check Sun Java 6 Runtime and click on Apply Changes button. Durig the installation you will be prompted to accept the licence.

  5. You can check, whether the JRE is installed correctly. Open a terminal and write command java -version. You should see similar output as on the picture.



Sunday Jun 29, 2008

Ubuntu, PHP, NetBeans - part I

This article is about installing PHP environment - PHP, Apache, MySQL and xDebug in Ubuntu 8.04. Everything is available through the default Ubuntu repositories, so it should not be hard. I did this last week, when I prepared a machine for our UI study. It's expected that you have already installed Ubuntu or you use VirtuaBox and you have installed Ubuntu as a virtual machine.

Open a terminal. You will need to install all the parts as root, so you have to execute commands trough sudo or  you can in the terminal write command

$ sudo bash

and from this time all what you do in this terminal you do as root. There are the steps for installing the PHP development environment:

  1. Install Appache web server

    apt-get install apache2

  2. Install MySQL server

    apt-get install mysql-server

    The installation of MySQL server will ask for password for root user. It's not mandatory, but I recommend to enter a password.

  3. Install PHP 5

    apt-get install php5

  4. Install MySQL extension for PHP

    apt-get install php5-mysql

  5. Install xDebug extension for PHP - the extension for debugging.

    apt-get install php5-xdebug

  6. This all what you have to install. Now we will set up Apache and PHP.

  7. Setup the Apache web server to use users web sites

    After installing Apache the server should be running. If you click this link http://localhost/ the Firefox is opened and you should see the same content as is on the picture. 

    Localhost

    But when you try the url, which acces web sites in your home folder, it fails. Instead petr write your username:).


    To get it work you have to:
    • Enable userdir module in Apache web server

      a2enmod userdir

    • Create public_html folder in your homedir (do it uder your account, not as root)

      mkdir public_html

    • Restart Apache web server

      /etc/init.d/apache2 restart

      If you do it correctly after refreshing Firefox you should see empty content of the folder as on the picture.



  8. Enable remote debugging in xDebug

    In the folder public_html create index.php file with content:
    <?php
         phpinfo();
    ?>
    
    Refresh Firefox and you should see how the PHP runtime is setup. Search for the property xdebug.remote_enable property. By default this property is switched off as you can see on the picture.


    To enable this property you have to open file /etc/php5/conf.d/xdebug.ini and add line

    xdebug.remote_enable=on

    and restart the Apache web server

    /etc/init.d/apache2 restart

This is all. Now you are ready to start develop a PHP application. Next I will write how to instal JRE (Java Runtime Environment) or JDK (Java Development Kit) and NetBeans PHP. Also I will describe how to check, whether the debugging and MySQL database work well.

Tuesday Jun 17, 2008

How to set up NetBeans to treat files with an extension as PHP files II

Last week I described in the article How to set up NetBeans to treat files with an extension as PHP files, how to do it in the Early Access build and I mentioned that the NetBeans core team is working on simplifying the procedure. And now the feature is in the build.

If you download a continual or daily build, you can see the Open As ... action in the context menu of files that are not recognized by default. If you invoke it, then the Open As ... dialog opens and you can choose how the files with the same extension will be treated in NetBeans. If you choose mimetype text/x-php5, then files with the same extension will be opened in the PHP editor.

New way how tho treat files as a php files

And you can change it later in the Options dialog.

Options for customizing Open as


Wednesday Jun 11, 2008

How to set up NetBeans to treat files with an extension as PHP files

Sometimes people ask me for an advice, how to set up NetBeans to treat some file with certain extension as PHP file.  For example .phpt files are test files for testing PHP runtime, which contains PHP code and NetBeans Early Access treats these files only as a text files.

There are steps how to do it:

  • Invoke Options dialog (Tools -> Options).
  • In Options dialog press Advance Options button to display Advance Options dialog.
  • Browse  IDE Configuration -> System -> File Types.
  • Expand the File Types node and select PHP Files node.
  • In context menu select Open item, which opens the PHP MimeType resolver in editor.
    Advance Option dialog
  • Close the Advance Options Dialog.
  • Add the <ext> tag to the PHP File MimeType resolver. For the .phpt file is added <ext name="phpt"/> tag. The result file should contain:
  • <MIME-resolver>
        <file>
            <ext name="php"/>
            <ext name="php3"/>
            <ext name="php4"/>
            <ext name="php5"/>              
            <ext name="inc"/>
            <ext name="phpt"/>
            <resolver mime="text/x-php5"/>
        </file>
    </MIME-resolver>
  • Save the change
  • Restart the IDE

I know, this is not so simple as should be, but NetBeans core engineers are working on simplifying the UI. I hope it will be available in NetBeans 6.5 and the specification you can see here.

About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today