Archive for the ‘Zend’ Category
Checking all your checkboxes with jQuery
Ok I know this blog is geared towards ExtJS and I do expect you to lambast me for posting jQuery code snippets but, in my free time one lunch time I decided what it would be like to rewrite the ExtJS vertical checkbox examples I’ve been posting using jQuery.
Turns out, there’s not a great deal of difference in the length of the code, maybe the clarity and readability is slightly improved with jQuery, although looking at it there’s not a great deal in it. So for shits n giggles here’s my jQuery code:
<script type="text/javascript">
$(document).ready(function(){
$("#select_none").click(function(){
$(":checkbox").attr("checked", false);
$("#update_button").attr("disabled", true);
return false;
});
$("#select_all").click(function(){
$(":checkbox").attr("checked", true);
$("#update_button").attr("disabled", false);
return false;
});
// clear all checkboxes.
$("#select_none").click();
$(":checkbox").click(function(){
if($(this).attr("checked") == true)
{
if($("#update_button").attr("disabled")==true)
$("#update_button").attr("disabled", false);
}
else
{
if($(":checked").length == 0)
{
$("#update_button").attr("disabled", true);
}
}
})
});
FYI if you’re interested in checking out jQuery in more detail, have a look at the post over on Ajaxian filled with jQuery videos presented by John Resig himself.
Code Templates for increased productivity
Hi All,
I’ve a little off topic post for you today. I’ve had my head in a rather large amount of PHP recently and being the lazy developer I am, I was looking for ways to work smarter, and not harder. While using Zend Studio 5.5 (not the flashy Eclipse one, any one used that? What’s it like?) I added a few code templates to the preferences.
Benefits of code templates include:
- Less typing! yey!
- Standardised syntax and layout.
- No copy and paste errors! You know when you copy some code and forget a bit?
- and probably some more…
Here’s my code templates, you can add these by going to:
Tools > Preferences > Templates
Assign this to the keys access to produce an instance variable with get and set acessor methods.
private $_${VARIABLE} = null;
/**
* Acessor Get ${VARIABLE}
*/
public function get_${VARIABLE}()
{
return $this->_${VARIABLE};
}
/**
* Accessor Set ${VARIABLE}
*/
public function set_${VARIABLE}($value)
{
$this->_${VARIABLE} = $value;
}
My most used template is dbg I assign this to print the contents of an array or object:
echo "<pre>"; print_r(${VARIABLE}); echo "</pre>";
This one comes from Zend and is invoked by typing itar:
for (${INDEX} = 0; ${INDEX} < count(${ARRAY_NAME}); ${INDEX}++)
{
${END}
}
When I create a new PHP file, I like to type php and get the following (remember to set the context to HTML here!)
< ?php
/**
* Enter description here....
* @author ${USER}
* @date ${DATE} ${TIME}
*/
${END}
?>
Another Zend one, type fnc to get a function declaration
public function ${name}()
{
${END}
}
One for the thorough developer, I type test to get a PHPUnit test boiler plate (HTML Context again!):
< ?php
/**
* @author ${USER}
* @created_at ${DATE} ${TIME}
*
*/
require_once('PHPUnit/Framework.php');
// require_once('test_subject_file');
class ${VARIABLE}Test extends PHPUnit_Framework_TestCase
{
private $_instance = null;
public function setUp()
{
}
public function tearDown()
{
}
public function testMethod()
{
}
}
?>
If you already know these or use some of your own please do share them! If you’ve never used code templates before most editors support them and they’re really good for eliminating the mundane bits of coding!
Getting Started with Ext Js and the Zend Framework
Tutorial : Getting Started with Ext Js and the Zend Framework
Not read it yet, looks good though. Give it a scan…