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 650417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:03:02+00:00 2026-05-13T22:03:02+00:00

I have a subscription link on a page that the logged in users can

  • 0

I have a subscription link on a page that the logged in users can use.

Toggling the link on the page is no issue, as I can do a .post and echo out what the PHP returns

if ($subscription == true) {
  echo 'Subscribed';
} else {
  echo 'Click to subscribe';
}

However, what bugs me is that I have to write that same piece of code in my template file. I could however make an ajax call for that immediately as the page loads.

What is the best way of doing 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-13T22:03:03+00:00Added an answer on May 13, 2026 at 10:03 pm

    Okay I decided to fix it using PHP. Now when you hit the page it calls for :

    http://url/module/controller/check/id/$id/object/$object_name

    and ajax’d it into my div. Then if its clicked it goes to and puts the return value in the html

    http://url/module/controller/toggle/id/$id/object/$object_name

    Class:

    <?php
    
    
    class User_SubscriptionController extends Zend_Controller_Action {
    
    
    function init() {
        $contextSwitch  = $this->_helper->getHelper('ForceContext');
        $userSess       = new Zend_Session_Namespace('User');
        $this->user     = $userSess->model;
    
        $this->id           = $this->_getParam('id');
        $this->object_name  = $this->_getParam('object');
    
        if (empty($this->id) || empty($this->object_name)) {
            throw new exception('Id and Object name must be passed');
        }
    
    }
    
    
    public function checkAction() {
    
        $subscription = Eurocreme_Baseclass::load_by_fields(array('object_name' => $this->object_name, 'object_id' => $this->id, 'user_id' => $this->user->id, 'table_name' => 'Subscription'), 1);
    
        if (is_object($subscription)) {
            echo 'Click To Un-Susbscribe';
        } else {
            echo 'Click To Subscribe';
        }
        exit;
    }
    
    
    public function toggleAction() {
    
        $subscription = Eurocreme_Baseclass::load_by_fields(array('object_name' => $this->object_name, 'object_id' => $this->id, 'user_id' => $this->user->id, 'table_name' => 'Subscription'), 1);
    
        if (is_object($subscription)) {
            $subscription->delete();
        } else {
            $subscription = Eurocreme_Baseclass::create(array('object_name' => $this->object_name, 'object_id' => $this->id, 'user_id' => $this->user->id, 'table_name' => 'Subscription', 'frequency' => 1));
        }
    
        $this->checkAction();
    }
    

    }

    and the view code is:

    <?php $this->headScript()->captureStart(); ?>
    $('document').ready(function() { 
    
        $.get('/user/subscription/check/id/<?php echo $this->object->id; ?>/object/Movie', function(data) {
            $('#subscription_link').html(data);
        });
    
        $("#subscription_link").click(function(){
            $.get('/user/subscription/toggle/id/<?php echo $this->object->id; ?>/object/Movie', function(data) {
                $('#subscription_link').html(data);
            });
            return true;
        });
    
    
    }); 
    <?php $this->headScript()->captureEnd(); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application with set limits on subscription attributes i/e a user can
I have an MSDN subscription and I'm wondering what edition of Visual Studio 2008
I'm just a one-man software shop, and I currently have an MSDN subscription. It
I have created a one-time subscription in SSRS report manager 2008. However I keep
Have a n-tire web application and search often times out after 30 secs. How
I have several SSRS '08 reports that look great when viewed as a web
When you submit the newsletter subscription form (subscribe.phtml), the form actions aclls a php
Can you cancel a PayPal automatic payment via API? It's a Subscription created via
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could

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.