Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Controllers vs an Advanced Module

edited July 2011 in Modules
Thanks in advance for responding to what is undoubtedly obvious if you've done it before ...

I have a series of huge forms which are not going to be friendly if auto-created by fuel -- to put it in perspective, one of them will populate 70 checkboxes using an imagemap and a slug of javascript to keep it sane... -- I count 10 rather complex forms and then I'm going to need to check and save the data.

Up until now, everything has been in simple modules and I've successfully let Fuel generate the edit forms. Conceptually, nothing here goes beyond the simple module concept, but I'm not finding answers in any of the available examples.

I suspect I'm struggling with "boundaries" between CI and Fuel. I'm trying to do something that was easily done with one controller, one model, and multiple views in CI 1 + BackendPro.

I easily get the controller within the Fuel application to execute a "got there" , but I don't seem to then be able to load a model that follows the Fuel specifications -- I get Fatal error: Class 'Base_module_model' not found in \application\models\plants_model.php on line should I be heading for basic CI and ignoring FUEL for this?

If so, can I get to my Fuel views/blocks/layouts? Can I still get to Fuel check to see if my user is logged in validly? I'd clearly like to use Fuel's validation enhancements. Possible?

I'm suspecting that I just need to know something basic that I'm failing to find in the Fuel focused on simplifying by not needing a controllers, but at this point, I'm fairly sure I need one or several, and I'm truly confused about how to integrate Fuel with standard CI controllers.

Thanks for putting up with me.



  • edited 3:03PM
    No worries.. If you are needing your own special controllers and views to create parts of your admin area, I'd recommend using an "advanced module". The FUEL main module and blog are nothing more then an "advanced module" (think of it as it's own application directory). I'd recommend looking at any of the fuel/modules/ folders to get ideas as a place to start and then post back with any questions.

    With regards to that Fatal error, make sure you include the Base_module_model file like so in your model at the top:
  • edited 3:03PM
    Thanks -- belatedly.

    I went the "controller" route and it is working with one exception and I'm hoping you may have a clue. And if you tell me I should have created a model -- I'll hear the "I told you so" and go do it.

    I use form_builder, I use a model constructed exactly the same as the it would be had I let fuel handle the whole process. I look at the generated form code, it looks good to my eye. Form fields of all types work except images -- but I never get an uploaded image (I verified by immediately getting the posted variables and doing an r_print on them before any other processing of the form happens -- I get everything else). I tried loading the edit view with and without 'render_mode'=>'cms' and it made no difference.

    The form generator code:

    $id = uri_segment(3);
    $plants = fuel_model('plants', array ( 'limit'=>1, 'where'=> array('id'=>$id), 'order'=>'scientific'));
    $plant = current($plants);
    $vars['plant_id'] =$plant_id = $plant->id;
    $vars['scientific'] = $plant->scientific;
    $this->load->library('form_builder', array('id'=>'plant_photo_edit_form','form_attrs'=>array('method'=>'post','action'=>'plants/updatephoto'),'submit_value' => 'Submit Changes', 'textarea_rows' => '5'));

    $upload_path = assets_server_path('images/plants', 'images');

    $fields['photo_image'] = array('label' => 'File', 'type'=>'file','class'=>'required', 'upload_path' => $upload_path, 'required' => TRUE, 'overwrite' => TRUE);

    $fields['photographer'] = array('label' => 'Photographer','class'=>'required');
    $fields['caption'] = array('label' => 'Caption', 'type'=>'text');
    $fields['priority'] = array('label' => 'Priority', 'value'=>'100');
    $fields['published'] = array('label' => 'Published?','type'=>'enum','options' => ARRAY('yes' => 'yes', 'no' => 'no'),'value'=>'yes' );
    $fields['plant_id'] = array ('type' => 'hidden', 'value' => $plant_id);
    $fields['id'] = array ('type' => 'hidden', 'value' => $id);

    #Set any other defaults -- anything coming straight from the DB was already set
    $vars['form'] = $this->form_builder->render($fields,'table');
    $vars['messages'] = '';

    $page_init = array('location' => 'plants/editphoto');
    $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init);
    Below: the results of the r_print and the ultimate upchuck by My_Model that the "photo_image" does not exist

    Array ( [photo_image_overwrite] => 1 [photo_image_path] => C:/xampp/htdocs/assets/images/images/plants [photographer] => Test [caption] => [priority] => 100 [published] => yes [Submit_Changes] => Submit Changes [plant_id] => 1 [id] => 1 )

    Fatal error: Uncaught exception 'Exception' with message 'property photo_image does not exist.' in C:\xampp\htdocs\fuel\application\core\MY_Model.php:2916 Stack trace: #0 C:\xampp\htdocs\fuel\application\controllers\plants.php(421): Data_record->__set('photo_image', false) #1 [internal function]: Plants->updatephoto() #2 C:\xampp\htdocs\fuel\codeigniter\core\CodeIgniter.php(318): call_user_func_array(Array, Array) #3 C:\xampp\htdocs\index.php(236): require_once('C:\xampp\htdocs...') #4 {main} thrown in C:\xampp\htdocs\fuel\application\core\MY_Model.php on line 2916
    A few other tests lead me to suspect that something in the processing before control gets to my controller code is stripping the 'photo_image'. One of my tests involved turning off xss but I thought it was already off, and possibly I was turning it off the wrong way?

    Again, thanks.
  • edited 3:03PM
    That error is actually from the model side when it is getting saved saying that the record doesn't have a field named "photo_image" to save to. How is that information being saved (or did I miss it above)?
  • edited July 2011
    You missed it. Or misunderstood the problem. The model can't save what the controller never gets.

    photo_image is a form field -- and the form html looks right, including the additional image-related fields that fuel generates

    The browser does properly allow browsing for an image -- but

    photo_image never makes it to plants/updatephoto

    Somewhere between the form and the controller function updatephoto, photo_image goes into never-never land.

    (note the r_print of the post variables received by plants/updatephoto -- it gets every field except photo_image)
  • edited 3:03PM
    I think it has to do with the fact that it's a file tand does not go into the $_POST global variable but instead goes into the $_FILES global variable. What happens if you an on_after_post hook on the model and do a print_r on $_FILES?
  • edited 3:03PM
    Thank you!

    That was definitely the problem. I struggle so much trying to learn "object oriented" and use CI that I forget basic PHP!
Sign In or Register to comment.