Image upload in pages

edited May 2012 in Modules
Is there a work around for the problems mentioned in this topic: http://www.getfuelcms.com/forums/discussion/comment/2799/#Comment_2799

I have the same issues. How do other people do it when they want the customer to be able to upload images when they create pages in the admin.

Another question that I have. Is it possible to have the same option of choosing a picture like in you can do in a model when you use fields that end with image?

Comments

  • edited 1:43PM
    Try the following in your MY_fuel_layouts layout:
    ... 'file' => array(), 'file_upload' => array('type' => 'file') ...
    For the second question, you can use the class "asset_select" in your form field like so:
    $fields['my_image']['class'] = 'asset_select';
    To have the images select from a different folder you can do the following
    $fields['my_image']['class'] = 'asset_select images/blog';
  • edited 1:43PM
    Thanks for the answer. I still have some questions though.
    If I use $file in my layout than it the picture shows up even if the page was saved with an empty upload field, because the picture name remains in the file field.
    However the problem with inline editing is not resolved. If I use
    fuel_var('file_upload','')
    then I can still not upload a new picture from within inline editing mode. Maybe I understood you wrong.

    Where do I put the:
    $fields['my_image']['class'] = 'asset_select';
    Also in the MY_fuel_layout? Because that did not work for me.

    Then the last question.. If I try to upload an image from another folder than the assets folder I get the error "The filetype you are attempting to upload is not allowed." The assets map is writable. What could this mean?
  • edited 1:43PM
    Lets say that a page that a customer adds has a left 'side-block'. In this side-block I want the customer to be able to add multiple pictures with some text and a link (different per page). If I would create this page myself I would use a simple module and use the fuel_edit('create'......... method to let the costumer be able to add a picture.

    This is not possible with a page that is created via the admin. How could I do this? Can you combine models with pages that are created in the admin?
    By the way. Every side-block should be able to be different per page.
  • edited 1:43PM
    Could you add the side-block module logic to your layout file or include it in a block that is used in your layout file?
  • edited 1:43PM
    Well I do not know how. How can I add an extra picture inline to a page that is created in the page module?
    Because these pages have a fixed amount of input fields as defined in MY_fuel_layouts.php they are 'static' in a way that it is never possible to make something where you do not know how much pictures someone is going to upload?
  • edited 1:43PM
    You may want to try creating a field type of "multi" and then provide it the options of the images in your side-block simple module in you MY_fuel_layouts file like so:
    ... $options = array(); if (defined('FUEL_ADMIN')){ $CI =& get_instance(); $options = $CI->drop_down_lists_model->options_list(); } $config['layout_fields']['main']['my_images'] = array('type' => 'multi', 'options' => $options, 'class' => 'add_edit side_block');
    All the managing and uploading is done in your side-block simple module outside of the pages module. In the pages module, you are just associating the images for that page.

    I realize this may not be ideal. However, we will have a much better solution for this in the next release.
  • edited 1:43PM
    Thanks.
    I changed my approach a little. This is what I am doing know. I have my simple module and I added an extra column to the table. This extra column contains the page name of the page (the body_var) when you create a page in the admin.

    I added an on_before_save() hook:
    function on_before_save() { $data = array( 'page' => 'test' ); $this->db->insert('test_banner_rechts', $data); }
    What I want is to dynamically insert the body_class in the table. So if you are the a page projects than I want to add 'projects' to my column called page. My problem is that I don't how I could send the body_class, which is available in the view off course, to the on_before_save hook.
    Is this possible at all?
  • edited 1:43PM
    Okay here I am again. I found a solution for my problem. I don't think it is a pretty solution but it works.
    I use session control to store the $body_var variable in the view so that the model can use this session variable. This is the same solution as in http://www.getfuelcms.com/forums/discussion/722 .

    This works fine. But I hope another solution is available some time?
    Now I can add content via a simple module with fueledit('create'. Adding pictures is also not a problem. BUT when I try to change a picture nothing happens. I know that the model is loaded when I click the button but after that nothing happens. This is my code in the view:
    $this->session->set_userdata('test_session', $body_class); $CI =& get_instance(); $model_name = 'test_banner_rechts_model'; $tabel_name = 'test_banner_rechts'; $CI->load->model($model_name); $CI->$model_name->set_page_variable($body_class); $kolom = $CI->$model_name->find_all(array('page' => $body_class), 'page desc'); echo fuel_edit('create', 'Voeg een plaatje toe', $tabel_name);?> <?php foreach ($kolom as $value) : ?> <?php echo fuel_edit($value->id, 'Pas het plaatje aan', $tabel_name); ?> <div class="banner"><h2><?php echo $value->titel ?></h2> <img src="<?php echo $this->asset->img_path('banner/'.$value->image); ?>" alt="" /> <a href="<?php echo $value->link ?>"> <?php echo $value->linktext ?> </a> </div> <?php endforeach ?>

    So my question is Admin do you know a way around this bug?
  • edited 1:43PM
    I'm sorry but I don't know of one at the moment. I believe we have an easier solution in place in the next version which I realize does you no good at the moment and I'm sorry about that. The solution will be that you can pass initialization parameters like so:
    fuel_edit('create|body_class=myval', 'Create', 'test_banner_rechts')?>
    We are still working out some bugs and documentation but need to find some time to wrap things up and release it as a beta.
  • edited 1:43PM
    I have a problem with this example for latest version
    rotate the gripper but anyway I'm looking for opportunities to select from a list of assets for a particular page
    any idea
  • edited 1:43PM
    ha I found in another post http://getfuelcms.com/forums/discussion/comment/168/#Comment_168
    'header_image' => array ('description' => 'Header Image', 'class' => 'asset_select images', 'upload_path' => assets_server_path ('', 'images')), 'header_upload_image' => array ('type' => 'file', 'description' => 'Header Image'),
  • edited 1:43PM
    Back again. Thanks so much for the fuel update!! I have been reading the new user guide and it looks very good!!

    I have also been looking at the new fuel_edit but I do not see what you mentioned. There is one sentence: "Alternatively, you can now also just pass the entire object and it will generate the id, label, module and published values automatically". But this is not clear to me.
    My question is (how) can I pass initialization parameters?
  • edited 1:43PM
    For example, say we had a model called widgets and we wanted to iterate over an array of widget objects and display them along with an edit pencil icon. Before we had to do something like this:
    <?php $widgets = fuel_model('widgets'); ?> <ul> <?php foreach($widgets as $widget) : ?> <li> <?=fuel_edit($widget->id, 'Edit Widget:'.$widget->name, 'widgets')?> <?=$widget->name?>: <?=$widget->description?> </li> <?php endforeach;?>
    Now you can just do the following:
    <?php $widgets = fuel_model('widgets'); ?> <ul> <?php foreach($widgets as $widget) : ?> <li> <?=fuel_edit($widget)?> <?=$widget->name?>: <?=$widget->description?> </li> <?php endforeach;?>
Sign In or Register to comment.