Changeset 366

Show
Ignore:
Timestamp:
09/19/07 05:04:28 (1 year ago)
Author:
bermiferrer
Message:

Fixing bug on automatic base URL computation. Formatting AkObserver? documentation.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/app/models/framework_setup.php

    r365 r366  
    723723            } 
    724724        } 
    725  
    726725    } 
    727726 
  • trunk/docs/tutorial.markdown

    r322 r366  
    258258    ./script/generate scaffold Author 
    259259 
    260 This will generate a bunch of files and folders with code that really works!. Don't trust me? Try it yourself. Point your browser to [http://localhost/booklink/author](http://localhost/booklink/author) and [http://localhost/booklink/books](http://localhost/booklink/books) to start adding authors and books. Create some records and come back for an explanation of what is going under the hood. 
     260This will generate a bunch of files and folders with code that really works!. Don't trust me? Try it yourself. Point your browser to [http://localhost/booklink/author](http://localhost/booklink/author) and [http://localhost/booklink/books](http://localhost/booklink/books) or to  [http://localhost/booklink/?ak=author](http://localhost/booklink/?ak=author) and [http://localhost/booklink/?ak=books](http://localhost/booklink/?ak=books) in case mod_rewrite is disabled to start adding authors and books. Create some records and come back for an explanation of what is going under the hood. 
    261261 
    262262 
  • trunk/lib/AkActiveRecord/AkObserver.php

    r285 r366  
    2222 
    2323/** 
    24 * Observer classes respond to lifecycle callbacks to implement trigger-like 
    25 * behavior outside the original class. This is a great way to reduce the 
    26 * clutter that normally comes when the model class is burdened with 
    27 * functionality that doesn't pertain to the core responsibility of the 
    28 * class. Example: 
     24* Observer classes respond to life-cycle callbacks to implement trigger-like  
     25* behavior outside the original class. This is a great way to reduce the clutter 
     26* that normally comes when the model class is burdened with functionality that 
     27* doesn't pertain to the core responsibility of the class.  
    2928*  
    30 *   class CommentObserver extends AkObserver 
    31 *   { 
    32 *       function afterSave($comment) 
    33 *       { 
    34 *           Ak::mail("admin@example.com", "New comment was posted", $comment->toString()); 
    35 *       } 
    36 *   } 
     29* Example: 
     30*  
     31*     class CommentObserver extends AkObserver 
     32*     { 
     33*         function afterSave($comment) 
     34*         { 
     35*             Ak::mail("admin@example.com", "New comment was posted", 
     36*                     $comment->toString()); 
     37*         } 
     38*     } 
    3739*  
    3840* This Observer sends an email when a Comment::save is finished. 
    3941*  
    40 * == Observing a class that can't be inferred 
     42* ## Observing a class that can't be inferred 
    4143*  
    42 * Observers will by default be mapped to the class with which they share a name. So CommentObserver will 
    43 * be tied to observing Comment, ProductManagerObserver to ProductManager, and so on. If you want to name your observer 
    44 * differently than the class you're interested in observing, you can use the AkActiveRecord->observe() class method: 
     44* Observers will by default be mapped to the class with which they share a name. 
     45* So CommentObserver will be tied to observing Comment, ProductManagerObserver 
     46* to ProductManager, and so on. If you want to name your observer differently 
     47* than the class you're interested in observing, you can use the 
     48* AkActiveRecord->observe() class method: 
    4549*  
    46 *   class AuditObserver extends AkObserver 
    47 *   { 
    48 *       function __construct() 
    49 *       { 
    50 *           $this->observe('Account'); 
    51 *       } 
     50*     function afterUpdate(&$account) 
     51*     { 
     52*         $AuditTrail =& new AuditTrail($account, "UPDATED"); 
     53*         $AuditTrail->save(); 
     54*     } 
    5255*  
    53 *       function afterUpdate(&$account) 
    54 *       { 
    55 *           $AuditTrail =& new AuditTrail($account, "UPDATED"); 
    56 *           $AuditTrail->save(); 
    57 *       } 
    58 *   } 
     56* If the audit observer needs to watch more than one kind of object, this can be 
     57* specified with multiple arguments: 
    5958*  
    60 * If the audit observer needs to watch more than one kind of object, this can be specified with multiple arguments: 
     59*     function afterUpdate(&$record) 
     60*     { 
     61*         $ObservedRecord =& new AuditTrail($record, "UPDATED"); 
     62*         $ObservedRecord->save(); 
     63*     } 
    6164*  
    62 *   class AuditObserver extends AkObserver 
    63 *   { 
    64 *       function __construct() 
    65 *       { 
    66 *           $this->observe('Account', 'Balance'); 
    67 *       } 
     65* The AuditObserver will now act on both updates to Account and Balance by 
     66* treating them both as records. 
    6867*  
    69 *       function afterUpdate(&$record) 
    70 *       { 
    71 *           $ObservedRecord =& new AuditTrail($record, "UPDATED"); 
    72 *           $ObservedRecord->save(); 
    73 *       } 
    74 *   } 
     68* ## Available callback methods 
    7569*  
    76 * The AuditObserver will now act on both updates to Account and Balance by treating them both as records. 
     70* The observer can implement callback methods for each of these methods: 
     71* beforeCreate, beforeValidation, beforeValidationOnCreate, beforeSave, 
     72* afterValidation, afterValidationOnCreate, afterCreate and afterSave 
    7773*  
    78 * == Available callback method
     74* ## Triggering Observer
    7975*  
    80 * The observer can implement callback methods for each of these methods: beforeCreate, beforeValidation, beforeValidationOnCreate, beforeSave, afterValidation, afterValidationOnCreate, afterCreate and afterSave 
     76* In order to activate an observer, you need to call create an Observer instance 
     77* and attach it to a model.  
    8178*  
    82 * == Triggering Observers 
     79* In the Akelos Framework, this can be done in controllers using the short-hand 
     80* of for example:  
    8381*  
    84 * In order to activate an observer, you need to call create an Observer instance and attach it to a model.  
    85 *   In the Akelos Framework, this can be done in controllers 
    86 *   using the short-hand of for example  
    87 *   $ComentObserverInstance =& new CommentObserver(); 
    88 *   $Model->addObserver(&$ComentObserverInstance); 
     82*     $ComentObserverInstance =& new CommentObserver(); 
     83*     $Model->addObserver(&$ComentObserverInstance); 
     84
    8985*/ 
    90  
    9186class AkObserver extends AkObject 
    9287{ 
  • trunk/lib/constants.php

    r365 r366  
    115115if(!AK_CLI && AK_WEB_REQUEST){ 
    116116 
    117     defined('AK_SITE_URL_SUFFIX') ? null : define('AK_SITE_URL_SUFFIX', str_replace(array(join(DS,array_diff((array)@explode(DS,AK_BASE_DIR), (array)@explode('/',AK_REQUEST_URI))), DS), array('','/'), AK_BASE_DIR)); 
     117    defined('AK_SITE_URL_SUFFIX') ? null : define('AK_SITE_URL_SUFFIX', str_replace(array(join(DS,array_diff((array)@explode(DS,AK_BASE_DIR), (array)@explode('/',AK_REQUEST_URI))), DS,'//'), array('','/','/'), AK_BASE_DIR)); 
    118118 
    119119    defined('AK_AUTOMATIC_SSL_DETECTION') ? null : define('AK_AUTOMATIC_SSL_DETECTION', 1);