0

In one of these php frameworks I've noticed a posibility to request the object Request in action as $this->request->paramName

class MyRequest extends Zend_Controller_Request_Http{

    public $params = array();

    public function __construct() {
        $this->params = $this->getParams();
        parent::__construct();
    }

    public function __get($name) {
        if (isset($this->_params[$name])) {
            return $this->_params[$name];
        } 
    }

    public function __isset($name) {
        return isset($this->_params[$name]);
    }

}

in MyController I've added variable request

public $request = null;

How can I change that standart Request to my one?

public function __construct(
    Zend_Controller_Request_Abstract $request,
    Zend_Controller_Response_Abstract $response,
    array $invokeArgs = array()) {
        $request = new MyRequest();
        parent::__construct($request, $response, $invokeArgs);
        $this->request = $this->getRequest();
    }
  • This function has given no results.

Option 1 is make method _initRequest() in bootstrap:

protected function _initRequest() {
    $this->bootstrap ( 'FrontController' );
    $front = $this->getResource ( 'FrontController' );
    $request = $front->getRequest ();
    if (null === $front->getRequest ()) {
        $request = new MyRequest();
        $front->setRequest ( $request );
    }
    return $request;
}
1
  • the constructor belongs to class MyController Commented Feb 22, 2012 at 12:26

2 Answers 2

1

A bit dirty and untested solution. Would love to hear if it works.

//Bootstrap:

public function _initRequest()
{
    $this->bootstrap('frontController');
    $front = $this->getResource('frontController');
    $front->setRequest(new MyRequest());
}
Sign up to request clarification or add additional context in comments.

1 Comment

I was thinking about this option, I do not really like it
0

Try this it might help you:

in controller file

public function exampleAction(){   
    $result = $this->_request;

    $model  = new Employer_Model_JobInfo();        
    $results = $model->sample($result);
}

// the above line stores the values sent from the client side in $result.then sends that values to Model file with parameter $result   ..

in model file

class Employer_Model_JobInfo extends Gears_Db_Table_Abstract{
    public function sample($param){

        $paramVal       = $param->getParam('name');
        $paramVal1       = $param->getParam('email');

    }
}

The name and email are what name used to sent the data from client to server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.