Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-9644

new class 'moodle_url'

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.9
    • None
    • Libraries
    • None
    • MOODLE_19_STABLE

    Description

      Does it make sense to have a new class moodle_url in weblib.php to handle constructing a url. It would internally stores params as an array and have methods to manipulate the array. The class could output the params as hidden fields in a form or as a url with get params appended. This is functionality that is needed all over moodle and some code encapsulated in a class might help? Could be also passed to the constructor of formslib.

      I'm updating the question code to get rid of the dependence on session vars to store params used in the page and I'd like to write a class like this and put it in weblib.php. Was thinking of moving methods like below out of listlib.php into a class that could then be used as a param for methods of the listlib class and elsewhere. Will also add a method to ouput the params as hidden form elements for buttons. And also to process a url string and break it down into an array of params and a url.

      Also could we have a global var. $FULLMEOBJ which is $FULLME but as moodle_url object with params so you can use methods to output $ME or $FULLME and easily manipulate the params for the page to override some of them, add params, remove params etc.

      /**

      • Add an array of params to the params for this page.
        *
      • @param array $params
        */
        function add_page_params($params) { $this->pageparams = $params + $this->pageparams; }

      /**

      • Get url and query string for an action on this page (get_url() + sesskey)
        *
      • @param array $overrideparams an array of params which override $this->pageparams
      • @return string
        */
        function get_action_url($overrideparams = array()){
        global $USER;

      $arr = array();
      $paramarray = $overrideparams + $this->pageparams + array('sesskey'=>$USER->sesskey);
      foreach ($paramarray as $key => $val)

      { $arr[] = urlencode($key)."=".urlencode($val); }
      $params = implode($arr, "&");

      return $this->pageurl.'?'.$params;
      }

      /**
      * Get url and query string for this page
      *
      * @param array $overrideparams an array of params which override $this->pageparams
      * @return string
      */
      function get_url($overrideparams = array()){

      $arr = array();
      $paramarray = $overrideparams + $this->pageparams;
      foreach ($paramarray as $key => $val){ $arr[] = urlencode($key)."=".urlencode($val); }

      $params = implode($arr, "&");

      return $this->pageurl.'?'.$params;
      }

      Attachments

        Issue Links

          Activity

            People

              jamiesensei Jamie Pratt
              jamiesensei Jamie Pratt
              Nobody Nobody
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: