Getting current threadid to insert into db

Status
Not open for further replies.

Mikey

:mikey:
Staff member
Jan 26, 2008
17,836
692
510
33
Disunited Queendom
mikeylicio.us
I have a add on which I am building, which inserts threads into the database with a short (user defined) description, and I'll figure out how to display them later.

Anyway, I need a way to insert the threadid into the database into my table.

I've tried;

PHP:
public function actionAddYes() {
        $db = XenForo_Application::get('db');
        $visitor = XenForo_Visitor::getInstance();
        $userid = $visitor['user_id'];
        $blurb = $this->_input->cleanString($_POST['blurb']);
        // $date = XenForo_Application::get('time'); <- not working - if anyone could suggest an alternate, i'd appreciate that also
        $threadid = $this->get('thread_id');
        $db->query("INSERT INTO `xf_Mikey` (`threadid`, `userid`, `date`, `blurb`) VALUES ('$threadid', '$userid', '$date' '$blurb');");
		return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS);
    }

Note, what I know I've learnt from reading the development forums or through reading other people's code.

Anyway, that doesnt work, I get this: Fatal error: Call to undefined method Mikey_ControllerPublic_Index::get() in /var/www/sites/xenfor:wave:library/Mikey/ControllerPublic/Index.php on line 33


Note; i've also posted this over at xenforo.com - so feel free to reply here or there :p

Any help will be appreciated :)
 
Oct 6, 2010
105
9
225
32
Well, first of get() is a member of the DataWriter class, so you won't be able to call it via $this-> in a controller. And secondly, I'm a bit confused. Are you attempting to create a thread based on what they posted? If you are doing this when you do a thread (via the DataWriter of course) you could use getMergedData() from the DataWriter class to return an array that would have the thread_id in it. It is extremely late... and I'm working on a very small amount of sleep, so I may be off.
 
  • Like
Reactions: 1 person

Mikey

:mikey:
Staff member
Jan 26, 2008
17,836
692
510
33
Disunited Queendom
mikeylicio.us
Here's the scenario;

User clicks button on thread to 'favourite' it (opens in overlay), the thread is then put into the favourites table with their userid, the threadid (which I need), the date it was 'favourited', and a short description, like this;

2010-12-07-07h29_11.png
 
Oct 6, 2010
105
9
225
32
Ooooh. Well then, that is probably easier than I thought. Construct your link with a parameter of the thread ID (should be available via $thread?). Then in your action / route pull that out and send it as a valid PHP set up. :) That's how I'd accomplish it.
 

Cezz

OMG Member
Sep 24, 2010
581
48
255
36
United Kingdom
What's your prefix and action that is occurring?

I worked this out with him on IRC :D...

For everyone else, the key parts of passing any vars to anther page is having them in the URI, your match and buildLink functions in the Route Prefix class need to take into consideration the variables you want passed. And you should link to the pages using {xen:link} and not by directly typing the URL.

Once you have the variable in the URL you should then be able to access it using the input function... EG. $this->_input->filterSingle('thread_id', XenForo_Input::INT);
 
  • Like
Reactions: 1 person
Status
Not open for further replies.