Ãþ§OActionªºÄ~©Ó¹Ï:

¤½¶}¤èªk(Public Methods) | |
| Action ($actionInfo, $httpRequest) | |
| perform () | |
| validate () | |
| validationErrorProcessing () | |
| setValidationErrorView ($view) | |
| registerFieldValidator ($fieldName, $validator, $onlyIfAvailable=false) | |
| registerField ($fieldName) | |
| getView () | |
| setCommonData ($copyFormValues=false) | |
| setForwardAction ($nextActionKey) | |
| setSuccess ($success) | |
¤½¶}ÄÝ©Ê | |
| $_view | |
| $_request | |
| $_actionInfo | |
| $_fieldValidators | |
| $_validationErrorView | |
| $_previousAction | |
| $_isSuccess | |
¨p¦³¤èªk(Private Methods) | |
| setPreviousAction ($previousAction) | |
| getPreviousAction () | |
| setForwardActionParameter ($param, $value) | |
Action classes are expected to at least provide their own logic in the Action::perform() method. In previous versions of pLog it was also necessary to provide data validation logic in the Action::validate() method, but that is not necessary anymore (albeit possible if needed) since the introduction of the new data validation framework (See the FormValidator class and the Validator and Validator_Rules modules) The Action::validate() method now provides some code of its own that triggers the data validation process if there is any data to be validated.
There is a lot more information about the data validation framework here: http://wiki.plogworld.net/index.php/PLog_1.0/Forms_and_data_validation
The View object that Action classes must create can be set via the private attribute Action::_view or te method Action::setView(), though the first one is the most widely used throughout the core code.
Please keep in mind that it is advisable to call the Action::setCommonData() method at the very end of the Action::perform() method in our custom classes because it needs to perform some extra operations right before the view is sent back to the controller.
©w¸q¦b action.class.php Àɮפ§²Ä 56 ¦æ.
|
||||||||||||
|
Constructor.
©w¸q¦b action.class.php Àɮפ§²Ä 74 ¦æ. °Ñ¦Ò Object::Object(). ³Q°Ñ¦Ò©ó AdminAction::AdminAction(), AdminDefaultAction::AdminDefaultAction(), AdminLoginAction::AdminLoginAction(), BlogAction::BlogAction(), ResourceServerAction::ResourceServerAction(), SummaryAction::SummaryAction(), UpdateStepThree::UpdateStepThree(), WizardIntro::WizardIntro(), WizardStepFive::WizardStepFive(), WizardStepFour::WizardStepFour(), ¤Î WizardStepOne::WizardStepOne(). 00075 { 00076 $this->Object(); 00077 00078 $this->_request = new Request( $httpRequest ); 00079 00080 $this->_actionInfo = $actionInfo; 00081 00082 $this->_fieldValidators = Array(); 00083 00084 // initialize the views to empty values 00085 $this->_view = null; 00086 $this->_validationErrorView = null; 00087 00088 // form object, used for data validation 00089 $this->_form = new FormValidator(); 00090 00091 // no previous action 00092 $this->_previousAction = null; 00093 00094 // by default, the action is successful 00095 $this->_isSuccess = true; 00096 }
|
|
|
returns the reference to the previous action in the process flow
©w¸q¦b action.class.php Àɮפ§²Ä 115 ¦æ.
|
|
|
This function does not need to be reimplemented by the childs of this class. It just returns the resulting view of the operation.
©w¸q¦b action.class.php Àɮפ§²Ä 246 ¦æ.
|
|
|
|
registers a new field whose value should be available to the view/template in case it needs to be reshown.Those fields that haven't been registered, will *not* be shown when rerunning the view.
©w¸q¦b action.class.php Àɮפ§²Ä 232 ¦æ. ³Q°Ñ¦Ò©ó AdminAddBlogUserAction::AdminAddBlogUserAction(), AdminAddPostAction::AdminAddPostAction(), AdminAddUserAction::AdminAddUserAction(), AdminEditPostAction::AdminEditPostAction(), AdminUpdateBlogSettingsAction::AdminUpdateBlogSettingsAction(), AdminUpdateEditBlogAction::AdminUpdateEditBlogAction(), AdminUpdatePostAction::AdminUpdatePostAction(), AdminUpdateResourceAction::AdminUpdateResourceAction(), AdminUpdateResourceAlbumAction::AdminUpdateResourceAlbumAction(), AdminUpdateUserProfileAction::AdminUpdateUserProfileAction(), AdminUpdateUserSettingsAction::AdminUpdateUserSettingsAction(), ¤Î WizardStepFour::WizardStepFour().
|
|
||||||||||||||||
|
|
we can do things here that are common to all the views. This method must be called just before the Action::perform() method has finished its processing since most of the child Action classes use it to do some kind of post-processing.
¦bAdminAction, BlogAction, ¤Î SummaryAction«·s¹ê§@. ©w¸q¦b action.class.php Àɮפ§²Ä 263 ¦æ. ³Q°Ñ¦Ò©ó UpdateStepThree::perform(), UpdateStepOne::perform(), WizardStepFive::perform(), WizardStepFour::perform(), WizardStepThree::perform(), WizardStepTwo::perform(), WizardStepOne::perform(), WizardIntro::perform(), AdminLoginAction::perform(), ¤Î validationErrorProcessing(). 00264 { 00265 $this->_view->setValue( "form", $this->_form ); 00266 00267 if( $copyFormValues ) { 00268 // in case we'd like to copy the values from the form 00269 $fieldValues = $this->_form->getFieldValues(); 00270 foreach( $fieldValues as $fieldName => $fieldValue ) { 00271 $this->_view->setValue( "$fieldName", $fieldValue ); 00272 } 00273 } 00274 00275 return true; 00276 }
|
|
|
after executing the current action we will not show the results but transfer the execution flow to another action. In other words, the Controller will detect that the processing is being passed to another Action class and instead of calling Action::getView() right after Action::perform() it will call the perform() method of the next action in the flow. It is only possible to specify one action to forward to at a time, but this feature can be used as many times as needed.
©w¸q¦b action.class.php Àɮפ§²Ä 292 ¦æ. °Ñ¦Ò Controller::setForwardAction(). 00293 { 00294 Controller::setForwardAction( $nextActionKey, $this ); 00295 00296 return true; 00297 }
|
|
||||||||||||
|
sets a parameter in the session... or in other words, make it available for the next coming action.
©w¸q¦b action.class.php Àɮפ§²Ä 308 ¦æ.
|
|
|
©w¸q¦b action.class.php Àɮפ§²Ä 104 ¦æ.
|
|
|
This method can be used to trigger validation errors even if they did not really happen, or to disable errors if they happened.
©w¸q¦b action.class.php Àɮפ§²Ä 319 ¦æ.
|
|
|
sets the view that will be shown in case there is an error during the validation process... It makes things a bit easier for us when it comes to validate data. This view will only be used if validate() generates a validation error or if we force the action to generate an error via Action::setSuccess()
©w¸q¦b action.class.php Àɮפ§²Ä 199 ¦æ. ³Q°Ñ¦Ò©ó AddCommentAction::AddCommentAction(), AdminAddArticleCategoryAction::AdminAddArticleCategoryAction(), AdminAddBlogAction::AdminAddBlogAction(), AdminAddBlogUserAction::AdminAddBlogUserAction(), AdminAddCustomFieldAction::AdminAddCustomFieldAction(), AdminAddLinkAction::AdminAddLinkAction(), AdminAddLinkCategoryAction::AdminAddLinkCategoryAction(), AdminAddPostAction::AdminAddPostAction(), AdminAddResourceAction::AdminAddResourceAction(), AdminAddResourceAlbumAction::AdminAddResourceAlbumAction(), AdminAddUserAction::AdminAddUserAction(), AdminDeleteArticleCategoryAction::AdminDeleteArticleCategoryAction(), AdminDeleteBlogAction::AdminDeleteBlogAction(), AdminDeleteBlogTemplateAction::AdminDeleteBlogTemplateAction(), AdminDeleteBlogUserPermissionsAction::AdminDeleteBlogUserPermissionsAction(), AdminDeleteCommentAction::AdminDeleteCommentAction(), AdminDeleteCustomFieldsAction::AdminDeleteCustomFieldsAction(), AdminDeleteGalleryItemsAction::AdminDeleteGalleryItemsAction(), AdminDeleteLinkAction::AdminDeleteLinkAction(), AdminDeleteLinkCategoryAction::AdminDeleteLinkCategoryAction(), AdminDeleteLocalesAction::AdminDeleteLocalesAction(), AdminDeletePostAction::AdminDeletePostAction(), AdminDeleteReferrerAction::AdminDeleteReferrerAction(), AdminDeleteResourceAction::AdminDeleteResourceAction(), AdminDeleteResourceAlbumAction::AdminDeleteResourceAlbumAction(), AdminDeleteTemplatesAction::AdminDeleteTemplatesAction(), AdminDeleteTrackbackAction::AdminDeleteTrackbackAction(), AdminDeleteUsersAction::AdminDeleteUsersAction(), AdminEditArticleCategoryAction::AdminEditArticleCategoryAction(), AdminEditBlogAction::AdminEditBlogAction(), AdminEditCommentsAction::AdminEditCommentsAction(), AdminEditCustomFieldAction::AdminEditCustomFieldAction(), AdminEditLinkAction::AdminEditLinkAction(), AdminEditLinkCategoryAction::AdminEditLinkCategoryAction(), AdminEditLinksAction::AdminEditLinksAction(), AdminEditPostAction::AdminEditPostAction(), AdminEditResourceAlbumAction::AdminEditResourceAlbumAction(), AdminEditTrackbacksAction::AdminEditTrackbacksAction(), AdminLoginAction::AdminLoginAction(), AdminMarkCommentAction::AdminMarkCommentAction(), AdminResourceInfoAction::AdminNewResourceAlbumAction(), AdminPostStatsAction::AdminPostStatsAction(), AdminRegeneratePreviewAction::AdminRegeneratePreviewAction(), AdminResourcesAction::AdminResourcesAction(), AdminUpdateArticleCategoryAction::AdminUpdateArticleCategoryAction(), AdminUpdateBlogSettingsAction::AdminUpdateBlogSettingsAction(), AdminUpdateCustomFieldAction::AdminUpdateCustomFieldAction(), AdminUpdateEditBlogAction::AdminUpdateEditBlogAction(), AdminUpdateLinkAction::AdminUpdateLinkAction(), AdminUpdateLinkCategoryAction::AdminUpdateLinkCategoryAction(), AdminUpdatePostAction::AdminUpdatePostAction(), AdminUpdateResourceAction::AdminUpdateResourceAction(), AdminUpdateResourceAlbumAction::AdminUpdateResourceAlbumAction(), AdminUpdateUserProfileAction::AdminUpdateUserProfileAction(), AdminUpdateUserSettingsAction::AdminUpdateUserSettingsAction(), AdminUserProfileAction::AdminUserProfileAction(), BlogProfileAction::BlogProfileAction(), ChooseBlogTemplateAction::ChooseBlogTemplateAction(), doBlogRegistration::doBlogRegistration(), SearchAction::SearchAction(), SummarySendResetEmail::SummarySendResetEmail(), SummaryUpdatePassword::SummaryUpdatePassword(), TemplateAction::TemplateAction(), UserProfileAction::UserProfileAction(), AdminUpdateResourceAction::validate(), CommentAction::ViewArticleAction(), WizardStepFive::WizardStepFive(), WizardStepFour::WizardStepFour(), ¤Î WizardStepOne::WizardStepOne().
|
|
|
This method can be used for data validation and is always executed before perform(). If it returns 'true', execution will continue as normal. If it returns 'false', the process will be stopped and the current contents of the view will be returned. If the view is empty, an exception will be thrown. As of pLog 1.0, it is not necessary to implement data validation code here and it is recommended to use the data validation framework (see methods Action::registerFieldValidator() and related) There is more information about the data validation framework in the wiki: http://wiki.plogworld.net/index.php/PLog_1.0/Forms_and_data_validation. With the default code provided in the Action::validate() method, the callback method Action::validationErrorProcessing() will be called and after that, the view set via the Action::setValidationErrorView() will be used to generate the contents of the error message.
¦bAddCommentAction, AdminAddBlogTemplateAction, AdminAddLocaleAction, AdminMainAction, AdminNewResourceAction, AdminPostStatsAction, AdminSendTrackbacksAction, AdminUpdateGlobalSettingsAction, AdminUpdateResourceAction, AdminUpdateUserSettingsAction, AdminUserPictureSelectAction, AdminXmlSaveDraftAction, DefaultAction, ResourceServerAction, ViewAlbumAction, ViewArticleAction, ViewArticleTrackbacksAction, ViewResourceAction, SummaryRssAction, SummarySearchAction, SummarySetNewPassword, UpdateStepTwo, ¤Î UpdateStepFour«·s¹ê§@. ©w¸q¦b action.class.php Àɮפ§²Ä 152 ¦æ. °Ñ¦Ò validationErrorProcessing(). ³Q°Ñ¦Ò©ó SummaryCustomPageAction::perform(). 00153 { 00154 // use the FormValidator object to validate the data 00155 $validationOk = $this->_form->validate( $this->_request ); 00156 00157 // if something went wrong... let's do somethinga about it :) 00158 if( !$validationOk ) { 00159 $this->validationErrorProcessing(); 00160 } 00161 00162 return $validationOk; 00163 }
|
|
|
This method will be called when a validation error happens. Child classes are free to extend or reimplement this one and can be used as some sort of a trigger in order to do some cleanup if needed. Ê
¦bAddCommentAction, ¤Î RegisterAction«·s¹ê§@. ©w¸q¦b action.class.php Àɮפ§²Ä 172 ¦æ. °Ñ¦Ò setCommonData(). ³Q°Ñ¦Ò©ó validate(). 00173 { 00174 // if there was a validaton error, then inform the view 00175 $this->_view->setError( true ); 00176 00177 // and export all the data to the view so that it can be reused in the error view 00178 $fieldValues = $this->_form->getFieldValues(); 00179 foreach( $fieldValues as $fieldName => $fieldValue ) { 00180 $this->_view->setValue( "$fieldName", $fieldValue ); 00181 } 00182 00183 $this->_form->setFormIsValid( false ); 00184 $this->setCommonData(); 00185 00186 return true; 00187 }
|
|
|
©w¸q¦b action.class.php Àɮפ§²Ä 62 ¦æ. |
|
|
©w¸q¦b action.class.php Àɮפ§²Ä 63 ¦æ. |
|
|
©w¸q¦b action.class.php Àɮפ§²Ä 66 ¦æ. |
|
|
©w¸q¦b action.class.php Àɮפ§²Ä 65 ¦æ. |
|
|
©w¸q¦b action.class.php Àɮפ§²Ä 61 ¦æ. |
|
|
©w¸q¦b action.class.php Àɮפ§²Ä 64 ¦æ. |
|
|
©w¸q¦b action.class.php Àɮפ§²Ä 60 ¦æ. |