Zend DE Template: setter and getter for classes

Small, short code snippets that other people may find useful. Do you have a good regex that you would like to share? Share it! Even better, the code can be commented on, and improved.

Moderator: General Moderators

Post Reply
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Zend DE Template: setter and getter for classes

Post by jason »

For those of you with the new Zend DE 3.5, here are some templates I have put together for getters/setters in PHP. What other templates have you built?

Template: setter

Code: Select all

/**
* @desc Setter for ${name}
* @return void
* @param ${type} ${name}
*/
function set_${name} ( $${name} ) {
	$this->${name} = $${name};
}${END}

Template: getter

Code: Select all

/**
* @desc Getter for ${name}
* @return ${type}
*/
function get_${name} () { return $this->${name}; }${END}
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Oh, and for those of you who don't know, templates are really cool. For example, take the setter template above. In the normal editor, I would type the word 'setter' and then hit the enter key. It would automatically put the code in. Then, where you see ${name}, it would allow me to type a word in. For example, username. Everywhere you see ${name}, it would replace it with 'username'. After I typed username in, I would hit enter, and it would take me to the next token, ${type}, and I would do the same thing. Fill in the type (in this case, string), and then hit enter. Because everything is filled in, it takes me to wherever the ${END} tag is.

So by typing 'setter' + ENTER + 'username' + ENTER + 'string' + ENTER, I get the following.

Code: Select all

/**
* @desc Setter for username
* @return void
* @param string username
*/
function set_username ( $username ) {
	$this->username = $username;
}
Make's my life so much easier.
redmonkey
Forum Regular
Posts: 836
Joined: Thu Dec 18, 2003 3:58 pm

Post by redmonkey »

Must admit I haven't really played with it that much as of yet.

However, I did change the 'itar' template from....

Code: Select all

for ($&#123;INDEX&#125; = 0; $&#123;INDEX&#125; < count($&#123;ARRAY_NAME&#125;); $&#123;INDEX&#125;++) &#123;
	$&#123;END&#125;
&#125;
to....

Code: Select all

for ($&#123;INDEX&#125; = 0, $&#123;VARIABLE&#125; = count($&#123;ARRAY_NAME&#125;); $&#123;INDEX&#125; < $&#123;VARIABLE&#125;; $&#123;INDEX&#125;++)
&#123;
	$&#123;END&#125;
&#125;
I was somewhat surprised by the original template for 'itar'
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

Jason can you explain me better :cry: i'm afraid that i could not understood what are you talking about, but my six sense is telling me that i must know more about this
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Do you use Zend's IDE?
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

Nope i'm using a open source editor (SourceEdit).

Please do not tell me that this is available only from Zend enviroment. :(.
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

Doh i'v read it now the whole post please appologise i should notice that
"For those of you with the new Zend DE 3.5".
Post Reply