Monday, June 30, 2008

del.icio.us

My tagged pages in del.icio.us:
Suhas Dhoke

Interacting with your Views

Interacting with your views:

set($variable, $value);
string $variable;
mixed $value;

The principal use of this function is to extract data from a controller and transfer it to a view.
It can be used to transfer single values, whole arrays and so on etc. The moment you utilize set(), the variable can be accessed in your view: doing set(name, john) in your controller makes the variable name available in the view.

validateErrors() - displays the number of all the errors produced by an unsuccessful save.
validate() - this function is used to validate a model data respecting the rules of validation defined in to the model.

render($action, $layout, $file) - this function may not always be needed because render is called by default when every controller action ends, so the view specific to your action is rendered. On the other side, you can call this function to render the view anywhere in the controller code.

Sunday, June 29, 2008

Expand - Collapse

Thanks to Uncle Jim, who made this script. (Ref: http://jdstiles.com/java/expandcollapsesections.html)

This script shows an example to Expand and Collapse the block individually and also allow to show/hide all the blocks at a time.

<script type="text/javascript">
var collapseDivs, collapseLinks;

function createDocumentStructure (tagName) {
if (document.getElementsByTagName) {
var elements = document.getElementsByTagName(tagName);
collapseDivs = new Array(elements.length);
collapseLinks = new Array(elements.length);
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
var siblingContainer;
if (document.createElement &&
(siblingContainer = document.createElement('div')) &&
siblingContainer.style)
{
var nextSibling = element.nextSibling;
element.parentNode.insertBefore(siblingContainer, nextSibling);
var nextElement = elements[i + 1];
while (nextSibling != nextElement && nextSibling != null) {
var toMove = nextSibling;
nextSibling = nextSibling.nextSibling;
siblingContainer.appendChild(toMove);
}
siblingContainer.style.display = 'none';

collapseDivs[i] = siblingContainer;

createCollapseLink(element, siblingContainer, i);
}
else {
// no dynamic creation of elements possible
return;
}
}
createCollapseExpandAll(elements[0]);
}
}

function createCollapseLink (element, siblingContainer, index) {
var span;
if (document.createElement && (span = document.createElement('span'))) {
span.appendChild(document.createTextNode(String.fromCharCode(160)));
var link = document.createElement('a');
link.collapseDiv = siblingContainer;
link.href = '#';
link.appendChild(document.createTextNode('expand'));
link.onclick = collapseExpandLink;
collapseLinks[index] = link;
span.appendChild(link);
element.appendChild(span);
}
}

function collapseExpandLink (evt) {
if (this.collapseDiv.style.display == '') {
this.parentNode.parentNode.nextSibling.style.display = 'none';
this.firstChild.nodeValue = 'expand';
}
else {
this.parentNode.parentNode.nextSibling.style.display = '';
this.firstChild.nodeValue = 'collapse';
}

if (evt && evt.preventDefault) {
evt.preventDefault();
}
return false;
}

function createCollapseExpandAll (firstElement) {
var div;
if (document.createElement && (div = document.createElement('div'))) {
var link = document.createElement('a');
link.href = '#';
link.appendChild(document.createTextNode('expand all'));
link.onclick = expandAll;
div.appendChild(link);
div.appendChild(document.createTextNode(' '));
link = document.createElement('a');
link.href = '#';
link.appendChild(document.createTextNode('collapse all'));
link.onclick = collapseAll;
div.appendChild(link);
firstElement.parentNode.insertBefore(div, firstElement);
}
}

function expandAll (evt) {
for (var i = 0; i < collapseDivs.length; i++) {
collapseDivs[i].style.display = '';
collapseLinks[i].firstChild.nodeValue = 'collapse';
}

if (evt && evt.preventDefault) {
evt.preventDefault();
}
return false;
}

function collapseAll (evt) {
for (var i = 0; i < collapseDivs.length; i++) {
collapseDivs[i].style.display = 'none';
collapseLinks[i].firstChild.nodeValue = 'expand';
}

if (evt && evt.preventDefault) {
evt.preventDefault();
}
return false;
}
</script>
<script type="text/javascript">
window.onload = function (evt) {
createDocumentStructure('h1');
}
</script>

<center>
<h1>Chapter 1</h1>
<p>This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. This is chapter 1. </p>
<h1>Chapter 2</h1>
<p>This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. </p>
<p>This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. This is chapter 2. .</p>
<h1>Chapter 3</h1>
<p>This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. This is chapter 3. </p>
</center>

Demo Example

Wednesday, June 25, 2008

My First Post

Hello friends.

I've just created the blog and this is my first post.