Announcement

Collapse
No announcement yet.

Class 'vB_Api_Extensions' not found

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Class 'vB_Api_Extensions' not found

    Hello,
    I have another one and I need your help.
    I created a mode for my forum (vb5). I used ajax to transfer data from outside to core/packages/helloworld/api/page.php
    PHP Code:
      <?php  
    class helloworld_Api_Page extends vB_Api_Extensions  
    {  
    public 
    $product 'helloworld';  
    public 
    $version '1.0.0';  
    public 
    $developer 'Bkav';  
    public 
    $title 'New Home';  
    public 
    $minver '5.1.5';  
    public 
    $maxver '5.9.99';  
    public 
    $infourl '';  
    public 
    $checkurl '';  
    public 
    $AutoInstall 0;  
    public 
    $extensionOrder 5;    
    public function 
    fetchPageById($page$pageid$routeData = array())  
    {          
    if(isset(
    $_POST['page']))        
    {                
    echo 
    "return";          
     }        
    page['hwWorld'] = $strReturn;            r
    eturn $page
    ;  
    }
     }
    ?>
    The ajax I used:
    Code:
    $(document).ready(function(){
     $("a#pagetab").live("click",function(){
      
     var fid=$(this).attr("rel");
      
     var p=$(this).attr("data");
     var rs = $.ajax({
                    url: "core/packages/helloworld/api/page.php",
                    type: "POST",
                    data: { forumid:fid, page:p },
                    dataType: "html",
                    beforeSend: function () {
                        $("div.active").html("<img src='modnews/images/gif-load.gif'/> Loading...");
                    }
                });
            rs.done(function(data){
                $("div.active").html(data);
            });  
     }); });
    And the result I got:
    HTML Code:
    <br /> <b>Fatal error</b>: Class 'vB_Api_Extensions' not found in <b>/var/www/betawhitehat/core/packages/helloworld/api/page.php</b> on line <b>7</b><br />
    Can you help me solve this?
    Do your best, the rest will come

  • #2
    You should post about this over on vbulletin.org, the modification site, in their Programming forum.

    Please don't PM or VM me for support - I only help out in the threads.
    vBulletin Manual & vBulletin 4.0 Code Documentation (API)
    Want help modifying your vbulletin forum? Head on over to vbulletin.org
    If I post CSS and you don't know where it goes, throw it into the additional.css template.

    W3Schools &lt;- awesome site for html/css help

    Comment


    • #3
      I don't think you can call an extension api in ajax like that.

      What you can do is create a frontend controller that you can call via ajax.

      Save this in /includes/vb5/frontend/controller/helloworld.php

      PHP Code:
      class vB5_Frontend_Controller_HelloWorld extends vB5_Frontend_Controller
      {
          public function 
      actionSayHello()
          {
              
      //you can call any api method here, for example:
              
      $api Api_InterfaceAbstract::instance();
              
      $data = array(
                  
      'userid' => $_POST['userid']
              );
              
      $result $api->callApi('user''fetchProfileInfo'$data);
              if (!empty(
      $result) AND empty($result['errors'])) {
                  return 
      'Hello world, ' $result['username'] . '!';
              }
              return 
      'Hello world!';
          }



      Then call via ajax:

      Code:
      $.ajax({
          url: vBulletin.getAjaxBaseurl() + '/helloworld/sayhello',
          type: "POST",
          data: { userid: 1 },
          success: function(response) {
              alert(response);
          }
      });
      Or you can call an api method directly via ajax:

      Code:
      $.ajax({
          url: vBulletin.getAjaxBaseurl() + '/ajax/api/user/fetchUserInfo',
          type: "POST",
          data: { userid: 1 },
          dataType: 'json',
          success: function(response) {
              if (response && !response['errors']) {
                  alert('Hello world, ' + response['username'] + '!');
              }
              else {
                  alert('Hello world!');
              }
          }
      });
      The codes above are not tested but you get the idea.

      GIPHY for vB5 AutoLinker Auto-Create Flag Report Topic Social Icons in Postbit Clear Cache Cron DragDrop Upload Topic AJAX AutoUpdate Custom Avatars Selector Stop Links in Posts...and more!

      Comment

      Related Topics

      Collapse

      Working...
      X