NetBeans and CakePHP: The Code Completition

After the previous article regarding the power of NetBeans, today we will talk abit about integrating NetBeans with CakePHP.
Basically our problem with NetBeans occurs  when we want code competition in our controller but we have model-based methods and properties.  Also, if we want Cake’s functions and properties also then the same problem arrises.Lets image our [...]

After the previous article regarding the power of NetBeans, today we will talk abit about integrating NetBeans with CakePHP.

Basically our problem with NetBeans occurs  when we want code competition in our controller but we have model-based methods and properties.  Also, if we want Cake’s functions and properties also then the same problem arrises.Lets image our situation:

We have a model named Article.


We also have the controller for this model, named ArticlesController which we will use to find all articles in our database.

Article->find("all");
        $this->set("articles",$articles);
    }
}
?>

Normally in this case, when we are typing “$this->Article->” we want to have all the methods and properties of Article Model and parent AppModel but NetBeans is not showing us this.

The solution to this is actully easier then expected:

Just add before your class, in the documentation area of the file, the following code:

/**
* @property Article $Article
*/
Article->find("all");
        $this->set("articles",$articles);
    }
}
?>

We also have the controller for this model, named ArticlesController which we will use to find all articles in our database.

This can also be done to help you with belongsTo model propery. You can have an Article belong to a User and add the appropriate @property and then get the methods from the User model.

To get the methods and properties of Cake’s core, then just right-click on the project, go to PHP Include Path and add your cake-folder. Now you also should see all the build-in-functions and properties.

As you can see, its piece of cake!


  • Hazem
    A great article can be found here http://www.tiplite.com
  • Try also Codelobster PHP Edition with special PHPCake plug-in.
  • To use those do the following (i tested it on Netbeans 6.7 RC1)

    a)Make a folder named "code_completition"
    b)make a cc.php in that folder and write in it the following lines:

    exit();
    $ajax = new AjaxHelper();
    $form = new FormHelper();
    $html = new HtmlHelper();
    $javascript = new JavascriptHelper();
    $number = new NumberHelper();
    $session = new SessionHelper();
    $text = new TextHelper();
    $time = new TimeHelper();
    $pagination = new PaginationHelper();
    $rss = new RssHelper();
    $xml = new XmlHelper();
    ?>

    c) go to your project properties, PHP Include path and add your code_competition folder there
    d) add in your file the following line:

    For example, if you wish to use the Session Helper:

    /**
    * @property SessionHelper $Session
    */

    (on top of your file ,after the < ? php start tag)

    Hope it will work for you also.
  • gitto
    how can i get code completion for cakephp built in function.. For eg: $this->Session->setFlash('Invalid id for User');

    how can i use code completion in this??
blog comments powered by Disqus


Popular tags

Partner Blogs

Latest tweets


Get Adobe Flash playerPlugin by wpburn.com wordpress themes
Web Analytics