Here is a good post that explains how to make several local variables available to the view at once.
Of course, you can always reference $this->data in the view…
Here is a good post that explains how to make several local variables available to the view at once.
Of course, you can always reference $this->data in the view…
You just need the bolded text…
<html>
<HEAD>
<script type=”text/javascript”>
function textCounter(textarea, counterID, maxLen) {
cnt = document.getElementById(counterID);
if (textarea.value.length > maxLen)
{
textarea.value = textarea.value.substring(0,maxLen);
}
cnt.innerHTML = maxLen – textarea.value.length;
}
</script>
</HEAD>
<body>
<center>
<form action=”whatever.php”>
<textarea name=”text_area” cols=”50″ rows=”5″ onKeyUp=”textCounter(this,’count_display’,3500);” >
onBlur=”textCounter(this,’count_display’,3500);” >
</textarea>
<br>
<span id=”count_display”>3500</SPAN> characters remaining
<input type=”submit” value=”Submit”>
</form>
</center>
</body>
</html>
There isn’t really a helper method to create a form in Cake 1.1.X; it is deprecated. To create a form the easiest way would be to write:
form action=”<?php echo $html->url(‘/’ . $this->controller->name . ‘/’ . $this->controller->action)?>” method=”post”>
To make life somewhat easier, database columns that will be rendered as checkboxes should be of type tinyint (or number) with values of zero and one (where 1 is checked).
The definition of the html->checkbox function is (note: title is not used):
checkbox($fieldName, $title = null, $htmlAttributes = array(), $return = false)
Whether or not the checkbox is checked is based on the htmlAttributes array. To illustrate what I mean, these $htmlAttribute arrays will result in a checked checkbox:
array('value'=>1)
array('value'=>0)
array('checked'=>1)
array('checked'=>0)
array('checked'=>'checked')
A bit of odd code does make the value of 0 (zero) also check the checkbox, so do not do this
echo $html->checkbox('Model/column', null, array('value'=>$ind));
and expect the checkbox to be unchecked if $ind is zero. It seems this would be the right thing to do to optimize your code, however, it does not work as expected.
So, to create a checkbox you’d write the easiest thing possible:
echo $html->checkbox('Model/column');
and CakePHP will make it checked for you (no extra code required).
If you do not have AUTO_OUTPUT set to TRUE in /cake/app/config/core.php then be sure to echo all HTML helper methods.
Example:
echo $html->input('Model/column', array('size'=>'1', 'maxlength'=>'1'));
This is also true when rendering elements (which is also done in the View):
echo $this->renderElement('menu');
The variable $title is reserved for the title of the page. Do not use it for anything else.
Example:
$this->set('title', 'Add a Post');
The find() function has the following parameters:
Returns the specified (or all if not specified) fields from the first record that matches $conditions or FALSE if no data is found. Recursive must be -1 to not return any associated data.
Example:
$one_row = $this->ModelName->find('id = ' . clean_id, null, null, -1);
Return example (i.e. value in $one_row):
Array
(
[ModelName] => Array
(
[id] => 1000
[name] => Ford
[status] => A
[created] => 2007-08-04 00:42:17
[modified] => 2007-08-04 00:42:17
)
)
So to get the value of name to your view you could write:
$this->set('name', $one_row['ModelName']['name']);