junichi11 / cakephp-netbeans

CakePHP support in NetBeans
http://cakephp.org
71 stars 18 forks source link

NetBeans CakePHP Plugin

This plugin provides support for CakePHP.

since 2010/07/16

Environments

About CakePHP 3.x

CakePHP3 support is not provide in this plugin. Please use the following : cakephp3-netbeans

How to enable

CakePHP project is not recognized automatically from NetBeans 8.0. Please check project properties > Framework > CakePHP > enabled

What Works

[*1] right-click in project node > CakePHP > (Run Command | Clear Cache | Install Plugins)

Ignore tmp directory

app/tmp is ignored with default. If you would like to avoid this, please, uncheck ignore tmp directory option.

Existing Source

Your NetBeans Project needs to have the following trees.

CakePHP 1.3.x

myproject
├─nbproject
├─app
├─cake
├─plugins
├─vendors
├─...

CakePHP 2.x

myproject
├─nbproject
├─app
├─lib
│  └─Cake
├─plugins
├─vendors
├─...

NewProject (Ctrl + Shift + N) > PHP > PHP Application with Existing Source Please select your cakephp dir(e.g. /home/NetBeansProjects/myproject)

App Directory Path

You can set app directory path from source directory. Project properties > Framework > CakePHP > Custom directory path > app

Use multiple app directories

If you use multiple app directories:

// CakePHP 1
cakephp1.3
├─app
├─app2
├─app3
├─myapp
├─...
├─cake
├─plugins
├─vendors
├─...

// CakePHP 2
cakephp2.x
├─app
├─app2
├─app3
├─mycustom
├─...
├─lib
│  └─Cake
├─plugins
├─vendors
├─...

Use app directory as NetBeans project e.g. app1, app2, myapp, e.t.c.:

myproject(e.g. myapp)
├── nbproject
├── Config
├── Console
├── Controller
├── Lib
├── Locale
├── Model
├── Plugin
├── Test
├── Vendor
├── View
├── index.php
├── tmp
└── webroot
  1. Project properties > Framework > CakePHP
  2. app : "" (empty or ".")
  3. CakePHP Root : "../"

Please notice that Code Completion is not available. You have to add the cakephp core path to include path.

After settings, please close your project and reopen it.

.cake file support

.cake is configuration file for plugins of editors and IDEs. If your CakePHP project is not default directory structure, you should use it. e.g. In case of your app/Model directory name is app/MyModel, you have some Controller directories (Controller(default), SecondController, ThirdController), e.t.c. You can create it with Dotcake Plugin .

Supported category

If you want to use it, please set its path to Project properties > Framework > CakePHP > .cake

Clear Cache Action

