Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorsuthern
     

    How do I call functions from AkRouter in a controller? I'm specifically interested in the toUrl and toParams ones. Thanks!

    • CommentAuthorKaste
     

    hm, in a controller

    $this->urlFor(...);
    
    • CommentAuthorsuthern
     

    Ok, here's what I'm trying to accomplish: A filter dropdown which refreshes the page with the selected filter when it is selected from a drop-down list. My controller is called 'part', and my action is 'edit_accounts'. The three allowed parameters (what I want to use to filter by) are called category, account_type, and account_name. Actually, only 'category' filters the 'part's table. The other two are to automatically fill the values of a form for checkbox selection, so all three need to refresh the page when selected.

    What I've done is found some javascript code to put in the <select onclick=""> which refreshes the page based on the value inside the 'value' argument of the selected <option>. Because the code needs a URL, I have to create the url somehow.

    To create the url needed, I'd like do something like this for each <option>: $Router->toUrl(array_merge( $Router->toParams("/".$this->params['ak']) , array('$FILTER_NAME' => $filter_value) ) ). Then stick that resulting URL in XX <option value="XX" >filter_value</option> Ok, so array_merge is not correct, but it should show that I'm trying to refresh the page with the selected $filter_name with the $filter_value from the current URL.

    Yes, I wrote my own <select> handler to handle <select> options AND <option> options, so I'm good to go there (an update you may consider for core Akelos, unless it already has this feature hidden somewhere). What I need help with is where to stick this function to collect data for my <select> generating function so it has access to the $AkRouter->toParams function, or at least of proxy of said function. How would you go about it? Thanks for the shared time!

    • CommentAuthorsuthern
     

    Here's my form_select code: (which doesn't handle $html_options)

    function form_select($id, $name, $ops = array(), $select_options = array(), $ops_options = array(), $selected = FALSE) { $s = '<select id="'.$id.'_'.$name.'" name="'.$id.'['.$name.']" '; foreach($select_options AS $k => $v) { $s .= $k.'="'.$v.'" '; } $s .='>'; $d1 = array_keys($ops); $is_flat = (is_numeric($d1[0]))? TRUE : FALSE; foreach($ops AS $k => $v){ $s .= '<option '.(($selected && $selected==$v)? 'selected ':''); foreach($ops_options AS $k2 => $v2) { $s .= $k2.'="'.$v2.'" '; } $s .= 'value="'.(($is_flat)?$v:$k).'">'.$v.'</option>'; } $s .= "</select>"; return $s; }

    • CommentAuthorsuthern
     

    Ok, I solved it. It was simpler then I thought! I didn't need to use toParams. All I needed to do was collect the existing array keys from $this->params, and swap the needed key out for the new url. ;-)