@@ -370,42 +370,51 @@ function bake($action, $content = '') {
370
370
/**
371
371
* Builds content from template and variables
372
372
*
373
- * @param string $template file to use
373
+ * @param string $action name to generate content to
374
374
* @param array $vars passed for use in templates
375
375
* @return string content from template
376
376
* @access public
377
377
*/
378
- function getContent ($ template = null , $ vars = null ) {
379
- if (!$ template ) {
380
- $ template = $ this ->template ;
381
- }
382
- $ action = $ template ;
383
-
384
- $ adminRoute = Configure::read ('Routing.admin ' );
385
- if (!empty ($ adminRoute ) && strpos ($ template , $ adminRoute ) !== false ) {
386
- $ template = str_replace ($ adminRoute . '_ ' , '' , $ template );
387
- }
388
- if (in_array ($ template , array ('add ' , 'edit ' ))) {
389
- $ action = $ template ;
390
- $ template = 'form ' ;
391
- } elseif (preg_match ('@(_add|_edit)$@ ' , $ template )) {
392
- $ action = $ template ;
393
- $ template = str_replace (array ('_add ' , '_edit ' ), '_form ' , $ template );
394
- }
378
+ function getContent ($ action , $ vars = null ) {
395
379
if (!$ vars ) {
396
380
$ vars = $ this ->__loadController ();
397
381
}
398
382
399
383
$ this ->Template ->set ('action ' , $ action );
400
384
$ this ->Template ->set ('plugin ' , $ this ->plugin );
401
385
$ this ->Template ->set ($ vars );
402
- $ output = $ this ->Template ->generate ('views ' , $ template );
386
+ $ output = $ this ->Template ->generate ('views ' , $ this -> getTemplate ( $ action ) );
403
387
404
388
if (!empty ($ output )) {
405
389
return $ output ;
406
390
}
407
391
return false ;
408
392
}
393
+
394
+ /**
395
+ * Gets the template name based on the action name
396
+ *
397
+ * @param string $action name
398
+ * @return string template name
399
+ * @access public
400
+ */
401
+ function getTemplate ($ action ) {
402
+ if (!empty ($ this ->template ) && $ action != $ this ->template ) {
403
+ return $ this ->template ;
404
+ }
405
+ $ template = $ action ;
406
+ $ adminRoute = Configure::read ('Routing.admin ' );
407
+ if (!empty ($ adminRoute ) && strpos ($ template , $ adminRoute ) !== false ) {
408
+ $ template = str_replace ($ adminRoute . '_ ' , '' , $ template );
409
+ }
410
+ if (in_array ($ template , array ('add ' , 'edit ' ))) {
411
+ $ template = 'form ' ;
412
+ } elseif (preg_match ('@(_add|_edit)$@ ' , $ template )) {
413
+ $ template = str_replace (array ('_add ' , '_edit ' ), '_form ' , $ template );
414
+ }
415
+ return $ template ;
416
+ }
417
+
409
418
410
419
/**
411
420
* Displays help contents
0 commit comments