Just remember that there is an inline comment before that line that
says "DO NOT EDIT BELOW THIS LINE". Probably not there arbitrarily,
so ignore at your own risk ;)
On May 20, 12:27 pm, RainChen <[EMAIL PROTECTED]> wrote:
> Some times I want to add some methods or common attributes to all
> Cake's objects. We know that most of the classes are extended from
> class Object. But there are not something like AppObject as a AppModel
> style API for us to extend objects. I dug deep into Cake's core
> source. Finally I found Cake left a trap for us to hack into Cake's
> core without hacking its source codes.
>
> There are 3 steps:
> 1. open app/webroot/index.php
> 2. locate the line:
> "if (!include(CORE_PATH . 'cake' . DS . 'bootstrap.php')) {"
> and add followed codes before that line:
>
> //hack by RainChen
> //@ Thu May 15 23:53:55 CST 2008
> //@ load extended class Object
> if ($bootstrap = true) {
> require CORE_PATH . 'cake' . DS . 'basics.php';
> $TIME_START = getMicrotime();
> require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
> if(file_exists(APP.'object.php'))
> {
> // auto update CakeObject class file
> if(!file_exists(APP.'cake_object.php') ||
> filemtime(CAKE_CORE_INCLUDE_PATH.DS.LIBS.'object.php') >
> filemtime(APP.'cake_object.php'))
> {
> file_put_contents(APP.'cake_object.php',
> str_replace('class Object
> {', 'class CakeObject {',
> file_get_contents(CAKE_CORE_INCLUDE_PATH.DS.LIBS.'object.php')));
> }
> require_once(APP.'cake_object.php');
> require_once(APP.'object.php');
> }
> else
> require LIBS . 'object.php';
> require LIBS . 'inflector.php';
> require LIBS . 'configure.php';
> }
> //hack end
>
> 3. save followed codes to app/object.php :
> <?php
> class Object extends CakeObject
> {
> // add or override anything you need}
>
> ?>
>
> That's it !
> It works even you update files in cake/*.
>
> Any ways, this is just for fun or special purpose.(require Cake
> version >= 1.2.0.6311 beta )
>
> I used this trick to log objects that Cake used per request.For
> example:
>
> Array
> (
> [1] => object
> [2] => configure
> [3] => cache
> [4] => fileengine
> [5] => file
> [6] => folder
> [7] => app
> [8] => folder
> [9] => folder
> [10] => folder
> [11] => folder
> [12] => folder
> [13] => folder
> [14] => folder
> [15] => folder
> [16] => folder
> [17] => dispatcher
> [18] => router
> [19] => inflector
> [20] => folder
> [21] => folder
> [22] => pagescontroller
> [23] => folder
> [24] => appcomponent
> [25] => security
> [26] => sessioncomponent
> [27] => requesthandlercomponent
> [28] => authextcomponent
> [29] => i18n
> [30] => l10n
> [31] => folder
> [32] => appview
> [33] => folder
> [34] => folder
> [35] => htmlhelper
> [36] => formhelper
> [37] => sessionhelper
> )
>
> PS: classes not extended from Object:
> ShellDispatcher,CakeLog,Sanitize,JsHelperObject,XmlManager,TestManager
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---