本文整理汇总了PHP中plugins::save方法的典型用法代码示例。如果您正苦于以下问题:PHP plugins::save方法的具体用法?PHP plugins::save怎么用?PHP plugins::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plugins
的用法示例。
在下文中一共展示了plugins::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: formSave
/**
* Performs population of model
*
* @param object The base object to save
* @param string The message to display if successful
* @return bool
*/
protected function formSave(&$object, $saveMessage = NULL, $saveEvents = array())
{
// Determine name of the base model for the object being saved
if (get_parent_class($object) == 'Bluebox_Record') {
$baseClass = get_class($object);
} else {
$baseClass = get_parent_class($object);
}
// Import any post vars with the key of this model into the object
$formData = $this->input->post(strtolower($baseClass), array());
$object->fromArray($formData);
// Save data and all relations
try {
$this->save_prepare($object);
// Allow plugins to process any form-related data we just got back and attach to our data object
if (!plugins::save($this, $saveEvents)) {
throw new Bluebox_Exception('Plugins failed to save');
}
$this->pre_save($object);
// Save this base record
$object->save();
$this->post_save($object);
// Success - optionally set a save message
if (is_null($saveMessage)) {
$displayName = inflector::humanizeModelName(get_class($object));
message::set($displayName . ' saved!', array('type' => 'success'));
} else {
if (!empty($saveMessage)) {
message::set($saveMessage, array('type' => 'success'));
}
}
$this->save_succeeded($object);
return TRUE;
} catch (Doctrine_Connection_Exception $e) {
message::set('Doctrine error: ' . $e->getMessage());
} catch (Bluebox_Validation_Exception $e) {
message::set('Please correct the errors listed below.');
kohana::log('alert', $e->getMessage());
} catch (Bluebox_Exception $e) {
message::set('Please correct the errors listed below.');
kohana::log('alert', $e->getMessage());
} catch (Exception $e) {
message::set($e->getMessage());
}
$this->save_failed($object);
return FALSE;
}
示例2: index
/**
* This is the main wizard engine. It will process the steps in the protected $steps looking for
* methods that match the step name. When information is submitted back and a method called process{stepName}
* exists then the post var will be handed to it at which point that method chooses to continue
* to the next step (after processing the post) by returning true; otherwise if the process method of a
* step does not exist then it automaticly advances to the next or previous step.
*
* @return void
*/
public function index()
{
/**
* TODO: this is temporarliy here until the installMode step is but back
*/
$this->session->set('installer.installMode', 'install');
/**
* These vars are used to execute event hooks
*/
$this->views = $this->template->views = array();
// Get any responses
$returns = $this->input->post();
// If there are return values try to process them!
if (!empty($returns)) {
// This test makes sure that the form being submitted has a matching token,
// since the token changes every time the form is rendered if the tokens dont
// match then it must be a refresh....
$testToken = $this->session->get('installer.formToken', FALSE);
if (empty($returns['form_token']) || $returns['form_token'] != $testToken) {
if (isset($returns['next'])) {
unset($returns['next']);
}
if (isset($returns['prev'])) {
unset($returns['prev']);
}
}
// Save all the submits from this form
$ignoreReturns = array('next', 'prev', 'license', 'formToken');
foreach ($returns as $name => $return) {
if (!in_array($name, $ignoreReturns)) {
$this->session->set('installer.' . $name, $return);
}
}
$driver = $this->session->get('installer.tel_driver');
if (!empty($driver)) {
// Add an event for this telephony driver exclusively
$this->pluginEvents['driver'] = Router::$controller . '.' . $this->currentStep . '.' . $driver;
}
// See if the form was submitted with the next button
if (!empty($returns['next'])) {
// If the user wants to continue check for the existance of a method called process{stepName}
if (method_exists($this, 'process' . ucfirst($this->currentStep))) {
// It the process exists go to the next step on if this step returns true
$proceed = call_user_func(array($this, 'process' . ucfirst($this->currentStep)));
} else {
$proceed = TRUE;
}
// Run all registered save hooks for this installer.step
$proceed = $proceed & plugins::save($this, $this->pluginEvents);
// If the user wants to go back on step who are we to stop them?
$this->_nextWizard($proceed);
} else {
if (!empty($returns['prev'])) {
$this->_prevWizard();
}
}
}
// Lets generate a unique token that the form must respond with so on refresh
// it doesnt progress unexpectedly
$formToken = strtoupper(md5(uniqid(rand(), TRUE)));
$this->session->set('installer.formToken', $formToken);
$this->template->formToken = $formToken;
// Default to allow them to go to the back a step if the are not on the first.
$this->template->allowPrev = $this->currentStepKey > 0 ? TRUE : FALSE;
// By default they can always continue (but a step may disable this ability!)
$this->template->allowNext = TRUE;
// Attempt to render this step
try {
$subview = call_user_func(array($this, $this->currentStep));
// Set the step view in the main template
$this->template->content = $subview;
// Run all registered view hooks for this installer.step
plugins::views($this, $this->pluginEvents);
$this->template->views = $this->template->content->views;
} catch (Exception $e) {
$this->template->title = 'INSTALLATION ERROR';
$this->template->allowPrev = FALSE;
$this->template->allowNext = FALSE;
$subview = '<h2 class="error">ERROR: Can not execute step ' . $this->currentStep . ', wizard terminated!</h2>';
$subview .= '<small class="error">' . $e->getMessage() . '</small>';
$this->session->destroy();
// Set the step view in the main template
$this->template->content = $subview;
}
}