Delete each files of app/tmp/cache/* directorys.

Install Plugins Action

Settings: Tool > Option > PHP > CakePHP

Note

Url is only zipball url.

Run Action: see [*1]

Plugin version numbers are not necessarily latest. Please try to check and edit them manually.

Create New CakePHP Project

You need to connect the network.

  1. File > New Project (Ctrl + Shift + N)
  2. PHP > PHP Application
  3. Set the project name
  4. Run Configuration
  5. PHP Framework > check CakePHP PHP Web Framework

Select Unzip or Unzip local file or Composer or git command. If you select Unzip, also select CakePHP version. If you want to unzip the local file, please set the option (Tools > Options > PHP > CakePHP > New Project > Local file path) If you want to create a database.php file, please, check the Create database.php.

Also set the following automatically.

create a database, you can immediately start development in a local environment.

Installing with composer

We can set default composer.json on Options panel. We can use --empty and app name settings when we create a project. --empty is used with bake project. If app name is empty, app directory is source directory, otherwise it is created under the source directory.

Code Completion

Support for core components and helpers (default). Also support for classes in $uses, $components, $helpers.(also contain the alias)

// e.g.
public $uses('Comment', 'Member', 'User');
// $this->Comm [Ctrl + Space] => $this->Comment [Ctrl + Space]

public $components('Search.Prg', 'Foo');
// $this->P [Ctrl + Space] => $this->Prg-> [Ctrl + Space] => display methods and fields

public $helpers('Session', 'Html' => array('className' => 'MyHtml'));
// $this->Html-> [Ctrl + Space] => display MyHtmlHelper class methods and fields

Image File Completion

$this->Html->image('[Ctrl + Space]');
// popup file and directory names in the webroot/img
$this->Html->image('subdir/[Ctrl + Space]');
// popup file and directory names in the webroot/img/subdir
// ...
$this->Html->image('/mydir/[Ctrl + Space]');
// if you want to use files or directories in the webroot directory,
// please, start with "/"

$this->Html->image('Debug[Ctrl + Space]');
$this->Html->image('DebugKit.[Ctrl + Space]');
// support for Plugin images (CakePHP 2.x)

If target file exists, image will be displayed on document window.

You can run code completion also css and script methods ($this->Html->css(), script()) like the same as image method.

$this->Html->css('[Ctrl + Space]');
// popup file and directory names in the webroot/css
$this->Html->script('subdir/[Ctrl + Space]');
// popup file and directory names in the webroot/js/subdir
$this->Html->css('/mydir/[Ctrl + Space]');
$this->Html->script('PluginName.[Ctrl + Space]');

Element File Completion

$this->element('[Ctrl + Space]');
// popup file names in the appdir/View/Elements/
$this->element('MyPlugin.[Ctrl + Space]');
// support for Plugin elements (CakePHP 2.x)

Fields Completion

This is available in the following fields. This can also complete the plugin name. Please run code completion again(i.e. [Ctrl + Space]) after "PluginName.".

// e.g.
public $components = array('[Ctrl + Space]');
public $components = array('DebugKit.[Ctrl + Space]');

Go To View Action

You can move from controller action to view file.

  1. Right-click at the controller action
  2. Navigate > Go to view

e.g.

class MainController extends AppController{
    // ... something
    public function index() {
        // Right-click or shortcut here
    }
}

If you use shortcut, register with Keymap.

When the view file doesn't exist, create the empty view file automatically if set as follows.

Check Auto create a view file when go to view action is run at Right-click on project node > property > Framework > CakePHP

If you use the theme, set $theme to controller field.

Code Templates

Available code templates : Tools > Options > Editor > Code Templates > HTML/PHP

e.g.

This feature is also available with code completion.

Go To Action Action

Similar to Go to view action.

  1. Right-click on the view file (in editor)
  2. Navigate > Go to action

Smart Go To [v0.9.0]

You can go to specific files relate to a current file. e.g. In case of current file is Controller, you can go to existing view, model, component, helper and test. go to navigations matrix

How To Run

There are three ways.

Shortcuts

Pattern : [Ctrl + Shift + G] [] (or [Ctrl + J] [])

Of course, if you don't like these shortcuts, you are able to change them in Options (KeyMap).

Settings

project properties > Frameworks > CakePHP Please uncheck the following if you would like to go to it soon (without popup) when candidate file is only one.

Note

Format+ Action (Format for CakePHP)

This action run the following.

  1. Reformat (format settings : Tool > Option > Editor > Format)
  2. Remove indents of Document Block
  3. Change line separator to LF(Unix)

Q. Why do you add this action?

A. I add in order to follow the CakePHP Coding Standars

Hyperlink for view element files (v0.6.9)

You can go to the element file from view file.

Search the following element file directories:

e.g.

$this->element('sample');

Hold down Ctrl key and click on 'sample'.

If there is sample.ctp in the above directories, open the sample.ctp. Otherwise do nothing.

Display and Change debug level (v0.6.10)

You can change debug level on popup list.

When you choose the CakePHP file node, you would find the cake icon and debug level number at the lower right of the window.

If you change debug level, click the icon. Then the popup is displayed. Please, select the debug level number.

Check Default Action (v0.6.15)

Check default asset names. (e.g. css/cake.generic.css, img/cake.icon.png, ...)

Check whether favicon.ico is changed.

PHPUnit Test settings (PHPUnit Test Init Action)

Support for only CakePHP2.x

Project-right-click > CakePHP > PHPUnit Test Init

Do settings for doing PHPUnit Test with NetBeans.

Create following files:

And set PHPUnit settings of Project properties:

If you run this action, you can test using fixture with NetBeans.

bootstrap and NetBeansSuite Sources

https://gist.github.com/2055307 (nojimage)

Code Generation

How To Run

Alt + Insert or Right-click on editor, select Insert Code.

Generate uses, helpers, components and actsAs fields

Dialog is displayed when you run Insert Code action. Please select what you want to use. And code like followings are inserted.

$helpers = array('Html', ..., 'PluignName.SomeHelper');
$componens = array('Session', ..., 'MyComponent');
$uses = array('Post');
$actsAs = array('Tree', ..., 'PluignName.SomeBehavior');

You have to add settings for each classes by yourself if you need it.

Generate validations

This provides support for only Core validations.(e.g. notEmpty, isUnique, e.t.c) At first, you have to write the following before you run this feature.

public $validate = array(
    'fieldName' => array(
        // please set caret to here
    ),
);

Please move caret to place which you want to insert, and run Insert Code action. Then, code like followings will be inserted:

// template
'validationName' => array(
    'rule' => 'validationName',
    'message' => 'validationNamemessage'
},
// template : has arguments(are not initialized)
'validationName' => array(
    'rule' => array('validationName', validationName_arg1, validationName_arg2),
    'message' => 'validationNamemessage'
},

Since message is focused, you can change it to your message. Please push Enter key after you change it. And you can move to next message. If you want to move to previous message, please push Shift + Tab.

Please see also https://github.com/junichi11/cakephp-netbeans/issues/12

Run Action Action

You can run the action for controller.

public function index() {
    // move the caret here
}

Note

Currently, this is available for the simple situation.

Please also see the following: https://github.com/junichi11/cakephp-netbeans/issues/16

CMS Support

baserCMS3

baserCMS is an open source CMS and powered by CakePHP Framework.

Features

References

How To Run

How To Develop

References

Trableshooting

Can't get CakePHP verison numbers in the New Project Wizard

Donation

License

Common Development and Distribution License (CDDL) v1.0 and GNU General Public License (GPL) v2