Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /*
- * The idea is to have a full set of functionality, that I could use within all my projects for free
- * and transparently. Per project rewrites done only for the parts that has to be changed.
- * Otherwise use the defaults
- *
- * Make sure "Shared" parts are loaded I add this:
- */
- <?
- #app/webroot/index.php
- App::uses('Dispatcher', 'Routing');
- App::build(array(
- 'Controller' => array(ROOT . DS . 'cake/Share/Controller/'),
- 'Model' => array(ROOT . DS . 'cake/Share/Model/'),
- 'Plugin' => array(ROOT . DS . 'cake/',ROOT . DS . 'cake/Share/'),
- 'View' => array(ROOT . DS . 'cake/Share/View/')
- ),APP::APPEND);
- CakePlugin::load('Share', array('path' => ROOT . DS . 'cake/Share/'));
- ?>
- // To have e.g. shared Users Controller:
- #path/Share/Controller/UsersController.php
- <?php
- # To prevent collisions prefix the controller
- class SharedUsersController extends AppController {
- function login() {
- if (isset($this->data['User'])) {
- if ($this->Auth->login())
- $this->redirect($this->Auth->redirect());
- else
- $this->Session->setFlash(__('You failed'));
- }
- }
- function register() {/* Do something */}
- function remind(){/* Do something */}
- }
- # If no UsersController declared - declare.
- if (!class_exists('UsersController')) {
- class UsersController extends SharedUsersController {}
- }
- ?>
- /*
- * At his point in any projects I could go to site.com/users/login
- * And it just works (TM)
- *
- * However if I what to have custom layout for login, just do:
- */
- <?
- var_dump(App::import('Controller', 'Share.Users'));
- class UsersController extends SharedUsersController {
- function login() {
- $this->layout="fancy";
- parent::login();
- }
- }
- /*
- * Thats IT. All register/remind/etc functionality works as originally intended,
- * but login has new layout.
- */
Add Comment
Please, Sign In to add comment