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

[eluser]vincej[/eluser]
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:

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,

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

I am obviously missing something - any ideas ??

Many thanks !

#2

[eluser]CroNiX[/eluser]
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.
#3

[eluser]CroNiX[/eluser]
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
#4

[eluser]vincej[/eluser]
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.
#5

[eluser]CroNiX[/eluser]
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