I am tired of creating a new Model or Controller file by typing long
long codes as following to fit CakePHP convention:

 var $name = xxx;
 var $belongsTo = array(blah blah blah);
 var $hasMany = array(blah blah blah);

 var $use = ...
 var $scaffold.......

So, I define a Model templates in Eclipse to save some my time. I just
need:

1) Eclipse 3.2.1
2) PDT, PHP Development Tool (http://www.eclipse.org/php/)

I will use Model template as example, you can do same thing for
Controller template.

==Step 1: To Create a PHP template==
Click Eclipse Menu: Window -> Preferences -> PHP -> Templates. You can
see a list of php code templates. Click "New..." button, do following
in the new window:

Name: input "CakePHP New Model";
Context: pick "New PHP", neither "PHP" nor "PHPDoc".
Description: "Create a new CakePHP Model definition file"
Pattern: Copy following boring codes you hate to type by yourself into
"Pattern":

/*--------------------start sample codes----------------*/
<?php
/**
 * Rename this file as /app/models/xxxxxxxx.php
 * @author: ${user}
 * @created: ${date} ${time}
 */
class Xxxxxxxx extends AppModel
{
    var $$name = "Xxxxxxxx";
    var $$recursive = 1;//define how deep to dig the model

    /*
     * Uncomment following to define your own relations
    var $$belongsTo = array('Aaa' => array('className'     => 'Aaa',
                                          'conditions'    => '',
                                          'order'         => '',
                                          'foreignKey'    => 'aaa_id',
                                         ),
                                                   'Bbb' => array('className'   
  => 'Bbb',
                                          'conditions'    => '',
                                          'order'         => '',
                                          'foreignKey'    => 'bbb_id',
                                         ),
                          );


    var $$hasMany = array('Ccc' => array('className'     => 'Ccc',
                                        'conditions'    => '1',
                                        'order'         =>
'Ccc.modified DESC',
                                        'limit'         => '100',
                                        'foreignKey'    => '',
                                        'dependent'     => true,
                                        'exclusive'     => false,
                                        'finderQuery'   => '',
                                       ),
                        );

        function MyOwnFunction()
        {

        }
        */
}

?>
/*--------------------endsample codes----------------*/


Notice you can insert some variable. Also notice that double-dollar "$
$" means the character single-dollar "$".  Click "OK" to save this PHP
file template.


==Step 2: To Create a blank model file using PHP template==
In your PHP Navigator (which shows your project folders and files),
choose "/app/models/" mouse right-click to choose "New" -> "PHP File",
after inputting file name, the next window asks you to "Select PHP
Template", choose "CakePHP New Model" which is defined by you in Step
1. You can see "preview" beneath. Click "finish", you can get a new
model file with those long long codes prepared for you to edit. (For
example, you should rename the model name from "Xxxxx", uncomment and
edit $belongsTo or $hasMany to use them.

It cost me 5 minute to define this PHP template, save me half minute
for each model. Eventually I am better off.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to