PHP-Zend
PHP-Zend

Reputation: 311

calling a different action in the same controller

I'm developing a small app. using php and Zend Framework. I have a form, and I use it's controller to view the form. Now I need to manipulate the form data and redirect the user accordingly. here is my controller

<?php

class NewuserController extends Zend_Controller_Action {

public function init()
{
    /* Initialize action controller here */
}

public function newuserAction()
{
    $this->view->newuser;
}

public function adduserAction(){

    $data = $this->getRequest()->getParams();
    $u = new User();
    $u->setUserName($data['uName']);
    $u->setPrepwd($data['pwd']);
    $u->setPrepwd($data['pwd']);
    if($u->isEqual()){
        $val = $u->addUsers();
        if($val)
            $this->_helper->redirector('main','main');
    }
    else
        $this->_helper->redirector('newuser','newuser');


}
}

?>

my view is newuser.phtml. In the action attributr of the <form> I have specified Newuser/adduser . But when I submit the form it again displays the newuser.phtml.

Why is this?

Thanks in advance

Charu

Upvotes: 1

Views: 83

Answers (2)

Veronica
Veronica

Reputation: 11

I would suggest that you use the redirector helper instead of the foward because if you want the user to be redirected to the main page with foward it will redirect but it won't change the url so if they were to bookmark the page for example it wont work. If you use the redirector it will redirect and change the url to show just your main phtml page. Also if you are in the same controller its not necessary to include the second param which is the controller. Check this out for more help

http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.redirector

Upvotes: 1

Florent
Florent

Reputation: 12420

You can forward the request instead of redirecting:

$this->_forward('newuser');

Upvotes: 1

Related Questions