magento 1.7 - How to use a helper -


i creating module allows user input details form , save details allow relevant information forwarded them @ specified times.

to retrieve details form , add them database followed tutorial , produced code

    public function saveaction() {     $title = $this->getrequest()->getpost('title');     $f_name = $this->getrequest()->getpost('f_name');     $l_name = $this->getrequest()->getpost('l_name');     if ( isset($title) && ($title != '') && isset($f_name) && ($f_name != '') && isset($l_name) && ($l_name != '') ) {         $contact = mage::getmodel('prefcentre/prefcentre');         $contact->setdata('title', $title);         $contact->setdata('f_name', $f_name);         $contact->setdata('l_name', $l_name);         $contact->save();         $this->_redirect('prefcentre/index/emailpreferences');     } else {         $this->_redirect('prefcentre/index/signup');     } } 

the tutorial says put controller in saveaction, , works fine. limited understanding go in helper , i'd call helper controller

i placed above code in helper , called within saveaction using following

mage::helper('module/helpername');//returned blank screen , did not save 

i tried

mage::helper('module/helpername_function');//returned error 

my config has

<helpers>     <prefcentre>         <class>ps_prefcentre_helper</class>     </prefcentre> </helpers> 

1 . should code go in helper, if not should go?

2 . how call helper(or location code need go) utilise code?

1 . should code go in helper, if not should go?

the actual code posted imo predestinated used within controller action because realizes specific process flow: user data specific case -> save if applicable -> redirect.

secondly, helper imo never should control route dispatching. it's helper, not controller.

i fail see use case putting method helper give advantages.

2 . how call helper(or location code need go) utilise code?

your definition uses <prefcentre> alias, if did setup helper magento standard way , using file app/code/local/ps/prefcentre/helper/data.php, helper methods callable this:

mage::helper('prefcentre')->mymethodname(); 

Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -