Announcement

Collapse
No announcement yet.

Class 'vB_Api_Extensions' not found

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

  • Glenn Vergara
    replied
    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.

    Leave a comment:


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

    Leave a comment:


  • hienntp
    started a topic Class 'vB_Api_Extensions' not found

    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?

Related Topics

Collapse

Working...
X