本文整理汇总了PHP中Model::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::save方法的具体用法?PHP Model::save怎么用?PHP Model::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*/
protected function setUp()
{
$this->user = Model::fromArray(array('lastname' => 'Test', 'firstname' => 'Test', 'email' => 'pierre.rambaud86@gmail.com', 'login' => 'test-user-model', 'user_acl_role_id' => 1));
$this->user->setPassword('test-user-model-password');
$this->user->save();
$this->object = new Acl($this->user);
}
示例2: edit
public function edit($id)
{
if (IS_POST) {
//获取数据
if ($this->model->create() !== false) {
//判断数据是否正确
if ($this->model->save() !== false) {
$this->success('修改成功', cookie('__forward__'));
return;
//防止后面代码执行
}
}
$this->error('修改失败');
} else {
//调用钩子函数
$this->_before_edit_view();
//给页面分配树的数据
$row = $this->model->find($id);
//页面分配数据
$this->assign('meta_title', '编辑' . $this->meta_title);
$this->assign('row', $row);
$this->assign('id', $id);
//加载视图
$this->display('add');
}
}
示例3: error
/**
* Triggered when we're passed an error from the `WhistleComponent`
*
* @param array $error
* @return void
*/
public function error($error)
{
$error['level'] = $this->_translateError($error['level']);
$data = array();
if ($this->_model->name == 'RefereeLog') {
if (!empty($error['args'])) {
$error['args'] = serialize($error['args']);
}
if (!empty($error['trace'])) {
$error['trace'] = serialize($error['trace']);
}
if (!empty($error['request_parameters'])) {
$error['request_parameters'] = serialize($error['request_parameters']);
}
$data = $error;
} else {
$schema = array_keys($this->_model->schema());
$mapping = $this->_config['mapping'];
foreach ($error as $key => $value) {
if (!empty($mapping[$key])) {
if (is_array($mapping[$key])) {
$column = array_pop(array_intersect($mapping[$key], $schema));
} else {
$column = in_array($mapping[$key], $schema) ? $mapping[$key] : null;
}
if (!empty($column)) {
$data[$column] = $value;
}
}
}
}
$this->_model->save($data);
}
示例4: setVersion
/**
* Set current version for given type
*
* @param integer $version Current version
* @param string $type Can be 'app' or a plugin name
* @param boolean $migrated If true, will add the record to the database
* If false, will remove the record from the database
* @return boolean
*/
public function setVersion($version, $type, $migrated = true)
{
if ($migrated) {
$this->Version->create();
return $this->Version->save(array('version' => $version, 'type' => $type));
} else {
$conditions = array($this->Version->alias . '.version' => $version, $this->Version->alias . '.type' => $type);
return $this->Version->deleteAll($conditions);
}
}
示例5: addData
private function addData()
{
$validated = $this->modelInstance->setData($this->modelData);
if ($validated === true) {
$this->modelInstance->save();
$this->added++;
return 'Added';
} else {
return $validated;
}
}
示例6: write
/**
* Implements writing to log table.
*
* @param string $type The type of log you are making.
* @param string $content The message you want to log.
* @return boolean success of write.
*/
public function write($type, $content, $module = 'system', $foreign_key = 0)
{
$data = compact('type', 'content', 'module', 'foreign_key');
$user = AuthComponent::user();
if (!empty($user)) {
$data['user_id'] = $user['id'];
$data['username'] = $user['name'];
}
self::$_model->create();
return self::$_model->save($data);
}
示例7: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*/
public function setUp()
{
$this->init();
$this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content'));
$this->view->save();
$this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content'));
$this->layout->save();
$this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId()));
$this->documentType->save();
$this->document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => null));
$this->document->save();
ModuleModel::install(Registry::get('Application')->getServiceManager()->get('CustomModules'), 'Blog');
}
示例8: setUp
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @return void
*/
protected function setUp()
{
$this->view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content'));
$this->view->save();
$this->layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content'));
$this->layout->save();
$this->user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => 'pierre.rambaud86@gmail.com', 'login' => 'test', 'user_acl_role_id' => 1));
$this->user->setPassword('test');
$this->user->save();
$this->documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $this->view->getId(), 'user_id' => $this->user->getId()));
$this->documentType->save();
$this->document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => null));
$this->document->save();
$this->object = new Sitemap();
}
示例9: testMultipleUploadSaveReadDelete
public function testMultipleUploadSaveReadDelete()
{
// setup
$this->Model->Behaviors->load('Media.Attachable', array());
$this->Model->configureAttachment(array('files' => array('baseDir' => $this->attachmentDir, 'multiple' => true, 'removeOnOverwrite' => true)), true);
$data = array($this->Model->alias => array('title' => 'My Upload', 'files_upload' => array($this->upload1, $this->upload2)));
// save
$this->Model->create();
$result = $this->Model->save($data);
$this->assertTrue(isset($this->Model->id));
$this->assertEqual($result[$this->Model->alias]['files_upload'], '');
$this->assertEqual(preg_match('/Upload_File_1_([0-9a-z]+).txt,Upload_File_2_([0-9a-z]+).txt$/', $result[$this->Model->alias]['files']), 1);
$this->assertTrue(isset($result['Attachment']['files'][0]['path']));
$this->assertTrue(file_exists($result['Attachment']['files'][0]['path']));
$this->assertTrue(isset($result['Attachment']['files'][1]['path']));
$this->assertTrue(file_exists($result['Attachment']['files'][1]['path']));
// read
$modelId = $this->Model->id;
$this->Model->create();
$result = $this->Model->read(null, $modelId);
$this->assertTrue(isset($result[$this->Model->alias]['files']));
$this->assertTrue(!isset($result[$this->Model->alias]['files_upload']));
$this->assertEqual(preg_match('/Upload_File_1_([0-9a-z]+).txt,Upload_File_2_([0-9a-z]+).txt$/', $result[$this->Model->alias]['files']), 1);
$this->assertTrue(isset($result['Attachment']['files'][0]['path']));
$this->assertTrue(file_exists($result['Attachment']['files'][0]['path']));
$this->assertTrue(isset($result['Attachment']['files'][1]['path']));
$this->assertTrue(file_exists($result['Attachment']['files'][1]['path']));
//delete
$deleted = $this->Model->delete($this->Model->id);
$this->assertTrue($deleted, 'Failed to delete Attachment');
$this->assertTrue(!file_exists($result['Attachment']['files'][0]['path']), 'Attachment not deleted');
$this->assertTrue(!file_exists($result['Attachment']['files'][1]['path']), 'Attachment not deleted');
}
示例10: save
public function save(array $options = [])
{
if (empty($this->finished_at)) {
$this->finished_at = new DateTime();
}
return parent::save($options);
}
示例11: save
function save()
{
$this->import_parameters();
$this->load_library('htmlpurifier-4.5.0-lite/library/HTMLPurifier.auto');
$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$message = $purifier->purify(html_entity_decode($this->message));
$this->set('message', $message);
$reference_object = new $this->reference_object($this->reference_id);
//if the message is being created for an object other than a project, then the project id will be retrieved from
//the actual object
//if the message is being posted on a project, then the project id is the messages reference_id
if ($this->reference_object != 'project') {
$project_id = isset($reference_object->project_id) ? $reference_object->project_id : false;
} else {
$project_id = $this->reference_id;
}
if ($project_id) {
$this->set('project_id', $project_id);
}
if (isset($reference_object->client_id)) {
$this->set('client_id', $reference_object->client_id);
}
$this->set('user_id', current_user()->id);
//these two parameters shouldn't be set yet (they are set when we log activity which happens after the save),
//but let's just make sure
$this->unset_param('linked_object');
$this->unset_param('linked_object_title');
$result = parent::save();
ActivityManager::message_created($this);
return $result;
}
示例12: save
public function save()
{
if ($this->permalink == "") {
$this->permalink = self::make_permalink($this->name);
}
return parent::save(self::table);
}
示例13: save
public function save()
{
if (!$this->priority) {
$this->priority = "Normal";
}
return parent::save(self::table);
}
示例14: save
public function save()
{
//$form = Helper::createForm($wget='');
$form = Helper::createForm();
$postData = ipRequest()->getPost();
$errors = $form->validate($postData);
if ($errors) {
// Validation error
$status = array('status' => 'error', 'errors' => $errors);
return new \Ip\Response\Json($status);
} else {
// Success
Model::save(ipRequest()->getPost('language_id'), ipRequest()->getPost('zone_name'), ipRequest()->getPost('user_id'), ipRequest()->getPost('name'), ipRequest()->getPost('email'), ipRequest()->getPost('link'), ipRequest()->getPost('text'), ipRequest()->getPost('ip'), ipRequest()->getPost('approved'), ipRequest()->getPost('session_id'), ipRequest()->getPost('verification_code'), ipRequest()->getPost('active'));
//get page where this widget sits :)
$postData = ipRequest()->getPost();
$vcode = $postData['verification_code'];
$fullWidgetRecord = \Ip\Internal\Content\Model::getWidgetRecord($postData['wgetId']);
$pageTitle = '';
if (isset($fullWidgetRecord['revisionId'])) {
$revision = \Ip\Internal\Revision::getRevision($fullWidgetRecord['revisionId']);
if (!empty($revision['pageId'])) {
$pageTitle = ipPage($revision['pageId'])->getTitle();
}
}
$stamp = date(__('m/d/Y', 'Comments')) . __(', at ', 'Comments') . date('H:i:s');
//sending email notification
Helper::sendMailNotification(trim(ipRequest()->getPost('zone_name')), trim(ipRequest()->getPost('name')), $stamp, trim(ipRequest()->getPost('text')), trim(ipRequest()->getPost('email')), trim($pageTitle), trim($vcode));
//$actionUrl = ipActionUrl(array('sa' => 'FormExample.showSuccessMessage'));
//$status = array('redirectUrl' => $actionUrl);
$status = array('status' => 'ok');
//success
return new \Ip\Response\Json($status);
}
}
示例15: save
public function save(array $options = array())
{
if (!$this->reject_sn) {
$this->reject_sn = uniqid();
}
parent::save($options);
}