Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using Tabbed Interface for User Profile
  • I know that this is by far probably the easiest question to answer but I am having a difficulty. 

    I want to use tabbed panel with the first tab saying 'Overview' which display the action_view method and then I would like to display 'Update Profile' tab which will display action_edit which renders _form. I did get it to appear on different tabs in few different ways but I could not update the profile information in any way I tried. In the end, I realized that I wasn't calling the action_edit method and was just simply displaying the form instead. 

    Here is the code written completely in HTML, I am in process of converting this template into PHP thus my difficulty


    I know that you could just call it by the href or maybe id but I could not get anything like that to work. However I have seen other use config type of settings to call on each part but I never really knew how to do that, or grasp how it was done. 

    Thank you again in advance for your help! :)
  • When working in tabs you need to display all tabs in one call or use Ajax and a REST call to populate that tab. But the easies way is all tabs in one call.

    All tabs do are hide the information <div> until someone clicks on the tab.  And then hides the other tab and makes visible the one that is active,




  • I did have it display all tabs in one call by displaying the files but that didn't work out because I have a _form.php that both create.php and edit.php uses and I didn't quite know how to exclude the files that I didn't want. 
  • Afaik it works exactly the same as any other view.

    <div class="tabs">
        <div class="tab tab1">
            <?php echo render('my/tab1/_form.php'); ?>
        </div>
        <div class="tab tab2 hidden">
            <?php echo render('my/tab2/_form.php'); ?>
        </div>
        <div class="tab tab3 hidden">
            <?php echo render('my/tab3/_form.php'); ?>
        </div>
    </div>

    or something along those lines.
  • On another subject.....

    I know that is the example that comes as default  _form.php.  But it means you either need to pass through vars from the action to the form or make the vars global.

    Personally I don't use the create.php/update.php (or whatever it was).

    I just have this little piece of code at the top of my forms.

    <?php
    $form_url = '/admin/documents/' . $action . '/';
    if (isset($document) && $document->id != null) {
        $form_url = $form_url . $document->id;
    }
    ?>

    I set a var $action in the controller to know how to built the form action.


  • The example comes from oil, which generates it, so there's a single view with the form for both create and edit, and code doesn't need to be replicated. It does indeed require the main view to pass data on to the _form view (I personally never use global data).

    I would have that code in a Viewmodel, not in the view itself (ideally, a view should not contain logic).
  • My idea is the same.  Even less code.
    I have one form.   And I have one file called form.php.

    I use the same view file for both inserts or updates.  (not included)

    I simply pass an $action variable that sets the forms post url.

    As in $url = '/controller/' . $action

    I usually also check for an $id of some type for an update and either attach that to the end of the url or in a hidden input.

    Yes there is a tiny bit of logic in there that could be moved to a Model View that would build that POST url etc.

  • Agreed.

    And from a Fuel perspective, the logic in the "create" and "update" views should indeed be in a Viewmodel, which then uses a single form view.

    For v2, we'll probably go for the same approach as for fieldsets, where you have "renderers" (which here would be "generators") that you can plugin, to allow you to generate the exact code you want.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion