Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have been working on a magento module for sometime now (not because it is a large module, its my first and I really struggled with it). I now have it working, which I was really pleased with at first, but now I would like to improve it by increasing the reusability of the code.

While making my module I have looked at other modules to learn from them and have seen that many actions are only a line or two and I have tried keeping in with the skinny controller approach but failed, my example is as follows:

I have a function that get a users details that they have inputted into a custom form

protected function _setPostData()
{        
    $this->_salutation = $this->getRequest()->getPost('salutation');
    $this->_f_name = $this->getRequest()->getPost('f_name');
    $this->_l_name = $this->getRequest()->getPost('l_name');
    $this->_email = $this->getRequest()->getPost('email');
    $this->_emailAddressCheck = $this->getRequest()->getPost('emailAddressCheck');
    $this->_gender = $this->getRequest()->getPost('gender');
    $this->_country = $this->getRequest()->getPost('country');
    $this->_pref_lang = $this->getRequest()->getPost('pref_lang');        
}

I feel that this is not the correct way to do it and that there is a better way of achieving the same goal, as you can see this function gets the posts data and assigns it to attributes that i've set at the start of the class. I have several other examples that are very similar to the above and if someone could please offer some guidance on this one I am sure I will be able to work out the others

This example is held within the index action, should I put it in a helper as once it created correctly i am sure there will be a few occasions that I will be able to use it again?

share|improve this question
Why the close votes? This sounds more like a design recommendation then "code to be written". – mnhg Aug 16 at 8:07
I'm not familiar with Magento. Is there no Form component that encapsulate all the form-request-validation-stuff? Just as a example not a recommendation Synfony Forms – mnhg Aug 16 at 8:11

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.