1

I wanted to incorporate GUMP https://github.com/Wixel/GUMP into my Slim rest framework.

I am looking to intercept a GET or POST request before validating it with GUMP before continuing to process. Could anyone provide a brief snippet of code how to do this as I was unable to figure it out using middleware (server is on php 5.2).

thanks

4

1 回答 1

4

为什么不使用这样的东西:

$rules = array(
  'username'    => 'required|alpha_numeric|max_len,100|min_len,6',
  'password'    => 'required|max_len,100|min_len,6',
  'email'       => 'required|valid_email',
  'gender'      => 'required|exact_len,1',
  'credit_card' => 'trim|valid_cc',
);
$filters = array(
  'username'    => 'trim|sanitize_string',
  'password'    => 'trim|base64',
  'email'       => 'trim|sanitize_email',
  'gender'      => 'trim',
  'bio'         => 'noise_words'
);
//now get $post data and validate
$post = $app->request()->post(); // $app - Slim main app instance
$validated = $gump->validate( $gump->filter($post, $filters), $rules );
于 2012-03-02T11:06:28.373 回答