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

  • SEARCH
  • Home
  • 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 630503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:51:43+00:00 2026-05-13T19:51:43+00:00

In a CMS I’m building I want to have my own javascript namespaced object

  • 0

In a CMS I’m building I want to have my own javascript namespaced object $cms. This object should have a method/function hasIdentity that returns the status of whether the user is logged in.

Is there a way that I can have this method/function return the status without having to resort to either:

  • AJAX
  • a global var
  • or rewriting the following script from within PHP

This is what I have so var:

var $cms = {
    hasIdentity: function()
    {
        return /* the status provided by PHP */;
    }
};

It’s a bit of a esthetic matter perhaps, but I don’t want to resort to this:

// write this global var;
var $isLoggedIn = false;

var $cms = {
    hasIdentity: function()
    {
        return $isLoggedIn;
    }
};

Or this:

var $cms = {
    hasIdentity: function()
    {
        $isLoggedIn = this.do.some.ajax.call();
        return $isLoggedIn;
    }
};

I was maybe thinking more of a sort of OOP approach, something like constructing the $cms object by writing it from within PHP:

<script type="text/javascript">
  $cms = new $cms( <?php echo $loggedIn ? 'true', 'false' ?> );
</script>

Now, I believe I can’t use the new keyword like that in Javascript, but I hope you catch my drift, and see where I want to go with this.

  • 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-05-13T19:51:43+00:00Added an answer on May 13, 2026 at 7:51 pm

    You could also do:

    $cms.isLoggedIn = <?php echo $loggedIn ? 'true', 'false' ?>;
    

    That because your $cms object is not a constructor function. If it were, you would have been able to new it.

    var CMS = function (loggedIn) {
        this.loggedIn = loggedIn;
    };
    
    CMS.prototype.hasIdentity = function () {
        return this.loggedIn;
    };
    
    $cms = new CMS(<?php echo $loggedIn ? 'true', 'false' ?>);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a CMS in PHP and one dread I have is that the
I have a CMS system that stores data across tables like this: Entries Table
I'm building a CMS in ASP.NET MVC and want to allow users to pick
I have text I am displaying in SIlverlight that is coming from a CMS
When I disable cms.middleware.multilingual.MultilingualURLMiddleware I have Caught an exception while rendering 'WSGIRequest' object has
I'm building a CMS-type webapp that allows users to enter arbitrary-sized blocks of HTML.
I'm writing a CMS application in PHP and one of the requirements is that
We're building a CMS. The site will be built and managed by the users
In our CMS, we have a place in which we enable users to play
I'm creating a cms and have not yet settled on the matter of where

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.