Adding enhancement idea from Ticket #2201.

Fixed the use of parseHtmlOptions which is deprecated.
Fixed an undefined index on check box when there is no model.

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4672 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-03-25 02:03:34 +00:00
parent 8fa50d9100
commit 3292a8efdb
2 changed files with 25 additions and 16 deletions

View file

@ -1036,16 +1036,22 @@ class Controller extends Object {
} elseif (is_string($scope)) { } elseif (is_string($scope)) {
$conditions = array($conditions, $scope); $conditions = array($conditions, $scope);
} }
$recursive = $object->recursive;
$count = $object->findCount($conditions, $recursive);
$pageCount = ceil($count / $limit);
if($page == 'last') {
$options['page'] = $page = $pageCount;
}
$results = $object->findAll($conditions, $fields, $order, $limit, $page, $recursive); $results = $object->findAll($conditions, $fields, $order, $limit, $page, $recursive);
$count = $object->findCount($conditions);
$paging = array( $paging = array(
'page' => $page, 'page' => $page,
'current' => count($results), 'current' => count($results),
'count' => $count, 'count' => $count,
'prevPage' => ($page > 1), 'prevPage' => ($page > 1),
'nextPage' => ($count > ($page * $limit)), 'nextPage' => ($count > ($page * $limit)),
'pageCount' => ceil($count / $limit), 'pageCount' => $pageCount,
'defaults' => am(array('limit' => 20, 'step' => 1), $defaults), 'defaults' => am(array('limit' => 20, 'step' => 1), $defaults),
'options' => $options 'options' => $options
); );

View file

@ -312,12 +312,12 @@ class HtmlHelper extends AppHelper {
} }
$url = $this->webroot((COMPRESS_CSS ? 'c' : '') . CSS_URL . $path . ".css"); $url = $this->webroot((COMPRESS_CSS ? 'c' : '') . CSS_URL . $path . ".css");
if ($rel == 'import') { if ($rel == 'import') {
$out = sprintf($this->tags['style'], $this->parseHtmlOptions($htmlAttributes, null, '', ' '), '@import url(' . $url . ');'); $out = sprintf($this->tags['style'], $this->_parseAttributes($htmlAttributes, null, '', ' '), '@import url(' . $url . ');');
} else { } else {
if ($rel == null) { if ($rel == null) {
$rel = 'stylesheet'; $rel = 'stylesheet';
} }
$out = sprintf($this->tags['css'], $rel, $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' ')); $out = sprintf($this->tags['css'], $rel, $url, $this->_parseAttributes($htmlAttributes, null, '', ' '));
} }
$out = $this->output($out); $out = $this->output($out);
@ -398,9 +398,12 @@ class HtmlHelper extends AppHelper {
} else { } else {
$model = $this->model(); $model = $this->model();
if (isset($htmlAttributes['value']) || (!class_exists($model) && !loadModel($model))) { if (isset($htmlAttributes['value']) || (!class_exists($model) && !loadModel($model))) {
$htmlAttributes['checked'] = ($htmlAttributes['value'] == $value) ? 'checked' : null; if(isset($htmlAttributes['value']) && $htmlAttributes['value'] == $value){
$htmlAttributes['checked'] = 'checked';
if ($htmlAttributes['value'] == '0') { } else {
$htmlAttributes['checked'] = null;
}
if (isset($htmlAttributes['value']) && $htmlAttributes['value'] == '0') {
$notCheckedValue = -1; $notCheckedValue = -1;
} }
} else { } else {
@ -467,7 +470,7 @@ class HtmlHelper extends AppHelper {
if (!isset($htmlAttributes['alt'])) { if (!isset($htmlAttributes['alt'])) {
$htmlAttributes['alt'] = ''; $htmlAttributes['alt'] = '';
} }
return $this->output(sprintf($this->tags['image'], $url, $this->parseHtmlOptions($htmlAttributes, null, '', ' '))); return $this->output(sprintf($this->tags['image'], $url, $this->_parseAttributes($htmlAttributes, null, '', ' ')));
} }
/** /**
* Creates a text input widget. * Creates a text input widget.
@ -507,7 +510,7 @@ class HtmlHelper extends AppHelper {
foreach($options as $optValue => $optTitle) { foreach($options as $optValue => $optTitle) {
$optionsHere = array('value' => $optValue); $optionsHere = array('value' => $optValue);
$optValue == $value ? $optionsHere['checked'] = 'checked' : null; $optValue == $value ? $optionsHere['checked'] = 'checked' : null;
$parsedOptions = $this->parseHtmlOptions(array_merge($htmlAttributes, $optionsHere), null, '', ' '); $parsedOptions = $this->_parseAttributes(array_merge($htmlAttributes, $optionsHere), null, '', ' ');
$individualTagName = $this->field() . "_{$optValue}"; $individualTagName = $this->field() . "_{$optValue}";
$out[] = sprintf($this->tags['radio'], $this->model(), $this->field(), $individualTagName, $parsedOptions, $optTitle); $out[] = sprintf($this->tags['radio'], $this->model(), $this->field(), $individualTagName, $parsedOptions, $optTitle);
} }
@ -526,9 +529,9 @@ class HtmlHelper extends AppHelper {
function tableHeaders($names, $trOptions = null, $thOptions = null) { function tableHeaders($names, $trOptions = null, $thOptions = null) {
$out = array(); $out = array();
foreach($names as $arg) { foreach($names as $arg) {
$out[] = sprintf($this->tags['tableheader'], $this->parseHtmlOptions($thOptions), $arg); $out[] = sprintf($this->tags['tableheader'], $this->_parseAttributes($thOptions), $arg);
} }
$data = sprintf($this->tags['tablerow'], $this->parseHtmlOptions($trOptions), join(' ', $out)); $data = sprintf($this->tags['tablerow'], $this->_parseAttributes($trOptions), join(' ', $out));
return $this->output($data); return $this->output($data);
} }
/** /**
@ -552,7 +555,7 @@ class HtmlHelper extends AppHelper {
foreach($line as $cell) { foreach($line as $cell) {
$cellsOut[] = sprintf($this->tags['tablecell'], null, $cell); $cellsOut[] = sprintf($this->tags['tablecell'], null, $cell);
} }
$options = $this->parseHtmlOptions($count % 2 ? $oddTrOptions : $evenTrOptions); $options = $this->_parseAttributes($count % 2 ? $oddTrOptions : $evenTrOptions);
$out[] = sprintf($this->tags['tablerow'], $options, join(' ', $cellsOut)); $out[] = sprintf($this->tags['tablerow'], $options, join(' ', $cellsOut));
} }
return $this->output(join("\n", $out)); return $this->output(join("\n", $out));
@ -635,7 +638,7 @@ class HtmlHelper extends AppHelper {
} else { } else {
$tag = 'block'; $tag = 'block';
} }
return $this->output(sprintf($this->tags[$tag], $this->parseHtmlOptions($attributes, null, ' ', ''), $text)); return $this->output(sprintf($this->tags[$tag], $this->_parseAttributes($attributes, null, ' ', ''), $text));
} }
/** /**
* Returns a formatted P tag. * Returns a formatted P tag.
@ -658,7 +661,7 @@ class HtmlHelper extends AppHelper {
} else { } else {
$tag = 'para'; $tag = 'para';
} }
return $this->output(sprintf($this->tags[$tag], $this->parseHtmlOptions($attributes, null, ' ', ''), $text)); return $this->output(sprintf($this->tags[$tag], $this->_parseAttributes($attributes, null, ' ', ''), $text));
} }
/**#@-*/ /**#@-*/
/************************************************************************* /*************************************************************************