1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: 25: 26:
27: App::import('Core', array('Component', 'View'));
28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39:
40: class Controller extends Object {
41: 42: 43: 44: 45: 46: 47:
48: var $name = null;
49: 50: 51: 52: 53: 54:
55: var $here = null;
56: 57: 58: 59: 60: 61:
62: var $webroot = null;
63: 64: 65: 66: 67: 68:
69: var $action = null;
70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81:
82: var $uses = false;
83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
93: var $helpers = array('Html', 'Form');
94: 95: 96: 97: 98: 99: 100: 101:
102: var $params = array();
103: 104: 105: 106: 107: 108: 109:
110: var $data = array();
111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
128: var $paginate = array('limit' => 20, 'page' => 1);
129: 130: 131: 132: 133: 134:
135: var $viewPath = null;
136: 137: 138: 139: 140: 141:
142: var $layoutPath = null;
143: 144: 145: 146: 147: 148:
149: var $viewVars = array();
150: 151: 152: 153: 154: 155: 156: 157:
158: var $pageTitle = false;
159: 160: 161: 162: 163: 164:
165: var $modelNames = array();
166: 167: 168: 169: 170: 171:
172: var $base = null;
173: 174: 175: 176: 177: 178: 179: 180: 181:
182: var $layout = 'default';
183: 184: 185: 186: 187: 188: 189:
190: var $autoRender = true;
191: 192: 193: 194: 195: 196:
197: var $autoLayout = true;
198: 199: 200: 201: 202: 203:
204: var $Component = null;
205: 206: 207: 208: 209: 210: 211: 212: 213: 214:
215: var $components = array();
216: 217: 218: 219: 220: 221:
222: var $view = 'View';
223: 224: 225: 226: 227: 228:
229: var $ext = '.ctp';
230: 231: 232: 233: 234: 235: 236: 237:
238: var $output = null;
239: 240: 241: 242: 243: 244:
245: var $plugin = null;
246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262:
263: var $cacheAction = false;
264: 265: 266: 267: 268: 269: 270: 271:
272: var $persistModel = false;
273: 274: 275: 276: 277: 278:
279: var $passedArgs = array();
280: 281: 282: 283: 284: 285: 286:
287: var $scaffold = false;
288: 289: 290: 291: 292: 293: 294:
295: var $methods = array();
296: 297: 298: 299: 300: 301: 302: 303: 304:
305: var $modelClass = null;
306: 307: 308: 309: 310: 311: 312: 313:
314: var $modelKey = null;
315: 316: 317: 318: 319: 320:
321: var $validationErrors = null;
322: 323: 324: 325:
326: function __construct() {
327: if ($this->name === null) {
328: $r = null;
329: if (!preg_match('/(.*)Controller/i', get_class($this), $r)) {
330: die (__("Controller::__construct() : Can not get or parse my own class name, exiting."));
331: }
332: $this->name = $r[1];
333: }
334:
335: if ($this->viewPath == null) {
336: $this->viewPath = Inflector::underscore($this->name);
337: }
338: $this->modelClass = Inflector::classify($this->name);
339: $this->modelKey = Inflector::underscore($this->modelClass);
340: $this->Component =& new Component();
341:
342: $childMethods = get_class_methods($this);
343: $parentMethods = get_class_methods('Controller');
344:
345: foreach ($childMethods as $key => $value) {
346: $childMethods[$key] = strtolower($value);
347: }
348:
349: foreach ($parentMethods as $key => $value) {
350: $parentMethods[$key] = strtolower($value);
351: }
352: $this->methods = array_diff($childMethods, $parentMethods);
353: parent::__construct();
354: }
355: 356: 357: 358: 359: 360:
361: function __mergeVars() {
362: $pluginName = Inflector::camelize($this->plugin);
363: $pluginController = $pluginName . 'AppController';
364:
365: if (is_subclass_of($this, 'AppController') || is_subclass_of($this, $pluginController)) {
366: $appVars = get_class_vars('AppController');
367: $uses = $appVars['uses'];
368: $merge = array('components', 'helpers');
369: $plugin = null;
370:
371: if (!empty($this->plugin)) {
372: $plugin = $pluginName . '.';
373: if (!is_subclass_of($this, $pluginController)) {
374: $pluginController = null;
375: }
376: } else {
377: $pluginController = null;
378: }
379:
380: if ($uses == $this->uses && !empty($this->uses)) {
381: if (!in_array($plugin . $this->modelClass, $this->uses)) {
382: array_unshift($this->uses, $plugin . $this->modelClass);
383: } elseif ($this->uses[0] !== $plugin . $this->modelClass) {
384: $this->uses = array_flip($this->uses);
385: unset($this->uses[$plugin . $this->modelClass]);
386: $this->uses = array_flip($this->uses);
387: array_unshift($this->uses, $plugin . $this->modelClass);
388: }
389: } elseif ($this->uses !== null || $this->uses !== false) {
390: $merge[] = 'uses';
391: }
392:
393: foreach ($merge as $var) {
394: if (!empty($appVars[$var]) && is_array($this->{$var})) {
395: if ($var === 'components') {
396: $normal = Set::normalize($this->{$var});
397: $app = Set::normalize($appVars[$var]);
398: if ($app !== $normal) {
399: $this->{$var} = Set::merge($app, $normal);
400: }
401: } else {
402: $this->{$var} = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
403: }
404: }
405: }
406: }
407:
408: if ($pluginController && $pluginName != null) {
409: $appVars = get_class_vars($pluginController);
410: $uses = $appVars['uses'];
411: $merge = array('components', 'helpers');
412:
413: if ($this->uses !== null || $this->uses !== false) {
414: $merge[] = 'uses';
415: }
416:
417: foreach ($merge as $var) {
418: if (isset($appVars[$var]) && !empty($appVars[$var]) && is_array($this->{$var})) {
419: if ($var === 'components') {
420: $normal = Set::normalize($this->{$var});
421: $app = Set::normalize($appVars[$var]);
422: if ($app !== $normal) {
423: $this->{$var} = Set::merge($app, $normal);
424: }
425: } else {
426: $this->{$var} = array_merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
427: }
428: }
429: }
430: }
431: }
432: 433: 434: 435: 436: 437: 438: 439: 440: 441:
442: function constructClasses() {
443: $this->__mergeVars();
444: $this->Component->init($this);
445:
446: if ($this->uses !== null || ($this->uses !== array())) {
447: if (empty($this->passedArgs) || !isset($this->passedArgs['0'])) {
448: $id = false;
449: } else {
450: $id = $this->passedArgs['0'];
451: }
452:
453: if ($this->uses === false) {
454: $this->loadModel($this->modelClass, $id);
455: } elseif ($this->uses) {
456: $uses = is_array($this->uses) ? $this->uses : array($this->uses);
457: $modelClassName = $uses[0];
458: if (strpos($uses[0], '.') !== false) {
459: list($plugin, $modelClassName) = explode('.', $uses[0]);
460: }
461: $this->modelClass = $modelClassName;
462: foreach ($uses as $modelClass) {
463: $this->loadModel($modelClass);
464: }
465: }
466: }
467: return true;
468: }
469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480:
481: function loadModel($modelClass = null, $id = null) {
482: if ($modelClass === null) {
483: $modelClass = $this->modelClass;
484: }
485: $cached = false;
486: $object = null;
487: $plugin = null;
488: if ($this->uses === false) {
489: if ($this->plugin) {
490: $plugin = $this->plugin . '.';
491: }
492: }
493:
494: if (strpos($modelClass, '.') !== false) {
495: list($plugin, $modelClass) = explode('.', $modelClass);
496: $plugin = $plugin . '.';
497: }
498:
499: if ($this->persistModel === true) {
500: $cached = $this->_persist($modelClass, null, $object);
501: }
502:
503: if (($cached === false)) {
504: $this->modelNames[] = $modelClass;
505:
506: if (!PHP5) {
507: $this->{$modelClass} =& ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id));
508: } else {
509: $this->{$modelClass} = ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id));
510: }
511:
512: if (!$this->{$modelClass}) {
513: return $this->cakeError('missingModel', array(array('className' => $modelClass, 'webroot' => '', 'base' => $this->base)));
514: }
515:
516: if ($this->persistModel === true) {
517: $this->_persist($modelClass, true, $this->{$modelClass});
518: $registry = ClassRegistry::getInstance();
519: $this->_persist($modelClass . 'registry', true, $registry->__objects, 'registry');
520: }
521: } else {
522: $this->_persist($modelClass . 'registry', true, $object, 'registry');
523: $this->_persist($modelClass, true, $object);
524: $this->modelNames[] = $modelClass;
525: }
526: }
527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537:
538: function redirect($url, $status = null, $exit = true) {
539: $this->autoRender = false;
540:
541: if (is_array($status)) {
542: extract($status, EXTR_OVERWRITE);
543: }
544: $response = $this->Component->beforeRedirect($this, $url, $status, $exit);
545:
546: if ($response === false) {
547: return;
548: }
549: if (is_array($response)) {
550: foreach ($response as $resp) {
551: if (is_array($resp) && isset($resp['url'])) {
552: extract($resp, EXTR_OVERWRITE);
553: } elseif ($resp !== null) {
554: $url = $resp;
555: }
556: }
557: }
558:
559: if (function_exists('session_write_close')) {
560: session_write_close();
561: }
562:
563: if (!empty($status)) {
564: $codes = array(
565: 100 => 'Continue',
566: 101 => 'Switching Protocols',
567: 200 => 'OK',
568: 201 => 'Created',
569: 202 => 'Accepted',
570: 203 => 'Non-Authoritative Information',
571: 204 => 'No Content',
572: 205 => 'Reset Content',
573: 206 => 'Partial Content',
574: 300 => 'Multiple Choices',
575: 301 => 'Moved Permanently',
576: 302 => 'Found',
577: 303 => 'See Other',
578: 304 => 'Not Modified',
579: 305 => 'Use Proxy',
580: 307 => 'Temporary Redirect',
581: 400 => 'Bad Request',
582: 401 => 'Unauthorized',
583: 402 => 'Payment Required',
584: 403 => 'Forbidden',
585: 404 => 'Not Found',
586: 405 => 'Method Not Allowed',
587: 406 => 'Not Acceptable',
588: 407 => 'Proxy Authentication Required',
589: 408 => 'Request Time-out',
590: 409 => 'Conflict',
591: 410 => 'Gone',
592: 411 => 'Length Required',
593: 412 => 'Precondition Failed',
594: 413 => 'Request Entity Too Large',
595: 414 => 'Request-URI Too Large',
596: 415 => 'Unsupported Media Type',
597: 416 => 'Requested range not satisfiable',
598: 417 => 'Expectation Failed',
599: 500 => 'Internal Server Error',
600: 501 => 'Not Implemented',
601: 502 => 'Bad Gateway',
602: 503 => 'Service Unavailable',
603: 504 => 'Gateway Time-out'
604: );
605: if (is_string($status)) {
606: $codes = array_flip($codes);
607: }
608:
609: if (isset($codes[$status])) {
610: $code = $msg = $codes[$status];
611: if (is_numeric($status)) {
612: $code = $status;
613: }
614: if (is_string($status)) {
615: $msg = $status;
616: }
617: $status = "HTTP/1.1 {$code} {$msg}";
618: } else {
619: $status = null;
620: }
621: }
622:
623: if (!empty($status)) {
624: $this->header($status);
625: }
626: if ($url !== null) {
627: $this->header('Location: ' . Router::url($url, true));
628: }
629:
630: if (!empty($status) && ($status >= 300 && $status < 400)) {
631: $this->header($status);
632: }
633:
634: if ($exit) {
635: $this->_stop();
636: }
637: }
638: 639: 640: 641: 642: 643: 644:
645: function header($status) {
646: header($status);
647: }
648: 649: 650: 651: 652: 653: 654: 655: 656: 657:
658: function set($one, $two = null) {
659: $data = array();
660:
661: if (is_array($one)) {
662: if (is_array($two)) {
663: $data = array_combine($one, $two);
664: } else {
665: $data = $one;
666: }
667: } else {
668: $data = array($one => $two);
669: }
670:
671: foreach ($data as $name => $value) {
672: if ($name === 'title') {
673: $this->pageTitle = $value;
674: } else {
675: if ($two === null && is_array($one)) {
676: $this->viewVars[Inflector::variable($name)] = $value;
677: } else {
678: $this->viewVars[$name] = $value;
679: }
680: }
681: }
682: }
683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694:
695: function setAction($action) {
696: $this->action = $action;
697: $args = func_get_args();
698: unset($args[0]);
699: return call_user_func_array(array(&$this, $action), $args);
700: }
701: 702: 703: 704: 705: 706: 707:
708: function isAuthorized() {
709: trigger_error(sprintf(__('%s::isAuthorized() is not defined.', true), $this->name), E_USER_WARNING);
710: return false;
711: }
712: 713: 714: 715: 716: 717:
718: function validate() {
719: $args = func_get_args();
720: $errors = call_user_func_array(array(&$this, 'validateErrors'), $args);
721:
722: if ($errors === false) {
723: return 0;
724: }
725: return count($errors);
726: }
727: 728: 729: 730: 731: 732: 733: 734: 735:
736: function validateErrors() {
737: $objects = func_get_args();
738:
739: if (empty($objects)) {
740: return false;
741: }
742:
743: $errors = array();
744: foreach ($objects as $object) {
745: if (isset($this->{$object->alias})) {
746: $object =& $this->{$object->alias};
747: }
748: $object->set($object->data);
749: $errors = array_merge($errors, $object->invalidFields());
750: }
751:
752: return $this->validationErrors = (!empty($errors) ? $errors : false);
753: }
754: 755: 756: 757: 758: 759: 760: 761: 762: 763:
764: function render($action = null, $layout = null, $file = null) {
765: $this->beforeRender();
766:
767: $viewClass = $this->view;
768: if ($this->view != 'View') {
769: if (strpos($viewClass, '.') !== false) {
770: list($plugin, $viewClass) = explode('.', $viewClass);
771: }
772: $viewClass = $viewClass . 'View';
773: App::import('View', $this->view);
774: }
775:
776: $this->Component->beforeRender($this);
777:
778: $this->params['models'] = $this->modelNames;
779:
780: if (Configure::read() > 2) {
781: $this->set('cakeDebug', $this);
782: }
783:
784: $View =& new $viewClass($this);
785:
786: if (!empty($this->modelNames)) {
787: $models = array();
788: foreach ($this->modelNames as $currentModel) {
789: if (isset($this->$currentModel) && is_a($this->$currentModel, 'Model')) {
790: $models[] = Inflector::underscore($currentModel);
791: }
792: if (isset($this->$currentModel) && is_a($this->$currentModel, 'Model') && !empty($this->$currentModel->validationErrors)) {
793: $View->validationErrors[Inflector::camelize($currentModel)] =& $this->$currentModel->validationErrors;
794: }
795: }
796: $models = array_diff(ClassRegistry::keys(), $models);
797: foreach ($models as $currentModel) {
798: if (ClassRegistry::isKeySet($currentModel)) {
799: $currentObject =& ClassRegistry::getObject($currentModel);
800: if (is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) {
801: $View->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors;
802: }
803: }
804: }
805: }
806:
807: $this->autoRender = false;
808: $this->output .= $View->render($action, $layout, $file);
809:
810: return $this->output;
811: }
812: 813: 814: 815: 816: 817: 818: 819: 820:
821: function referer($default = null, $local = false) {
822: $ref = env('HTTP_REFERER');
823: if (!empty($ref) && defined('FULL_BASE_URL')) {
824: $base = FULL_BASE_URL . $this->webroot;
825: if (strpos($ref, $base) === 0) {
826: $return = substr($ref, strlen($base));
827: if ($return[0] != '/') {
828: $return = '/'.$return;
829: }
830: return $return;
831: } elseif (!$local) {
832: return $ref;
833: }
834: }
835:
836: if ($default != null) {
837: return $default;
838: }
839: return '/';
840: }
841: 842: 843: 844: 845: 846: 847:
848: function disableCache() {
849: header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
850: header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
851: header("Cache-Control: no-store, no-cache, must-revalidate");
852: header("Cache-Control: post-check=0, pre-check=0", false);
853: header("Pragma: no-cache");
854: }
855: 856: 857: 858: 859: 860: 861: 862: 863: 864: 865: 866:
867: function flash($message, $url, $pause = 1) {
868: $this->autoRender = false;
869: $this->set('url', Router::url($url));
870: $this->set('message', $message);
871: $this->set('pause', $pause);
872: $this->set('page_title', $message);
873: $this->render(false, 'flash');
874: }
875: 876: 877: 878: 879: 880: 881: 882: 883: 884: 885:
886: function postConditions($data = array(), $op = null, $bool = 'AND', $exclusive = false) {
887: if (!is_array($data) || empty($data)) {
888: if (!empty($this->data)) {
889: $data = $this->data;
890: } else {
891: return null;
892: }
893: }
894: $cond = array();
895:
896: if ($op === null) {
897: $op = '';
898: }
899:
900: $arrayOp = is_array($op);
901: foreach ($data as $model => $fields) {
902: foreach ($fields as $field => $value) {
903: $key = $model.'.'.$field;
904: $fieldOp = $op;
905: if ($arrayOp) {
906: if (array_key_exists($key, $op)) {
907: $fieldOp = $op[$key];
908: } elseif (array_key_exists($field, $op)) {
909: $fieldOp = $op[$field];
910: } else {
911: $fieldOp = false;
912: }
913: }
914: if ($exclusive && $fieldOp === false) {
915: continue;
916: }
917: $fieldOp = strtoupper(trim($fieldOp));
918: if ($fieldOp === 'LIKE') {
919: $key = $key.' LIKE';
920: $value = '%'.$value.'%';
921: } elseif ($fieldOp && $fieldOp != '=') {
922: $key = $key.' '.$fieldOp;
923: }
924: $cond[$key] = $value;
925: }
926: }
927: if ($bool != null && strtoupper($bool) != 'AND') {
928: $cond = array($bool => $cond);
929: }
930: return $cond;
931: }
932: 933: 934: 935: 936: 937: 938: 939: 940: 941:
942: function paginate($object = null, $scope = array(), $whitelist = array()) {
943: if (is_array($object)) {
944: $whitelist = $scope;
945: $scope = $object;
946: $object = null;
947: }
948: $assoc = null;
949:
950: if (is_string($object)) {
951: $assoc = null;
952:
953: if (strpos($object, '.') !== false) {
954: list($object, $assoc) = explode('.', $object);
955: }
956:
957: if ($assoc && isset($this->{$object}->{$assoc})) {
958: $object =& $this->{$object}->{$assoc};
959: } elseif ($assoc && isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$assoc})) {
960: $object =& $this->{$this->modelClass}->{$assoc};
961: } elseif (isset($this->{$object})) {
962: $object =& $this->{$object};
963: } elseif (isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$object})) {
964: $object =& $this->{$this->modelClass}->{$object};
965: }
966: } elseif (empty($object) || $object === null) {
967: if (isset($this->{$this->modelClass})) {
968: $object =& $this->{$this->modelClass};
969: } else {
970: $className = null;
971: $name = $this->uses[0];
972: if (strpos($this->uses[0], '.') !== false) {
973: list($name, $className) = explode('.', $this->uses[0]);
974: }
975: if ($className) {
976: $object =& $this->{$className};
977: } else {
978: $object =& $this->{$name};
979: }
980: }
981: }
982:
983: if (!is_object($object)) {
984: trigger_error(sprintf(__('Controller::paginate() - can\'t find model %1$s in controller %2$sController', true), $object, $this->name), E_USER_WARNING);
985: return array();
986: }
987: $options = array_merge($this->params, $this->params['url'], $this->passedArgs);
988:
989: if (isset($this->paginate[$object->alias])) {
990: $defaults = $this->paginate[$object->alias];
991: } else {
992: $defaults = $this->paginate;
993: }
994:
995: if (isset($options['show'])) {
996: $options['limit'] = $options['show'];
997: }
998:
999: if (isset($options['sort'])) {
1000: $direction = null;
1001: if (isset($options['direction'])) {
1002: $direction = strtolower($options['direction']);
1003: }
1004: if ($direction != 'asc' && $direction != 'desc') {
1005: $direction = 'asc';
1006: }
1007: $options['order'] = array($options['sort'] => $direction);
1008: }
1009:
1010: if (!empty($options['order']) && is_array($options['order'])) {
1011: $alias = $object->alias ;
1012: $key = $field = key($options['order']);
1013:
1014: if (strpos($key, '.') !== false) {
1015: list($alias, $field) = explode('.', $key);
1016: }
1017: $value = $options['order'][$key];
1018: unset($options['order'][$key]);
1019:
1020: if (isset($object->{$alias}) && $object->{$alias}->hasField($field)) {
1021: $options['order'][$alias . '.' . $field] = $value;
1022: } elseif ($object->hasField($field)) {
1023: $options['order'][$object->alias . '.' . $field] = $value;
1024: }
1025: }
1026: $vars = array('fields', 'order', 'limit', 'page', 'recursive');
1027: $keys = array_keys($options);
1028: $count = count($keys);
1029:
1030: for ($i = 0; $i < $count; $i++) {
1031: if (!in_array($keys[$i], $vars, true)) {
1032: unset($options[$keys[$i]]);
1033: }
1034: if (empty($whitelist) && ($keys[$i] === 'fields' || $keys[$i] === 'recursive')) {
1035: unset($options[$keys[$i]]);
1036: } elseif (!empty($whitelist) && !in_array($keys[$i], $whitelist)) {
1037: unset($options[$keys[$i]]);
1038: }
1039: }
1040: $conditions = $fields = $order = $limit = $page = $recursive = null;
1041:
1042: if (!isset($defaults['conditions'])) {
1043: $defaults['conditions'] = array();
1044: }
1045:
1046: $type = 'all';
1047:
1048: if (isset($defaults[0])) {
1049: $type = $defaults[0];
1050: unset($defaults[0]);
1051: }
1052:
1053: $options = array_merge(array('page' => 1, 'limit' => 20), $defaults, $options);
1054: $options['limit'] = (int) $options['limit'];
1055: if (empty($options['limit']) || $options['limit'] < 1) {
1056: $options['limit'] = 1;
1057: }
1058:
1059: extract($options);
1060:
1061: if (is_array($scope) && !empty($scope)) {
1062: $conditions = array_merge($conditions, $scope);
1063: } elseif (is_string($scope)) {
1064: $conditions = array($conditions, $scope);
1065: }
1066: if ($recursive === null) {
1067: $recursive = $object->recursive;
1068: }
1069:
1070: $extra = array_diff_key($defaults, compact(
1071: 'conditions', 'fields', 'order', 'limit', 'page', 'recursive'
1072: ));
1073: if ($type !== 'all') {
1074: $extra['type'] = $type;
1075: }
1076:
1077: if (method_exists($object, 'paginateCount')) {
1078: $count = $object->paginateCount($conditions, $recursive, $extra);
1079: } else {
1080: $parameters = compact('conditions');
1081: if ($recursive != $object->recursive) {
1082: $parameters['recursive'] = $recursive;
1083: }
1084: $count = $object->find('count', array_merge($parameters, $extra));
1085: }
1086: $pageCount = intval(ceil($count / $limit));
1087:
1088: if ($page === 'last' || $page >= $pageCount) {
1089: $options['page'] = $page = $pageCount;
1090: } elseif (intval($page) < 1) {
1091: $options['page'] = $page = 1;
1092: }
1093: $page = $options['page'] = (integer)$page;
1094:
1095: if (method_exists($object, 'paginate')) {
1096: $results = $object->paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra);
1097: } else {
1098: $parameters = compact('conditions', 'fields', 'order', 'limit', 'page');
1099: if ($recursive != $object->recursive) {
1100: $parameters['recursive'] = $recursive;
1101: }
1102: $results = $object->find($type, array_merge($parameters, $extra));
1103: }
1104: $paging = array(
1105: 'page' => $page,
1106: 'current' => count($results),
1107: 'count' => $count,
1108: 'prevPage' => ($page > 1),
1109: 'nextPage' => ($count > ($page * $limit)),
1110: 'pageCount' => $pageCount,
1111: 'defaults' => array_merge(array('limit' => 20, 'step' => 1), $defaults),
1112: 'options' => $options
1113: );
1114: $this->params['paging'][$object->alias] = $paging;
1115:
1116: if (!in_array('Paginator', $this->helpers) && !array_key_exists('Paginator', $this->helpers)) {
1117: $this->helpers[] = 'Paginator';
1118: }
1119: return $results;
1120: }
1121: 1122: 1123: 1124: 1125: 1126:
1127: function beforeFilter() {
1128: }
1129: 1130: 1131: 1132: 1133: 1134:
1135: function beforeRender() {
1136: }
1137: 1138: 1139: 1140: 1141: 1142:
1143: function afterFilter() {
1144: }
1145: 1146: 1147: 1148: 1149: 1150: 1151: 1152:
1153: function _beforeScaffold($method) {
1154: return true;
1155: }
1156: 1157: 1158: 1159: 1160: 1161: 1162: 1163:
1164: function _afterScaffoldSave($method) {
1165: return true;
1166: }
1167: 1168: 1169: 1170: 1171: 1172: 1173: 1174:
1175: function _afterScaffoldSaveError($method) {
1176: return true;
1177: }
1178: 1179: 1180: 1181: 1182: 1183: 1184: 1185: 1186: 1187:
1188: function _scaffoldError($method) {
1189: return false;
1190: }
1191: }
1192: ?>
1193: