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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:08:02+00:00 2026-06-12T04:08:02+00:00

I am Using the Zend Framework. As a design pattern i am using the

  • 0

I am Using the Zend Framework.
As a design pattern i am using the state design pattern.

Now as you may know, Zend Framework let’s you create custom controllers, which can be used to respond to Ajax requests.
In my example i have the following ajax request

    function getResponse(name){
        $.ajax({
            dataType: 'json',
            data: {button: name},
            url: 'motor/ajaxtest',
            type: 'post',
            success: function(response)
            {
            }
        });
    }

The function getResponse is called every time a specific button is pressed.

public function ajaxtestAction()
{
    $input_in = $this->getRequest()->getParam('button');

    $Lok = new Lok();
    $this->_helper->viewRenderer->setNoRender();

    $text = array($Lok->getMotorState());
    $phpNative = Zend_Json::encode($text);
    echo $phpNative;
}

The Code above is my custom response to the ajax request. I want to pass on the name of the pressed button to $Lok = new Lok(); so i can use it in the “Lok” model Class without creating a new instance of The controller in the “Lok” class

Is there anyone who might be able to help me ?

EDIT———————————–

Here’s my Controller :

class MotorController extends Zend_Controller_Action
{
public function init()
{
}

public function indexAction() 
{ 
}

public function ajaxtestAction()
{
    $input_in = array($this->getRequest()->getParam('button'));
    $phpNativ1 = Zend_Json::encode($input_in);
    echo $phpNativ1;

    $Lok = new Lok();
    echo $input_in;
    $this->_helper->viewRenderer->setNoRender();

    $text = array($Lok->getMotorState());
    $phpNative = Zend_Json::encode($text);
    echo $phpNative;
}
}

Here are my Jquery functions :

$(document).ready(function(){

    $("p").click(function(){
        $(this).hide();
        $("input[name=State]").val('Forwards');
    });

    function getResponse(name){
        $.ajax({
            dataType: 'json',
            data: {button: name},
        url: 'motor/ajaxtest',
        type: 'post',
        success: function(response)
        {
        }
        });
    }

    $("button[name=on]").click(function() {
        var d_response = getResponse('on');
    });
});

And this is my Lok.php file :

class Lok
{
private $newMotor;
private $newTimer;
private $newSpeaker;
private $mySession;
private $motorState;
private $input;

public function __construct()
{
    //Method instances
    $newMotor = new Motor();
    $newTimer = new Timer();
    $newSpeaker = new Speaker();    
    $this->motorState = $newMotor->getMotorState();

    // Declaring the Session
    $mySession = new Zend_Session_Namespace();
    $mySession->s_motorState = $this->motorState;
}

public function __get($mySession)
{
    return $this->mySession;
}

public function __set($motorState, $mySession)
{
    $this->$mySession->s_motorState = $motorState;
}

public function getMotorState()
{
    return $this->motorState;
}

public function playSound($soundNumber)
{
    echo "Playing sound";
}

public function resetTimer()
{
    echo "Resetting timer";
}

public function setInput($input_in)
{
    $this->input=$input_in;
}
}
  • 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-12T04:08:04+00:00Added an answer on June 12, 2026 at 4:08 am

    As i’ve stated previously you should get the button name by calling the requests post data, this is done by $postData = $this->getRequest()->getPost()

    Then, to get the output into your Model, inside your model class you would create a property as well as setter and getter method for it.

    class Lok {
        protected $button;
        public function setButton($btn){}
        public function getButton(){}
    }
    

    And then it becomes as easy as doing something like

    $lokModel->setButton($postData['button'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Zend Framework and following the design pattern of separating the Data layer
I am using zend framework 1.10. I use the zf tool to create controllers,
In Zend Framework 1.8, using Zend_Tool, the framework now generates controllers, actions, etc. automatically.
I am using Zend Framework, I have a layout.phtml which renders navigation.phtml. How can
Using Zend Framework I want to use controllers stored in a directory which is
How can I read an xls/xlsx file from a controller using Zend framework?
I'm using Zend Framework and MySql to create my web-application. My SQL-code is the
I'm currently using Zend Framework and for some of the actions in various controllers
I am using zend framework. I have a text field which is a compulsory
I am using Zend Framework I have a form that allows me to create

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.