Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Two doubts, hmvc and pagination
  • Using this:
    $ params = Request :: forge ('some / route') -> set_method ('POST'); Can I send a $_POST to another controller by HMVC? If yes, how? I do not quite understand the use of it. How to pass parameters to a paging for to search? Session or $ _GET? Examples? Sorry my english! Thanks!
  • You pass parameters to an HMVC request using the parameter of the execute method:
    $params = Request::forge('some / route') ->set_method ('POST')->execute(array('myparam' => 'value'));
    

    If your HMVC controller method has to work both in direct requests and HMVC calls, than you currently have to work around that because the Input class has a global context at the moment, there is no $_POST per request.
  • Thanks!!
  • I'm just playing around with Fuel at the moment to get a feel for it. Working through modules / hmvc at the moment. My question is relevant to this topic. The params solution you suggest, (posting the params within the execute method) how does that work? As far as I can tell, this simply passes arguments to the sub-controller method, in which case why is there a field as well as a value in your example? I.e.
    public function action_index()
    {
     // fetch the output of a controller
     $widget = Request::forge('user')->set_method('GET')->execute(array('myparam' => 'value'));
    
     echo $widget;
    }
    

    And then on the sub-controller side:
    public function action_index()
    {
     var_dump(Request::active()->params());
     var_dump(Input::get());
     var_dump(func_get_args());
    }
    

    The only var_dump() that has any data is func_get_args(), so arguments of that method (with no field, only a value, of course).
    I'm guessing this isn't going to work for me, as I want to pass HTTP variables to the sub-controller as davi suggested. What would be the best way of doing this? Would it be to wrap the hmvc/Request::forge call into a class that has a method to accept the forge arguments, plus my specified HTTP vars for the sub-controller - and then within the class grab all the parent HTTP vars, set the specified HTTP vars, then reset the parent vars after the request has completed? Seems a bit hacky but would work. Is there any better way? Thanks
    PS. formatting control JS doesn't work in this forum.
  • You should be able to fetch those parameters using
    $this->param('fieldname');
    

    As to your next question, most of the FuelPHP classes at the moment have a static interface, which means they work globally. Which is a bad idea for some of them. We started working on that, Uri is already a request level class, but we still need to deal with Input. So at the moment there are no request level HTTP vars, and not easy to hack around as it involves making Input objects. It's on the roadmap for the next release (after 1.4 which is due this week).
  • Ok, will give that a go. If altered the http method super global (e.g. $_GET) before the request, would the input class not pick this up? As that could be a workaround for now?
  • No, the Input class hydrates and (optionally) sanitizes the input on first use, later calls will not access the global anymore.
  • Ah right. Hmm - then do you have any suggestions? Is there a dev version I could use perhaps? Or will I need to hack this together myself until 1.5 / 2 is out?
  • No, not yet. There are some other structural changes we want to implement for 1.5, we want to implement those first before we start making code changes, to avoid all sorts of merge issues. So if you need it now, you'll have to deal with it yourself. Alternatively, fix it in the core and send a pull request, so we don't have to...
  • Harro Verton wrote on Monday 5th of November 2012:
    You should be able to fetch those parameters using
    $this->param('fieldname');
    

    Ok - that doesn't work. Using the latest stable build. Code to request:
    $widget = Request::forge('community/user')->set_method('GET')->execute(array('myparam' => 'value'));
    

    And in community/user:
    var_dump($this->param('myparam'));
    
  • Harro Verton wrote on Monday 5th of November 2012:
    No, the Input class hydrates and (optionally) sanitizes the input on first use, later calls will not access the global anymore.

    Actually in my tests it seems to work. E.g.
    $_GET['tomato'] = 2;
    
    // fetch the output of a controller
    $widget = Request::forge('community/user')->execute();
    

    Then in community/user:
    var_dump(Input::get());
    

    Outputs
    array
    'tomato' => int 2 As a result I'll just use the method I mentioned above as a workaround until the release of 2.0. If I do end up finding/fixing anything, i'll be sure to contribute.
  • But probably only because it's the first call to get() ?
  • Harro Verton wrote on Tuesday 6th of November 2012:
    But probably only because it's the first call to get() ?

    Hmm nope, it is working on subsequent calls

Howdy, Stranger!

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

In this Discussion