I'm trying to pass a POST variable to one of my controllers, however I'm doing this from a static page (I know, not the cleanest and most efficient way to go about things. But for the sake of learning...). How can I read that POST variable in my controller if the POST data is being sent without a FormHelper form?
I'm posting the data using jQuery ajax, so this is without the CakePHP native "FormHelper".
Does this make sense? Let me know if I need to elaborate. I appreciate any help you can provide :)
You should be able to access the data with:
$this->params['form']['YOUR_VARIABLE_NAME']
And if you follow the naming convention used by the FormHelper and name your input field like data[ModelName][FieldName]
, then you can access the data as usual with:
$this->data['ModelName']['FieldName']
Don't forget Cake is just PHP.
class BazController extends AppController {
function foo() {
$foo = $_POST['bar'];
$this->set('foobar', $foo);
}
}
is perfectly valid. But I would do as @dhofstet suggests as it's much more "cakey".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With