1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

using GetHelper inside of a model?

Discussion in 'XenForo Development Discussions' started by Jaxel, Nov 20, 2010.

  1. Jaxel

    Jaxel Well-Known Member

    I am trying to use the following code:
    $ftpHelper = $this->getHelper('ForumThreadPost');
    $forum = $ftpHelper->assertForumValidAndViewable($options->EWRmedio_autoforum);
    $forumId = $forum['node_id'];
    However, it appears that getHelper is not a valid function in models; only in controllers. How would I do what I'm trying to do here inside of a model?
  2. Jaxel

    Jaxel Well-Known Member

    Okay... I decided to just use this:
    if (!$forum = $this->getModelFromCache('XenForo_Model_Forum')->getForumById('2'));
    	print_r($forum); exit;
    However, I'm having an issue with this... for some reason this code ALWAYS validates. It prints the $forum array info, and then exits. If $forum is getting retrieved properly, it shouldn't validate and the script should move on...
        [node_id] => 2
        [title] => Main Forum
        [description] =>
        [node_name] =>
        [node_type_id] => Forum
        [parent_node_id] => 1
        [display_order] => 1
        [display_in_list] => 1
        [lft] => 2
        [rgt] => 3
        [depth] => 1
        [style_id] => 0
        [effective_style_id] => 0
        [discussion_count] => 3
        [message_count] => 4
        [last_post_id] => 4
        [last_post_date] => 1289528456
        [last_post_user_id] => 2
        [last_post_username] => Digital Doctor
        [last_thread_title] => Lorem ipsum dolor sit amet
  3. Jaxel

    Jaxel Well-Known Member

    woops... i see the issue... random semicolons...
    SneakyDave likes this.
  4. Jeremy

    Jeremy Well-Known Member

    As soon as you said that it jumped out... oops. haha.
  5. Robust

    Robust Well-Known Member

    Are there any other ways of using the ForumThreadPost ControllerHelper in a model?
  6. Daniel Hood

    Daniel Hood Well-Known Member

    Might be able to do something like;

    $frontController XenForo_Application::get('fc');
    $fakeController = new XenForo_ControllerPublic_Index($frontController->getRequest(), $frontController->getResponse(), $frontController->route());
    $helper $fakeController->getHelper('ForumThreadPost');
    Completely untested.
    shri, Robust and SneakyDave like this.

Share This Page