Imitating Page Variable Structure

Hi!

I have a multilingual site with a gallery module that I am making. Because I need to store gallery data (gallery item name, description, etc.) in multiple languages, I am trying to imitate the pages/page variables structure that FUEL has by default. I've managed to get it to work on the backend, but now I am having trouble joining the gallery data with the galleryvariables data on the frontend.

$vars['display'] = fuel_model('gallery', array('find'=>'one', 'where'=>'slug=\''.$detail.'\''));

For instance, when I call this on the frontend, it only outputs only the data from the gallery table, missing the info from galleryvariables (analogous to pages / pagevariables).

I took a look at the Fuel_pages_model and noticed this class at the end:

class Fuel_page_model extends Base_module_record {

    function get_variables($language = NULL)
    {
        $params =array();
        if (!empty($language))
        {
            $params['where'] = array('language' => $language);
        }
        return $this->lazy_load(array('page_id' => $this->id), array(FUEL_FOLDER => 'fuel_pages_model'), TRUE, $params);
    }
}

Is this the class that does what I am trying to do (join the main data with the variable data)?

When I add a method like this to the end of my gallery_model file, I get an unspecified error on the front end, and when I do a var_dump on the $vars['display'] object (above) I get an infinitely long array of object data.

This is how I tried to do it (really just a shot in the dark because at this point it's all over my head):

class Galler_model extends Base_module_record {

    function get_variables($language = NULL)
    {
        $params =array();
        if (!empty($language))
        {
            $params['where'] = array('language' => $language);
        }
        return $this->lazy_load(array('gallery_id' => $this->id), 'galleryvariables_model', TRUE, $params);
    }
}

I named this Galler_model because I noticed in the Fuel_pages_model that the class which extends Base_module_model is Fuel_pages_model and the class that extends Base_module_record is Fuel_page_model (differing by only 1 letter). If I name it something else, like Gallerys_model, then nothing happens on the front end, so I assume I am doing something significant.

Am I getting warm? Any help is very much appreciated. Where should I look to learn how to join the gallery data and the gallery variable data?

Thank you!!!

Comments

  • For modules, you can add a varchar field called "language" to your module and query your front end results based on the language being viewed. There will then also be a dropdown select in the admin for you to filter the languages.

  • So the actual solution is a lot simpler than what I was trying to do by imitating the pages/pagevariables models?
    I actually got my method to work on the backend. I'm just having trouble getting access to the galleryvariables data.
    But if your suggestion is the best way and it won't require too much restructuring, then I'll try that.

    Thanks!

  • For simple modules, it just becomes a where condition on your model call since it's just a table. The Pages module has a different table structure and so it operates a bit differently.

  • Thanks! I was really overthinking here. :sweat:

  • I just finished merging my gallery and galleryvariables tables and restructuring my model code. It's much cleaner now, so I'm happy with it. But there's still one issue:

    FUEL automagically populates the "language" VARCHAR field with the languages I've set up, but it does not let me edit a single item across different languages like it does in pages.

    In pages, when you change the language, the following script runs and updates the fields with the pagevariables in the appropriate language (this is why I originally tried to imitate pages/pagevariables):

    $('#language').change(function(e){ $.changeChecksaveValue('#language', $(this).val()); window.location = jqx.config.fuelPath + '/gallery/edit/' + $('#id').val() + '?lang=' + $('#language').val(); });

    Then the model handles updating the variables.

    Now in my gallery module, it simply overwrites any existing data with the changes and changes the language from one to the other.

    What can I do about this? Do I have to create a different record for each item in a different language?

    Thanks!

  • edited May 2018

    And a second issue has come up too, since doing this, my serialized field for a series of images is giving me a compilation error. Any idea what I did wrong? On the backend, the serialized field looks fine (it's displaying images and everything), and in the DB it looks OK too:

    Compilation error at line 343 in "string:" : Parse error in ":"gallery\/hidges-an-exploration-of-art-and-language\/zach_wellstood_hidges_chapbook_1-2.png","caption":""},{"image":"gallery\/hidges-an-exploration-of-art-and-language\/zach_wellstood_hidges_chapbook_1-3.png","caption":""},{"image":"gallery\/hidges-an-exploration-of-art-and-language\/zach_wellstood_hidges_chapbook_1-4.png","caption":""}] [cat_id] => 3
    
    [layout] => series [published] => yes [featured] => 0 [tags] => [language] => en ) 1
    
  • For a simple module, each language version has it's own record.

    The pages module does something similar but with the fuel_pagevariables table (each language has it's own set of page variables associated with it). When you go to create a page with a different language, it prefills the input values with the values of the default language if it has those values saved. That page's language values aren't saved though until you click save.

    If you wanted to prefill in your input values with a default language's values when creating a new record, you can create a new method that does this and then specify a new edit_method on your module's model (the default value is the find_one_array method) and map to it in your MY_fuel_modules.php config file:

    'edit_method' => 'my_find_one_array',
    

    Regarding the Compilation error, that usually happens when the Dwoo template parse find {} brackets in your HTML. If you add a space after the opening bracket, it won't try and parse what's between the {}.

  • edited May 2018

    Great, I think that solves the issue with languages in the module. Thank you so much!

    The compilation error is being thrown when I try to output my serialized field data. If I output $serialized_field['series'][0] I get [, $serialized_field['series'][1] outputs { etc, and if I try to use it as an object, I get an error saying it's not an object. Is there something about the serialization method that's preventing it from being parsed correctly?

    I realized that my fuel_model()is returning an array instead of an object. Could this be the issue? If so, where could I fix that? Thanks in advance for helping with this headache. :blush:

  • Nevermind! Thanks to this post https://forum.getfuelcms.com/discussion/1508/fuel-model-has-many-no-object-data
    I figured it out. I did not declare class Gallery_model extends Base_module_record {

    Whoops!

Sign In or Register to comment.