CakePHP - Dynamic Model


/ Published in: PHP
Save to your folder(s)

A small snippet on how to create a dynamic model in CakePHP (useful for global functions that need a model to function. IE functions defined in the AppController


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. // THE DYNAMIC MODEL
  4. App::Import('Model', $model);
  5. $this->DynamicModel = new $model;
  6.  
  7. // USAGE EXAMPLE
  8.  
  9. function getModelColumns($model){
  10. App::Import('Model', $model);
  11. $this->DynamicModel = new $model;
  12. print_r($this->DynamicModel->getColumnTypes());exit();
  13. }
  14.  
  15. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.