PHP Catchable error?

PHP Catchable error?

autor Kevin Burton -
Počet odpovědí: 7

I recently upgraded to 2.6 and I got an error indicating that print_table could not be use and I should use html_writer::table instead. So I replace my call to print_table($table) with 'echo html_writer::table($table)'. Now I am getting an error indicating the there was a PHP cachable exception. What else has changed?

Thank you.

Průměr hodnocení: -
V odpovědi na Kevin Burton

Re: PHP Catchable error?

autor Paul Holden -
Obrázek: Core developers Obrázek: Moodle HQ Obrázek: Moodle Workplace team Obrázek: Particularly helpful Moodlers Obrázek: Peer reviewers Obrázek: Plugin developers Obrázek: Testers

You would reduce a lot of guesswork on the part of other forum users, and increase your chances of getting relevant help if you enabled developer debugging and posted the stacktrace from that exception mrknout

V odpovědi na Paul Holden

Re: PHP Catchable error?

autor Kevin Burton -

I am so new that I didn't know this was available. Thank you.

I have attached the debug output. There seems to be more wrong than just a single call. For upgrading do I go to deprecated.php and replace the single method call with all of the code in the deprecated function? For example get_context_instance() is in deprecated.php and there are about 10 lines of code that supposedly replace this function. Do I just copy and paste these lines? The same with print_header()? As far as the errors for $PAGE->context and setType() there must be something new that I am not doing? I have also attached the php that I am using in my module. The last error indicates that $table must be of type html_table. But I could find where $table is created. Also it indicates that require_login() is not called. As you can see from the source it is being called.

 

 

 

Příloha error1.jpg
Příloha error2.jpg
Příloha error3.jpg
V odpovědi na Kevin Burton

Re: PHP Catchable error?

autor Kevin Burton -

Ok, I only get debug messages about setting a capability (which is odd because acess.php has the capabiliity) and the last error which has a problem with calling html_writer::table(). Any ideas?

V odpovědi na Kevin Burton

Re: PHP Catchable error?

autor Davo Smith -
Obrázek: Core developers Obrázek: Particularly helpful Moodlers Obrázek: Peer reviewers Obrázek: Plugin developers

You will need to rewrite your code to generate a html_table object to pass into the html_writer::table() function call. 

The definition of html_table can be found in lib/outputcomponents.php - the comments in there explain exactly what each bit of the object is for, and there are numerous examples in the rest of the Moodle code.

The get_context_instance calls can be fairly safely ignored for the moment, but if you want to fix them (and this will probably need to be done before Moodle 2.7, as I guess they might become errors at that point) - convert them to the appropriate context_XX:instance($id) calls.

e.g.

get_context_instance($courseid, CONTEXT_COURSE) => context_course::instance($courseid);

get_context_instance($cmid, CONTEXT_MODULE) => context_module::instance($cmid);

(and similarly for CONTEXT_COURSECAT, CONTEXT_SYSTEM, CONTEXT_USER, CONTEXT_BLOCK)

It's not completely clear whether you were the original author of this 'mediasite' module you are seeing the error in - if you are not, then you may find it worth contacting the original author to see if they have upgraded it to work with Moodle 2.6. Alternatively, you might be able to find a developer who can do the upgrade for you.

V odpovědi na Davo Smith

Re: PHP Catchable error?

autor Kevin Burton -

That is the thing I don't think the code in my module is creating $table.  What would creating an html_table involve? 

I got rid of the error/warning for get_context_instance doing just what you suggested. Thank you.

I am not the original author. The original author left a long time ago. I have just inherited it.

V odpovědi na Kevin Burton

Re: PHP Catchable error?

autor Davo Smith -
Obrázek: Core developers Obrázek: Particularly helpful Moodlers Obrázek: Peer reviewers Obrázek: Plugin developers

Previously the code used print_table - so clearly it was trying to output some sort of table.

The correct way of doing this in Moodle 2.6 is to create an html_table object (I've outlined above where you can find the details of what to put in it - it would take a long time to write out a complete tutorial to using it properly here) and then pass it into html_writer::table($table);

Alternatively, you could rewrite the code to remove the table completely, but that is up to you (this forum is for offering help, not really for writing all the code for you!)

V odpovědi na Davo Smith

Re: PHP Catchable error?

autor Kevin Burton -

It turns out that PHP was trying to do too much for me. I had

if(count($results) > 0) {
foreach($results as $result) {
$table->data[] = get_result_item($result, $data->resourcetype, $selectlabel);
    }
}

Since $table didn't exist $table->data[] caused $table to be created as a stdClass. I changed this to

$table = new html_table();
if(count($results) > 0) {
foreach($results as $result) {
$table->data[] = get_result_item($result, $data->resourcetype, $selectlabel);
    }
}

And all is well. (Notice the addition of the explicit constructor for html_table.) Thank you.