Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8908485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:11:30+00:00 2026-06-15T03:11:30+00:00

I am trying to integrate Backbone in Yii and therefore I need REST. So

  • 0

I am trying to integrate Backbone in Yii and therefore I need REST. So I installed a Yii extension, restfullyii, which makes use of a username and password that need to be passed to requests. The problem is that I have no idea how to do this with Backbone.

Example of wanted request:

List
curl -i -H "Accept: application/json" -H "X_REST_USERNAME: admin@restuser" -H "X_REST_PASSWORD: admin@Access" http://yii-tester.local/api/sample/    
curl -i -H "Accept: application/json" -H "X_REST_USERNAME: admin@restuser" -H "X_REST_PASSWORD: admin@Access" http://yii-tester.local/api/sample/limit/1
curl -i -H "Accept: application/json" -H "X_REST_USERNAME: admin@restuser" -H "X_REST_PASSWORD: admin@Access" http://yii-tester.local/api/sample/limit/10/5 (limit/offeset)

Current error response, which totally makes sense..:

{
    "success": false,
    "message": "You are not authorized to proform this action.",
    "data": {"errorCode":500}
}

Does anyone have a clue how to send such values throughout Backbone?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:11:32+00:00Added an answer on June 15, 2026 at 3:11 am

    Backbone delegates its XHR requests to jQuery/Zepto, that’s what you will have to modify.

    The easiest solution is probably to provide defaults options via $.ajaxSetup and the headers options

    headers(added 1.5)
    Default: {}

    A map of additional header key/value pairs to send along with the
    request. This setting is set before the beforeSend function is called;
    therefore, any values in the headers setting can be overwritten from
    within the beforeSend function.

    You would set it like this:

    $.ajaxSetup({
        headers:{
            X_REST_USERNAME: "admin@restuser",
            X_REST_PASSWORD: "admin@Access"
        }
    });
    

    Every request sent will have the custom headers. See http://jsfiddle.net/nikoshr/j5Rr4/

    Or you could pass additional options to each requests, Backbone will forward them to jQuery:

    var m = new Backbone.Model();   
    m.fetch({
        headers:{
            X_REST_USERNAME: "admin@restuser",
            X_REST_PASSWORD: "admin@Access"
        }
    });
    

    http://jsfiddle.net/nikoshr/j5Rr4/2/

    Finally, you could override Backbone.sync to add the headers for every request:

    Backbone.realsync = Backbone.sync;
    Backbone.sync = function(method, model, options) {
        options || (options = {});
        options.headers = {
            X_REST_USERNAME: "admin@restuser",
            X_REST_PASSWORD: "admin@Access"
        };
    
        return Backbone.realsync.call(model, method, model, options);
    };
    
    var m = new Backbone.Model();
    m.fetch();
    

    http://jsfiddle.net/nikoshr/j5Rr4/4/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to integrate backbone.js as the frontend framework for my rails app. I
I am trying to integrate Pusher with my web application that uses backbone.js. I'm
I'm trying to integrate two Fortran 9x codes which contain data arrays with opposite
I have been trying to integrate unit testing with my Backbone models through an
Im trying to integrate prosody xmpp server with my rails application. I need to
I'm trying to integrate a google visualisation chart into my backbone.js app. Currently I
I have created a webapp using backbone.js and I am trying to integrate google
Im trying to integrate phpgrid with my codeigniter program. I need a few clarifications
I'm brand new to Backbone.js, and I'm trying to integrate it into my current
Im trying to integrate Brad Larson's GPUImage framework to my project. The sample code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.