示例#1
0
 /**
  *  constructor
  *  @param  mixed   param   PDO instance,
  *                          or record id (if integer),
  *                          or constraints (if array) but param['pdo'] is PDO instance
  */
 function __construct($params = null)
 {
     try {
         if (!static::$db && static::$adapter) {
             static::$db = new static::$adapter(static::$db_settings);
         }
     } catch (Exception $e) {
         throw new WaxDbException("Cannot Initialise DB", "Database Configuration Error");
     }
     $class_name = get_class($this);
     if ($class_name != 'WaxModel' && !$this->table) {
         $this->table = Inflections::underscore($class_name);
     }
     $this->define($this->primary_key, $this->primary_type, $this->primary_options);
     $this->setup();
     $this->set_identifier();
     // If a scope is passed into the constructor run a method called scope_[scope]().
     if ($params) {
         $method = "scope_" . $params;
         if (method_exists($this, $method)) {
             $this->{$method};
         } else {
             $res = $this->filter(array($this->primary_key => $params))->first();
             $this->row = $res->row;
             $this->clear();
         }
     }
 }
示例#2
0
 public function setup()
 {
     $this->col_name = false;
     $class_name = get_class($this->model);
     if (!$this->target_model) {
         $this->target_model = Inflections::camelize($this->field, true);
     }
     if (!$this->join_field) {
         $this->join_field = Inflections::underscore($class_name) . "_" . $this->model->primary_key;
     }
 }
示例#3
0
 public function setup()
 {
     if (!$this->target_model) {
         $this->target_model = Inflections::camelize($this->field, true);
     }
     $link = new $this->target_model();
     // Overrides naming of field to model_id if col_name is not explicitly set
     if ($this->col_name == $this->field) {
         $this->col_name = Inflections::underscore($this->target_model) . "_" . $link->primary_key;
     }
 }
示例#4
0
文件: WaxForm.php 项目: phpwax/phpwax
 /**
  * new function to return a default array of settings for any
  * new element added via define / add_element
  * main purpose is to prefix name attribute and ids with form_prefix 
  * to make them unique 
  */
 public function element_settings($name, $settings = array())
 {
     if (!$settings['post_fields']) {
         $settings['post_fields']['model'] = $this->form_prefix;
         $settings['post_fields']['attribute'] = $name;
     }
     if (!$settings['label']) {
         $settings['label'] = ucwords($name);
     }
     if (!$settings['id']) {
         $settings['id'] = $settings['post_fields']['model'] . "_" . Inflections::underscore($name);
     }
     return $settings;
 }
示例#5
0
 function __construct($params = null)
 {
     if (self::$adapter && !($this->db = new self::$adapter(self::$db_settings))) {
         throw new WaxDbException("Cannot Initialise API Connection", "Database Configuration Error");
     }
     $class_name = get_class($this);
     if ($class_name != 'WaxModel' && !$this->table) {
         $this->table = Inflections::underscore($class_name);
     }
     if ($params && is_string($params)) {
         //set the primary key to the right value;
         $this->{$this->primary_key} = $params;
     }
     $this->define($this->primary_key, $this->primary_type, $this->primary_options);
     $this->setup();
     $this->set_identifier();
 }
示例#6
0
 public function file()
 {
     return $this->cache_dir . Inflections::underscore(Inflections::slashcamelize($this->label)) . ".cache";
 }
示例#7
0
文件: Email.php 项目: phpwax/email
 public function get_templates($action)
 {
     $view = Inflections::underscore(get_class($this)) . "/" . $action;
     $view_path = new WaxTemplate($this);
     $view_path->add_path(VIEW_DIR . $view);
     $view_path->add_path(PLUGIN_DIR . "cms/view/" . $view);
     foreach ($view_path->template_paths as $path) {
         if (is_readable($path . ".html")) {
             $html = $view_path->parse();
         }
         if (is_readable($path . ".txt")) {
             $txt = $view_path->parse("txt");
         }
     }
     if ($html && $txt) {
         $this->is_html(true);
         $this->body = $html;
         $this->alt_body = $txt;
     } elseif ($html) {
         $this->is_html(true);
         $this->content_for_layout = $html;
         if ($content = $this->render_layout()) {
             $this->body = $content;
         } else {
             $this->body = $this->content_for_layout;
         }
     } elseif (!$html && $txt) {
         $this->body = $txt;
     }
 }
示例#8
0
 /**
  * Add the relationship
  *
  * @return Schema
  * @author Justin Palmer
  **/
 private function addRelationship($name, $type)
 {
     $options = new stdClass();
     $options->name = $name;
     $options->type = $type;
     $options->alias = Inflections::underscore(str_replace('-', '_', $name));
     $options->table = Inflections::tableize($options->alias);
     $options->foreign_key = Inflections::foreignKey(Inflections::singularize($this->model->table_name()));
     $this->relationships->set($name, $options);
     $options->on = $this->autoGenerateOn($name);
     $this->relationships->set($name, $options);
     return $this;
 }
示例#9
0
 /**
  * Register a new object with FormBuilder
  *
  * @return void
  * @author Justin Palmer
  **/
 public static function register($form_element)
 {
     if (self::$Registered === null) {
         self::$Registered = new Hash();
     }
     self::$Registered->set(Inflections::underscore($form_element), $form_element);
 }
示例#10
0
 /**
  *	This method is what it's all about, it simply steps through the filters and
  *	runs the action.
  *
  *	It then picks up the view content along the way and hey presto, you have a page.
  *  If you've messed up and not provided an action, it throws an exception.
  *
  *	@access protected
  */
 public function execute_request()
 {
     $this->controller = WaxUrl::get("controller");
     $this->action = WaxUrl::get("action");
     $this->route_array = explode("/", $_GET["route"]);
     $this->use_format = WaxUrl::get("format");
     WaxLog::log("info", "Loading controller {$this->controller} with action {$this->action} from route '{$_GET['route']}'");
     $this->controller_global();
     $this->run_filters("before");
     if (!$this->is_public_method($this, $this->action)) {
         if ($this->is_public_method($this, Inflections::underscore($this->action))) {
             $underscore_action = Inflections::underscore($this->action);
             $this->{$underscore_action}();
         } elseif (method_exists($this, 'method_missing')) {
             $this->method_missing();
         } else {
             $class = get_class($this);
             throw new WXRoutingException("No Public Action Defined for - " . $this->action . " in controller {$class}.", "Missing Action");
         }
     } else {
         $this->{$this->action}();
     }
     $this->run_filters("after");
     $this->content_for_layout = $this->render_view();
     if ($content = $this->render_layout()) {
         echo $content;
     } elseif ($this->content_for_layout) {
         echo $this->content_for_layout;
     } else {
         echo "";
     }
 }