本文整理汇总了PHP中AppModel类的典型用法代码示例。如果您正苦于以下问题:PHP AppModel类的具体用法?PHP AppModel怎么用?PHP AppModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AppModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: refreshMirror
/**
*
* @param AppModel $model
*/
public function refreshMirror($model, $checkPendingOperations = false)
{
if ($checkPendingOperations) {
if ($this->_pending[$model->alias] > 0) {
return;
}
$this->_pending[$model->alias] = 0;
}
$config = $this->settings[$model->alias];
if ($model->Behaviors->enabled('Translate')) {
if ($config['findOptions']['recursive'] >= 0 || $model->Behaviors->Translate->settings[$model->alias]) {
$oldLang = SlConfigure::read('I18n.lang');
$locales = SlConfigure::read('I18n.locales');
$localesPreg = '/_' . implode('$|_', $locales) . '$/';
foreach ($locales as $lang => $locale) {
Sl::setLocale($lang);
$data = $model->find($config['findType'], $config['findOptions']);
if ($config['collectionField']) {
$this->_cleanup($config['name'], $locale);
}
$this->_write($config['name'], $this->_prepareData($model, $config, $data, $localesPreg), $locale);
}
Sl::setLocale($oldLang);
return;
}
}
$data = $model->find($config['findType'], $config['findOptions']);
if ($config['collectionField']) {
$this->_cleanup($config['name']);
}
$this->_write($config['name'], $this->_prepareData($model, $config, $data));
}
开发者ID:sandulungu,项目名称:StarLight,代码行数:36,代码来源:mirrored.php
示例2: pingbackRegisterComment
/**
* Register pingback comment. Used by pingback server
*
* @param AppModel $model
* @param string $modelId
* @param array $options
* @param string $sourceUri
* @param string $targetUri
* @return boolean
*/
public function pingbackRegisterComment(&$model, $modelId, $sourceUri, $targetUri)
{
extract($this->settings[$model->alias]);
if ($model->{$commentAlias}->hasAny(array($commentAlias . '.foreign_key' => $modelId, 'author_url' => $sourceUri))) {
throw new XmlRpcResponseException(0, 'Pingback already registries in system.');
}
$sourceBody = $this->loadPageContent($sourceUri);
if (strpos($sourceBody, $targetUri) === false) {
throw new XmlRpcResponseException(0, 'Source link is not detected in target blog.');
}
$sourceBody = $this->cleanupPage($sourceBody);
$title = $this->fetchTitle($sourceBody);
$cite = $this->fetchPingbackCite($sourceBody, $sourceUri, $targetUri);
$isSpam = false;
$data = array('comment_type' => 'pingback', 'author_name' => $title . 'blog', 'author_url' => $sourceUri, 'title' => $title, 'foreign_key' => $modelId, 'model' => $model->alias, 'body' => $cite);
if ($model->{$commentAlias}->Behaviors->enabled('Antispamable')) {
$isSpam = $model->isSpam();
}
$data['is_spam'] = $isSpam ? 'spam' : 'clean';
$modelData = $model->find('first', array('conditions' => array('id' => $modelId), 'recursive' => -1));
if (!empty($modelData[$model->alias][$requireApproveModelField])) {
$data[$requireApproveCommentField] = 0;
}
$model->{$commentAlias}->create($data);
return $model->{$commentAlias}->save();
}
开发者ID:sh1omi,项目名称:xlrstats-web-v3,代码行数:36,代码来源:PingbackableBehavior.php
示例3: validateStatus
/**
* Method for validation of status change flow
*
* @param AppModel $Model
* @param array $data
* @return boolean
* @access public
*/
public function validateStatus($Model, $data)
{
if ($Model->exists() && ($current = $Model->field('status'))) {
return in_array($data['status'], $this->settings[$Model->alias]['status'][$current]);
}
return false;
}
开发者ID:hadzi,项目名称:brekfarm,代码行数:15,代码来源:status.php
示例4: valueList
/**
* get valuelist from filemaker layout
*
* @param AppModel $model
* @param string $fieldName
* @return mixed array or false
*/
function valueList(&$model, $fieldName = null)
{
if (empty($model->returnValueLists) || !$model->returnValueLists) {
return false;
}
if ($fields = $model->schema()) {
$valueList = array();
foreach ($fields as $_fieldName => $_schema) {
if (!empty($_schema['valuelist'])) {
$valueList[$_fieldName] = array();
foreach ($_schema['valuelist'] as $value) {
$value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
$valueList[$_fieldName][$value] = $value;
}
}
}
if (empty($fieldName)) {
return $valueList;
} else {
if (!empty($valueList[$fieldName])) {
return $valueList[$fieldName];
}
}
}
return false;
}
开发者ID:nojimage,项目名称:FileMaker-Todo-App,代码行数:33,代码来源:fm_value_list.php
示例5: main
function main()
{
if (empty($this->args)) {
return $this->err('Usage: ./cake uuidize <table>');
}
if ($this->args[0] == '?') {
return $this->out('Usage: ./cake uuidize <table> [-force] [-reindex]');
}
$options = array('force' => false, 'reindex' => false);
foreach ($this->params as $key => $val) {
foreach ($options as $name => $option) {
if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) {
$options[$name] = true;
}
}
}
foreach ($this->args as $table) {
$name = Inflector::classify($table);
$Model = new AppModel(array('name' => $name, 'table' => $table));
$records = $Model->find('all');
foreach ($records as $record) {
$Model->updateAll(array('id' => '"' . String::uuid() . '"'), array('id' => $record[$name]['id']));
}
}
}
开发者ID:stripthis,项目名称:donate,代码行数:25,代码来源:uuidize.php
示例6: main
function main()
{
if (empty($this->args)) {
return $this->err('Usage: ./cake fixturize <table>');
}
if ($this->args[0] == '?') {
return $this->out('Usage: ./cake fixturize <table> [-force] [-reindex]');
}
$options = array('force' => false, 'reindex' => false);
foreach ($this->params as $key => $val) {
foreach ($options as $name => $option) {
if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) {
$options[$name] = true;
}
}
}
foreach ($this->args as $table) {
$name = Inflector::classify($table);
$Model = new AppModel(array('name' => $name, 'table' => $table));
$file = sprintf('%stests/fixtures/%s_fixture.php', APP, Inflector::underscore($name));
$File = new File($file);
if ($File->exists() && !$options['force']) {
$this->err(sprintf('File %s already exists, use --force option.', $file));
continue;
}
$records = $Model->find('all');
$out = array();
$out[] = '<?php';
$out[] = '';
$out[] = sprintf('class %sFixture extends CakeTestFixture {', $name);
$out[] = sprintf(' var $name = \'%s\';', $name);
$out[] = ' var $records = array(';
$File->write(join("\n", $out));
foreach ($records as $record) {
$out = array();
$out[] = ' array(';
if ($options['reindex']) {
foreach (array('old_id', 'vendor_id') as $field) {
if ($Model->hasField($field)) {
$record[$name][$field] = $record[$name]['id'];
break;
}
}
$record[$name]['id'] = String::uuid();
}
foreach ($record[$name] as $field => $val) {
$out[] = sprintf(' \'%s\' => \'%s\',', addcslashes($field, "'"), addcslashes($val, "'"));
}
$out[] = ' ),';
$File->write(join("\n", $out));
}
$out = array();
$out[] = ' );';
$out[] = '}';
$out[] = '';
$out[] = '?>';
$File->write(join("\n", $out));
$this->out(sprintf('-> Create %sFixture with %d records (%d bytes) in "%s"', $name, count($records), $File->size(), $file));
}
}
开发者ID:stripthis,项目名称:donate,代码行数:60,代码来源:fixturize.php
示例7: beforeSave
/**
* Set current language
*
* @param AppModel $Model
*/
public function beforeSave(&$Model) {
$settings = $this->settings[$Model->alias];
$language = Configure::read('Config.language');
if ($Model->hasField($settings['languageField'])) {
$Model->set(array($settings['languageField'] => $language));
}
}
开发者ID:ntung,项目名称:i18n,代码行数:12,代码来源:i18nable.php
示例8: beforeSave
/**
* beforeSave callback, initializes created_by or modified_by field values
*
* @param AppModel $Model
* @return boolean
* @access public
*/
public function beforeSave($Model)
{
$field = $Model->exists() ? 'modified_by' : 'created_by';
if ($Model->hasField($field)) {
$Model->set($field, $this->_getUserId());
$this->_addToWhitelist($Model, $field);
}
return true;
}
开发者ID:hadzi,项目名称:brekfarm,代码行数:16,代码来源:owned.php
示例9: saveDataFromArray
static function saveDataFromArray($object, $listData, $listKey)
{
if (count($listData) == 0) {
return true;
}
$id = $object->getID();
$msgError = '';
$listLanguage = array_keys(Configure::read('MultiLanguage.fallback') + Configure::read('MultiLanguage.list'));
$mapping = Configure::read('MultiLanguage.app_mapping_list');
for ($ii = 1; $ii < count($listData[0]); $ii++) {
$listData[0][$ii] = isset($mapping[strtolower($listData[0][$ii])]) ? $mapping[strtolower($listData[0][$ii])] : $listData[0][$ii];
}
$data = $listData[0];
if (strtoupper($data[0]) != 'KEY' || count(array_intersect($listLanguage, $data)) != count($listLanguage)) {
$msgError = __('The header of Excel file shoud be in format') . ': Key';
foreach ($listLanguage as $lang) {
$msgError .= ', ' . $lang;
}
} else {
$listLanguage = $data;
$numField = count($listLanguage);
$dataMultiLang = array();
for ($row = 1; $row < count($listData); $row++) {
$data = $listData[$row];
$num = count($data);
if ($num != $numField || !in_array($data[0], $listKey)) {
$msgError .= __('Cannot import line %s', $row) . "<br />";
} else {
for ($c = 1; $c < $num; $c++) {
$dataMultiLang[$listLanguage[$c]][$data[0]] = $data[$c];
}
}
}
}
$fallback = array_keys(Configure::read('MultiLanguage.fallback'));
if (isset($dataMultiLang[$fallback[0]])) {
$row = $dataMultiLang[$fallback[0]];
$row['id'] = $id;
$object->clear();
$object->save($row, false);
unset($dataMultiLang[$fallback[0]]);
}
$model = new AppModel();
$model->useTable = 'multilanguage_' . $object->useTable;
foreach ($dataMultiLang as $lang => $row) {
$objMultiLang = $model->findByObjectIdAndLangCode($id, $lang);
if (isset($objMultiLang['AppModel']['id'])) {
$row['id'] = $objMultiLang['AppModel']['id'];
}
$row['lang_code'] = $lang;
$row['object_id'] = $id;
$model->clear();
$model->save($row, false);
}
return $msgError;
}
开发者ID:pdkhuong,项目名称:BBG,代码行数:56,代码来源:MultiLanguageLib.php
示例10: setup
/**
* Setup
*
* @param AppModel $model
* @param array $settings
* @access public
*/
public function setup(&$model, $settings = array())
{
if (!isset($this->settings[$model->alias])) {
$this->settings[$model->alias] = $this->defaults;
}
$this->settings[$model->alias] = am($this->settings[$model->alias], ife(is_array($settings), $settings, array()));
$cfg = $this->settings[$model->alias];
$model->bindModel(array('hasMany' => array('Comment' => array('className' => $cfg['commentModel'], 'foreignKey' => 'foreign_key', 'unique' => true, 'conditions' => '', 'fields' => '', 'dependent' => true, 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderQuery' => '', 'counterQuery' => ''))), false);
$model->Comment->bindModel(array('belongsTo' => array($model->name => array('className' => $model->name, 'foreignKey' => 'foreign_key', 'unique' => true, 'conditions' => '', 'fields' => '', 'dependent' => false))), false);
$model->Comment->bindModel(array('belongsTo' => array($cfg['userModelAlias'] => array('className' => $cfg['userModelClass'], 'foreignKey' => 'user_id', 'conditions' => '', 'fields' => '', 'counterCache' => true, 'order' => ''))), false);
}
开发者ID:hiltongoncalves,项目名称:Comments,代码行数:18,代码来源:commentable.php
示例11: isset
/**
* SetById method. Check is model innitialized.
*
* If $id is defined read record from model with this primary key value
*
* @param AppModel $model
* @param ID $id - value of model primary key to read
* @return boolean True if model initialized, false if no info in $model->data exists.
* @access private
*/
function __setById(&$model, $id = null, $checkId = true)
{
if (!isset($id)) {
if ($checkId) {
return isset($model->data[$model->alias]['id']);
} else {
return isset($model->data[$model->alias]);
}
} else {
return $model->read(null, $id);
}
}
开发者ID:Galvanio,项目名称:Kinspir,代码行数:22,代码来源:list.php
示例12: to_400
/**
* Upgrade to 4.0.0.
*/
public function to_400()
{
$this->out('<warning>This upgrade will delete the following tables after migration: settings, access, access_levels, profiles, reported.</warning>');
$answer = strtoupper($this->in('All data will be migrated to the new admin system, are you sure you want to continue?', array('Y', 'N')));
if ($answer === 'N') {
exit;
}
// Migrate old reports to the new admin system
$this->out('<success>Migrating reports...</success>');
$ItemReport = ClassRegistry::init('Admin.ItemReport');
$Reported = new AppModel(null, 'reported', $this->dbConfig);
$Reported->alias = 'Reported';
$Reported->tablePrefix = $this->tablePrefix;
foreach ($Reported->find('all') as $report) {
switch ($report['Reported']['itemType']) {
case 1:
$model = 'Forum.Topic';
break;
case 2:
$model = 'Forum.Post';
break;
case 3:
$model = $this->usersModel;
break;
}
$ItemReport->reportItem(array('reporter_id' => $report['Reported']['user_id'], 'model' => $model, 'foreign_key' => $report['Reported']['item_id'], 'item' => $report['Reported']['item_id'], 'reason' => $report['Reported']['comment'], 'created' => $report['Reported']['created']));
}
// Migrate profile data to users table
$this->out('<success>Migrating user profiles...</success>');
$User = ClassRegistry::init($this->usersModel);
$fieldMap = Configure::read('User.fieldMap');
$Profile = new AppModel(null, 'profiles', $this->dbConfig);
$Profile->alias = 'Profile';
$Profile->tablePrefix = $this->tablePrefix;
foreach ($Profile->find('all') as $prof) {
$query = array();
foreach (array('signature', 'locale', 'timezone', 'totalPosts', 'totalTopics', 'lastLogin') as $field) {
if ($key = $fieldMap[$field]) {
$query[$key] = $prof['Profile'][$field];
}
}
if (!$query) {
continue;
}
$User->id = $prof['Profile']['user_id'];
$User->save(array_filter($query), false);
}
// Delete tables handled by parent shell
$this->out('<success>Deleting old tables...</success>');
return true;
}
开发者ID:Lazy123,项目名称:forum,代码行数:54,代码来源:UpgradeShell.php
示例13: retrieveItem
protected function retrieveItem(AppModel $object, $parameter_not_found = MESSAGE_PARAMETER_NOT_FOUND, $parameter_not_valid = MESSAGE_PARAMETER_NOT_VALID, $record_not_found = MESSAGE_RECORD_NOT_FOUND)
{
if (count($this->registry->request['args']) <= 0) {
$this->error_500(array("error_string" => $parameter_not_found));
}
$id = intval($this->registry->request['args']['0']);
if ($id == 0) {
$this->error_500(array("error_string" => $parameter_not_valid));
}
$item = $object->get($id);
if ($item == null) {
$this->error_500(array("error_string" => $record_not_found));
}
return $item;
}
开发者ID:sg4r3z,项目名称:umvc,代码行数:15,代码来源:abstract.appcontroller.php
示例14: startTest
/**
* undocumented function
*
* @return void
* @access public
*/
function startTest()
{
$this->Sut = new GiftsController();
$this->Sut->constructClasses();
$this->Sut->Component->initialize($this->Sut);
$this->Sut->beforeFilter();
$this->Sut->Component->startup($this->Sut);
$this->Gift = ClassRegistry::init('Gift');
$this->Contact = ClassRegistry::init('Contact');
$this->Address = ClassRegistry::init('Address');
$this->Appeal = ClassRegistry::init('Appeal');
$this->Office = ClassRegistry::init('Office');
$this->Country = ClassRegistry::init('Country');
$this->City = ClassRegistry::init('City');
$this->Frequency = ClassRegistry::init('Frequency');
$models = array('Gift', 'Contact', 'Address', 'Phone');
AppModel::resetRequired($models);
if (!$this->gpiAppealId) {
$this->gpiAppealId = $this->Appeal->lookup(array('name LIKE' => '%default GPI appeal%'), 'id', false);
}
if (!$this->exampleAppealId) {
$this->exampleAppealId = $this->Appeal->lookup(array('name LIKE' => '%Example%'), 'id', false);
}
if (!$this->belgiumOfficeId) {
$this->belgiumOfficeId = $this->Office->lookup(array('name LIKE' => '%Belgium%'), 'id', false);
}
if (!$this->gpiOfficeId) {
$this->gpiOfficeId = $this->Office->lookup(array('name LIKE' => '%International%'), 'id', false);
}
}
开发者ID:stripthis,项目名称:donate,代码行数:36,代码来源:gifts_controller.test.php
示例15: changed
/**
* Mark a node change, triggering cascade cache clearing
*
* @param AppModel $model
* @param int $id
*/
public function changed($model, $id = null)
{
if (empty($id)) {
$id = $model->getID();
}
if ($model->Behaviors->enabled('Translate')) {
$locales = SlConfigure::read('I18n.locales');
foreach ($locales as $locale) {
$key = Inflector::underscore($model->alias) . "_{$id}_{$locale}";
Cache::delete($key, 'models');
}
} else {
$key = Inflector::underscore($model->alias) . "_{$id}";
Cache::delete($key, 'models');
}
}
开发者ID:sandulungu,项目名称:StarLight,代码行数:22,代码来源:cacheable.php
示例16: testGetUserTimeline
function testGetUserTimeline()
{
$result = $this->TestModel->getUserTimeline();
foreach ($result as $tweet) {
$this->assertEqual($tweet['user']['id'], 152934772);
}
// -- change user
$result = $this->TestModel->getUserTimeline('nojimage');
foreach ($result as $tweet) {
$this->assertEqual($tweet['user']['id'], 15982041);
}
$this->TestModel->data = array($this->TestModel->alias => array($this->TestModel->primaryKey => 'nojimage'));
$result = $this->TestModel->getUserTimeline();
foreach ($result as $tweet) {
$this->assertEqual($tweet['user']['id'], 15982041);
}
// -- limit
$result = $this->TestModel->getUserTimeline(array('id' => 'nojimage', 'count' => 10));
$this->assertTrue(count($result) <= 10);
// -- max_id
$last_id = $result[count($result) - 1]['id_str'];
$result = $this->TestModel->getUserTimeline(array('id' => 'nojimage', 'max_id' => $last_id));
$this->assertEqual($result[0]['id'], $last_id);
// -- paging
$next_id = $result[1]['id'];
$result = $this->TestModel->getUserTimeline(array('id' => 'nojimage', 'count' => 10, 'page' => 2));
$this->assertEqual($result[0]['id'], $next_id);
// -- exclude reply
$result = $this->TestModel->getUserTimeline(array('id' => 'nojimage', 'page' => 2, 'exclude_reply' => true));
foreach ($result as $tweet) {
$this->assertPattern('/^[^@]/u', $tweet['text'], $tweet['text']);
}
}
开发者ID:sanrentan,项目名称:sanrentan,代码行数:33,代码来源:TwitterTimelineBehaviorTest.php
示例17: beforeSave
/**
* Before save callback
*
* @return bool Success
*/
function beforeSave()
{
parent::beforeSave();
// Construct the absolute page URL
if (isset($this->data[$this->name]['slug'])) {
$level = 0;
$homePageId = intval(Configure::read('Wildflower.settings.home_page_id'));
if (intval($this->id) === $homePageId && $homePageId !== 0) {
// Home page has the URL of root
$this->data[$this->name]['url'] = '/';
} else {
if (!isset($this->data[$this->name]['parent_id']) or !is_numeric($this->data[$this->name]['parent_id'])) {
// Page has no parent
$this->data[$this->name]['url'] = "/{$this->data[$this->name]['slug']}";
} else {
$parentPage = $this->findById($this->data[$this->name]['parent_id'], array('url'));
$url = "/{$this->data[$this->name]['slug']}";
if ($parentPage[$this->name]['url'] !== '/') {
$url = $parentPage[$this->name]['url'] . $url;
}
$this->data[$this->name]['url'] = $url;
}
}
}
// Publish?
if (isset($this->data[$this->name]['publish'])) {
$this->data[$this->name]['draft'] = 0;
unset($this->data[$this->name]['publish']);
}
return true;
}
开发者ID:sambernard,项目名称:wildflower,代码行数:36,代码来源:page.php
示例18: afterDelete
/**
* afterDelete
*
* @return bool
*/
public function afterDelete()
{
if (!parent::afterDelete()) {
return false;
}
return true;
}
开发者ID:kingsolmn,项目名称:CakePHP-Braintree-Plugin,代码行数:12,代码来源:braintree_app_model.php
示例19: beforeSave
function beforeSave()
{
if (isset($this->data['Image']['tags'])) {
$this->data['Image']['tags'] = $this->cleanTags($this->data['Image']['tags']);
}
return parent::beforeSave();
}
开发者ID:phototech,项目名称:sailvenice,代码行数:7,代码来源:image.php
示例20: edit
public function edit($id = 0)
{
$this->fields['file_name']['visible'] = false;
$this->fields['file_content']['visible'] = false;
parent::edit($id);
$this->render = 'edit';
}
开发者ID:ivanbautsita,项目名称:gestion-escolar-campus-virtuales,代码行数:7,代码来源:StaffAttachment.php
注:本文中的AppModel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论