Moodle2.6 link constructor error

Moodle2.6 link constructor error

by Ivana Skelic -
Number of replies: 1

Hi,

I'm using link code example from Moodle Output API documentation to create link on my page, but I'm getting constructor error.

This example

$link = new action_link();
$link->url = new moodle_url('http://domain.com/index.php', array('id' => 2, 'action' => 'browse')); // required, but you can use a string instead
$link->text = 'Browse page 2'; // Required
echo $OUTPUT->link($link)

looks like this in my case:

$link = new action_link();
$link->url = new moodle_url('/mod/book/tool/validator/bcindex.php', array('id' => $book->id, 'chapterid' => $chapter->id));
$link->text = 'validate chapter'; // Required

And it gives me the following error:

Coding error detected, it must be fixed by a programmer: PHP catchable fatal error

Debug info: Argument 1 passed to action_link::__construct() must be an instance of moodle_url, none given, called in [dirroot]/mod/book/tool/validator/bindex.php on line 89 and defined
Error code: codingerror
Stack trace:
  • line 393 of /lib/setuplib.php: coding_exception thrown
  • line 952 of /lib/outputcomponents.php: call to default_error_handler()
  • line 89 of /mod/book/tool/validator/bindex.php: call to action_link->__construct()

 

And if I use this example:

$link = html_link::make(new moodle_url('http://domain.com/index.php', array('id' => 2, 'action' => 'browse')), 'Browse page 2');

I get the following error:

Fatal error: Class 'html_link' not found in /Applications/MAMP/htdocs/moodle/mod/book/tool/validator/bindex.php on line 92

Any help would be appreciated, thanks!

 

Average of ratings: -
In reply to Ivana Skelic

Re: Moodle2.6 link constructor error

by Itamar Tzadok -

The docs you are referring to may be outdated.

You can output an action link directly, e.g.:

$nonpopuplink = $rating->get_view_ratings_url();
$popuplink = $rating->get_view_ratings_url(true);
$popupaction = new popup_action('click', $popuplink, 'ratings', array('height' => 400, 'width' => 600));
                
return $OUTPUT->action_link($nonpopuplink, 'view all', $popupaction);

 

or construct with the required arguments. e.g.:

$url = !empty($options['baseurl']) ? $options['baseurl'] : $PAGE->url;
$str = get_string('multiduplicate', 'dataform');
$actionlink = new action_menu_link($url, new pix_icon('t/copy', $str), $str, true, array('id' => 'id_entry_bulkaction_duplicate'));

return $OUTPUT->render($actionlink);

 

And using the html_writer, e.g:

$editpermlink = html_writer::link(new moodle_url('/admin/roles/permissions.php', $params), $OUTPUT->pix_icon('i/edit', get_string('edit')));

hth smile

Average of ratings: Useful (2)