Welcome Guest, Not a member yet? Register   Sign In
Can someone advise what this code snippet does ?

HI - I pulled this out of PyroCMS which is built on CI. I can not see what the point is of these 3 lines of code:

$sample = new stdClass;
  foreach ($this->item_validation_rules as $rule)
   $sample->{$rule['field']} = $this->input->post($rule['field']);

To my eyes, all it appears to do is put the input post into a an empty class as a property ... but so what. It them goes on to use $sample as part of the view,

// Build the view using sample/views/admin/form.php
   ->title($this->module_details['name'], lang('sample.new_item'))
   ->set('sample', $sample)

I am obviously missing something - any ideas ??

Many thanks !


Don't know for sure, but it's creating an object and setting various properties of that object based on some sort of validation rules array. I assume this might be a part of some auto form validation, but never used Pyro so not sure. Makes sense though since it's loading a form.

It might make sense if you look at what template->set('sample', $sample) in reference to the 'admin/form' is doing since that's where it's being passed

Thanks CroNix - I'm impressed you are still around ! Pyro is a great cms AND built on CI .. although for how long who knows as Phil Sturgeon ( the author ) intends to take it to Laravel 4.

Yeah I'm starting to learn L4, but have some clients with large CI sites that won't be upgrading frameworks anytime soon as there isn't an actual need to. So, I'm still around but spreading my wings.

Theme © iAndrew 2016 - Forum software by © MyBB