function actionSave() { //insert $blog = E_FW::load_Class('Model_BlogActiveRecord', true, array('id' => '2', 'category_id' => 4, 'title' => 'a3b')); $blog->category_id = 11; var_dump($blog->save()); var_dump($blog); }
function __construct(array $params = array()) { if (isset($params['className'])) { $this->_db = E_FW::load_Class($params['className']); } else { E_FW::load_File('exception_Writer'); throw new Exception_Writer('Database Can Not Connect.'); } if (isset($params['mapping'])) { $this->_mapping = $params['mapping']; } }
function actionIndex() { $w = E_FW::load_Class('writer_File', true, './test.txt'); $w2 = E_FW::load_Class('writer_File', true, './test2.txt'); $w3 = E_FW::load_Class('writer_Db', true, array('className' => 'Model_Log', 'mapping' => array('timestamp' => 'time', 'message' => 'msg', 'priority' => 'lvs', 'priorityName' => 'lvsName', 'pid' => 'pid'))); $w4 = E_FW::load_Class('writer_Syslog', true, array('application' => 'E_FW-DEMO')); $a = E_FW::load_Class('log_Core'); $a->addField('pid', getmypid()); $a->addWriter($w); $a->addWriter($w2); $a->addWriter($w3); $a->addWriter($w4); var_dump($a->info('abc')); }
function actionCache() { $output = E_FW::load_Class('cache_OutputAnalytics'); //开始页面缓存 if (!$output->start('blog_index')) { $this->_ModelBlog = E_FW::load_Class('Model_Blog'); //数据库操作 $this->_ModelBlog->where(''); $this->_ModelBlog->order('id desc'); $this->_ModelBlog->limit(30); $news = $this->_ModelBlog->select(array('isCount' => true)); var_dump($news); $output->end(); } }
/** * 演示数据校验 */ public function actionValidator() { echo 'source data:'; $data = array('title' => '1q1123@', 'tag' => '', 'content' => '阿萨德飞1', 'date' => '1300-11-11a', 'postTime' => '1234', 'test' => 'abc'); var_dump($data); //获取数据对象 $validator = E_FW::load_Class('data_Core'); //设定校验规则 $validatorRule = array('title' => array('rule' => 'Alnum', 'min' => 4, 'max' => 20), 'tag' => array('require' => true, 'rule' => 'English'), 'date' => array('require' => false, 'rule' => 'Date'), 'content' => array('rule' => 'Chinese', 'min' => 4, 'max' => 500), 'postTime' => array('min' => 11, 'rule' => 'Number'), 'author' => array('max' => 50)); $validator->set(null, $validatorRule, $data); $validator->validate(); echo 'unknown data:'; var_dump($validator->unknown); echo 'invalid data:'; var_dump($validator->invalid); echo 'missing data:'; var_dump($validator->missing); }
/** * 查找数据(静态方法) * * 通过 $args 的指定,查找符合的数据 * 返回对象或对象集合 * * @param string $class_name 数据 Model 名 * @param array $args 查找的条件,与 TableGateway 的方法对应 * @return mixed * @access public */ public static function find($class_name, $args) { $define = self::_defMeta($class_name); foreach ($args as $key => $value) { self::$_meta->{$key}($value); } $row = self::$_meta->select(); if (count($row) > 1) { $rowSet = array(); foreach ($row as $value) { $t = E_FW::load_Class($class_name, true, $value); if (isset($define['funcs'])) { $t->_funcs = $define['funcs']; } $rowSet[] = $t; } return $rowSet; } else { if (count($row) == 1) { $t = E_FW::load_Class($class_name, true, $row[0]); if (isset($define['funcs'])) { $t->_funcs = $define['funcs']; } return $t; } else { return E_FW::load_Class($class_name, true, array()); } } }
public function actionDelete() { $this->_ModelBlog = E_FW::load_Class('Model_Blog'); $this->_ModelBlog->where(1); var_dump($this->_ModelBlog->del()); }
function actionDelete() { $this->_ModelCategory = E_FW::load_Class('Model_Category'); $this->_ModelCategory->where(43); print_r($this->_ModelCategory->del()); }
/** * 供select方法使用,面向关联表操作的select方法 * * @param array $rt * @param string $linkType * @return void * @access protected */ protected function _getLinkData(&$rt, $linkType) { if (!count($rt)) { return; } $linkSetting = $this->{$linkType}; $linkClass = E_FW::load_Class($linkSetting['tableClass']); switch ($linkType) { case 'belongsTo': //Article->ColumnID Join Column->ID foreach ($rt as $val) { $ID[] = $val[$linkSetting['joinKey']]; } $IDStr = implode(',', $ID); $linkClass->where('`' . $linkClass->primaryKey . '` IN (' . $IDStr . ')'); $linkData = $linkClass->select(array('link' => '')); foreach ($rt as $key => $val) { foreach ($linkData as $k => $v) { if ($val[$linkSetting['joinKey']] == $v[$linkClass->primaryKey]) { $rt[$key][$linkSetting['mappingName']] = $v; //unset($linkData[$k]); break; } } } break; case 'hasOne': //User->ID Join UserProfiles->UserID if (!isset($linkSetting['linkKey'])) { $linkSetting['linkKey'] = $this->primaryKey; } foreach ($rt as $val) { $ID[] = $val[$linkSetting['linkKey']]; } $IDStr = implode(',', $ID); $linkClass->where('`' . $linkSetting['joinKey'] . '` IN (' . $IDStr . ')'); $linkData = $linkClass->select(array('link' => '')); foreach ($rt as $key => $val) { foreach ($linkData as $k => $v) { if ($val[$linkSetting['linkKey']] == $v[$linkSetting['joinKey']]) { $rt[$key][$linkSetting['mappingName']] = $v; unset($linkData[$k]); break; } } } break; case 'hasMany': //User->ID Join Order->UserID foreach ($rt as $val) { $ID[] = $val[$this->primaryKey]; } $IDStr = implode(',', $ID); $linkClass->where('`' . $linkSetting['joinKey'] . '` IN (' . $IDStr . ')'); $linkData = $linkClass->select(array('link' => '')); foreach ($rt as $key => $val) { foreach ($linkData as $v) { if ($val[$this->primaryKey] == $v[$linkSetting['joinKey']]) { $rt[$key][$linkSetting['mappingName']][] = $v; } } } break; case 'manyToMany': //User->ID Join UserRoles->UserID | UserRoles->RolesID Join Roles->ID foreach ($rt as $val) { $ID[] = $val[$this->primaryKey]; } $IDStr = implode(',', $ID); //首先查询第三方表的关系数据 $relateClass = E_FW::load_Class($linkSetting['relateClass']); $relateData = $relateClass->field($linkSetting['linkKey'] . ', ' . $linkSetting['joinKey'])->where($linkSetting['joinKey'] . ' IN (' . $IDStr . ')')->select(array('link' => '')); unset($relateClass); foreach ($relateData as $val) { $ID[] = $val[$linkSetting['linkKey']]; } $IDStr = implode(',', $ID); //根据第三方的关系数据查找目标表的记录 $linkData = $linkClass->where($linkClass->primaryKey . ' IN (' . $IDStr . ')')->select(array('link' => '')); //将目标记录组合到关系数据数组中 foreach ($relateData as $key => $val) { foreach ($linkData as $v) { if ($val[$linkSetting['linkKey']] == $v[$linkClass->primaryKey]) { $relateData[$key] = array_merge($val, $v); } } } unset($linkData); //将关系数据组合到最终数组 foreach ($rt as $key => $val) { foreach ($relateData as $v) { if ($val[$this->primaryKey] == $v[$linkSetting['joinKey']]) { $rt[$key][$linkSetting['mappingName']][] = $v; } } } unset($relateData); break; } unset($linkClass); }