Hello,

Earlier I converted all my "Base" controllers to action helpers (thanks,
Matthew), except for one.
I still have CrudController which basicly has create/read/update/delete
actions and lot's of event methods.

I also found the old CrudController slides from Matthew (any updates coming
to this Matthew?):
http://weierophinney.net/matthew/uploads/2007-02-28-FrameworkPresentation.pdf

This makes the same thing, it's just a bit old.

I'll include some of my CrufController methods below.

Any comments/feedback or suggestions would be great!

br, Marko

protected function _setForm()
{

        // load the form and creates it
}

protected function _processForm($data = array())
{
        $this->_alterForm(); // Event

//processing + event calls here and there
}

// Gets the name of the Model we are creating/reading/updating/deleting
protected function _getModel()
{
        return $this->_request->getModuleName();
}

// Do something when empty row is created in createAction()
protected function _onRowCreation()
{

}

// Alter the form somehow (my forms are loaded from ini files and then
altered if needed)
protected function _alterForm()
{

}

// After form is altered you can still do something like set some element
values
protected function _alterFormPostProcess()
{

}

// Do something before form validation starts 
protected function _onBeforeValidation(array $post)
{
        return $post;
}

// Do something after form validation succeeded
protected function _onValidationSucceed(array $post)
{
        return $post;
}

// Do something if form was not valid
protected function _onValidationFailed(array $post)
{
        return $post;
}

// Do something just before when saving the row
protected function _onBeforeSave()
{
        return true;
}

// Do something just before deleting the row
protected function _onBeforeDelete()
{
        return true;
}

// Do something just after row has been saved
protected function _onSave()
{

}

// Do something after all saving and other stuff have been made
protected function _onSaveComplete()
{
        if ($this->_request->isXmlHttpRequest())
        {
                $this->_helper->json(array("redirect" => 
$this->_getRedirectOnSave()));
        }
        else
        {
                // Redirect to the next page
                $this->_redirect($this->_getRedirectOnSave(), 
array("prependBase" =>
false));
        }
}

// Get the redirect url after save > normally goes to readAction
protected function _getRedirectOnSave()
{
        if ($this->_hasParam("redirect_url"))
        {
                return $this->_getParam("redirect_url",
$this->getFrontController()->getBaseUrl());
        }
        else
        {
                return $this->getFrontController()->getBaseUrl();
        }
}

// Get the redirect url after delete
protected function _getRedirectOnDelete(array $data)
{
        return $this->getFrontController()->getBaseUrl();
}

// Gets the form section name for the ini file [user_form]
protected function _getFormName()
{
        return "{$this->_request->getModuleName()}_form";
}
-- 
View this message in context: 
http://www.nabble.com/CrudController-vs.-Action-helpers-tp22470068p22470068.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to