You are inserting an empty array before declaring it. Move the insert_query method below the actual declaration of the $mynews_insert_data_sql array and it will work.
I'd advise you to create the array directly and assign a neater name to it, in order to save a few memory when running the script.
function mynews_insert_data(&$handler)
{
global $mybb, $db;
if ($mybb->input['mynews_choose'] == 1) {
$data = array(
"topic" => $db->escape_string($mybb->input['subject']),
"cover" => $db->escape_string($mybb->input['mynews_cover']),
"tid" => $handler->data['tid']
);
$db->insert_query("mynews_topic", $data);
}
}
(2014-12-14, 02:52 PM)Shade Wrote: [ -> ]You are inserting an empty array before declaring it. Move the insert_query method below the actual declaration of the $mynews_insert_data_sql array and it will work.
I'd advise you to create the array directly and assign a neater name to it, in order to save a few memory when running the script.
function mynews_insert_data(&$handler)
{
global $mybb, $db;
if ($mybb->input['mynews_choose'] == 1) {
$data = array(
"topic" => $db->escape_string($mybb->input['subject']),
"cover" => $db->escape_string($mybb->input['mynews_cover']),
"tid" => $handler->data['tid']
);
$db->insert_query("mynews_topic", $data);
}
}
Ohhh yess, your are right! I forgot to declare the array before to send it ahahah Anyway, the tid field remains empty!
Try debugging with the method I explained above, checking the entire $handler object. Then you can see the exact hierarchy the tid is in.
(2014-12-14, 03:04 PM)Shade Wrote: [ -> ]Try debugging with the method I explained above, checking the entire $handler object. Then you can see the exact hierarchy the tid is in.
Ok, I never tried to debug using this code.. Could help me step by step?
For example, should I write something like this?
function my_debug($mynews_insert_data_sql)
{
echo "<pre>";
print_r($mynews_insert_data_sql);
echo "</pre>";
exit;
}
If yes, then what should I do?
Ok, I solved the debug problem. Look, it says me:
Array
(
[topic] => adadada
[cover] => adada
[tid] =>
)
So, the tid field is empty!
(2014-12-14, 06:12 PM)Rakes Wrote: [ -> ] (2014-12-14, 03:40 PM)Clear Wrote: [ -> ] (2014-12-14, 03:33 PM)Rakes Wrote: [ -> ]Use https://github.com/mybb/mybb/blob/21c269....php#L1718 then
How should I use it?
Uhm, you use that hook instead of the one you're using at the moment?
Ahh ok, because they have different name (add_hook and run_hook).. Ok, I try now!
It says me:
Cannot pass parameter 2 by reference in C:\xampp\htdocs\mybb\inc\plugins\mynews.php on line 33
(2014-12-14, 06:30 PM)Clear Wrote: [ -> ]Ahh ok, because they have different name (add_hook and run_hook).. Ok, I try now!
What?
run_hooks = the definition of the hook which makes it available for developers
add_hook = executng your code in an available hook
(2014-12-14, 06:30 PM)Clear Wrote: [ -> ]Cannot pass parameter 2 by reference in C:\xampp\htdocs\mybb\inc\plugins\mynews.php on line 33
As the error says, you can't pass 2nd parameter of the function by reference. Can't tell more without seeing the line...
(2014-12-14, 08:47 PM)Destroy666 Wrote: [ -> ] (2014-12-14, 06:30 PM)Clear Wrote: [ -> ]Ahh ok, because they have different name (add_hook and run_hook).. Ok, I try now!
What?
run_hooks = the definition of the hook which makes it available for developers
add_hook = executng your code in an available hook
(2014-12-14, 06:30 PM)Clear Wrote: [ -> ]Cannot pass parameter 2 by reference in C:\xampp\htdocs\mybb\inc\plugins\mynews.php on line 33
As the error says, you can't pass 2nd parameter of the function by reference. Can't tell more without seeing the line...
The function is the following:
function mynews_insert_data(&$handler) {
global $mybb, $db;
if($mybb->input['mynews_choose'] == 1) {
$subject_topic = $mybb->input['subject'];
$mynews_cover = $mybb->input['mynews_cover'];
$mynews_insert_data_sql = array(
"topic" => $db->escape_string($subject_topic),
"cover" => $db->escape_string($mynews_cover),
"tid" => $handler->data['tid']
);
$db->insert_query("mynews_topic", $mynews_insert_data_sql);
my_debug($mynews_insert_data_sql);
}
}
Should the 2nd parameter be "cover" => $mynews_cover?
The line 33 is the following:
$plugins->run_hooks('datahandler_post_insert_thread_end', 'mynews_insert_data');