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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:04:19+00:00 2026-05-17T18:04:19+00:00

I have a rest controller example im trying to run that is giving me

  • 0

I have a rest controller example im trying to run that is giving me a headache.

My url im trying to access is localhost/books/edit/1

For some weird reason this route seems to call the getAction with the Controller instead of the editAction. And it throws errors saying that the object doesnt exist.

The controller is,

class BooksController extends Zend_Rest_Controller {

    private $_booksTable;
    private $_form;

    public function init() {
        $bootstrap = $this->getInvokeArg ( 'bootstrap' );
        $db = $bootstrap->getResource ( 'db' );

        $options = $bootstrap->getOption ( 'resources' );
        $dbFile = $options ['db'] ['params'] ['dbname'];
        if (! file_exists ( $dbFile )) {
            $createTable = "CREATE TABLE IF NOT EXISTS books (
                        id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
                        name VARCHAR(32) NOT NULL,
                        price DECIMAL(5,2) NOT NULL
                    )";
            $db->query ( $createTable );

            $insert1 = "INSERT INTO books (name, price) VALUES ('jQuery in Action', 39.99)";
            $insert2 = "INSERT INTO books (name, price) VALUES ('PHP in Action', 45.99)";
            $db->query ( $insert1 );
            $db->query ( $insert2 );
        }

        $this->_booksTable = new Zend_Db_Table ( 'books' );
        $this->_form = new Default_Form_Book ();
    }

    /**
     * The index action handles index/list requests; it should respond with a
     * list of the requested resources.
     */
    public function indexAction() {
        $this->view->books = $this->_booksTable->fetchAll ();
    }

    /**
     * The list action is the default for the rest controller
     * Forward to index
     */
    public function listAction() {
        $this->_forward ( 'index' );
    }

    /**
     * The get action handles GET requests and receives an 'id' parameter; it 
     * should respond with the server resource state of the resource identified
     * by the 'id' value.
     */
    public function getAction() {
        $this->view->book = $this->_booksTable->find ( $this->_getParam ( 'id' ) )->current ();
    }

    /**
     * Show the new book form
     */
    public function newAction() {
        $this->view->form = $this->_form;
    }

    /**
     * The post action handles POST requests; it should accept and digest a
     * POSTed resource representation and persist the resource state.
     */
    public function postAction() {
        if ($this->_form->isValid ( $this->_request->getParams () )) {
            $this->_booksTable->createRow ( $this->_form->getValues () )->save ();
            $this->_redirect ( 'books' );
        } else {
            $this->view->form = $this->_form;
            $this->render ( 'new' );
        }
    }

    /**
     * Show the edit book form. Url format: /books/edit/2
     */
    public function editAction() {
        var_dump ($this->getRequest()->getParam ( 'edit' ));
        $book = $this->_booksTable->find ( $this->getRequest()->getParam ( 'id' ) )->current ();
        var_dump ($book->toArray ());
        $this->_form->populate ( $book->toArray () );
        $this->view->form = $this->_form;
        $this->view->book = $book;
    }

    /**
     * The put action handles PUT requests and receives an 'id' parameter; it 
     * should update the server resource state of the resource identified by 
     * the 'id' value.
     */
    public function putAction() {
        $book = $this->_booksTable->find ( $this->_getParam ( 'id' ) )->current ();
        if ($this->_form->isValid ( $this->_request->getParams () )) {
            $book->setFromArray ( $this->_form->getValues () )->save ();
            $this->_redirect ( 'books' );
        } else {
            $this->view->book = $book;
            $this->view->form = $this->_form;
            $this->render ( 'edit' );
        }
    }

    /**
     * The delete action handles DELETE requests and receives an 'id' 
     * parameter; it should update the server resource state of the resource
     * identified by the 'id' value.
     */
    public function deleteAction() {
        $book = $this->_booksTable->find ( $this->_getParam ( 'id' ) )->current ();
        $book->delete ();
        $this->_redirect ( 'books' );
    }

}

The bootstrap is,

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    protected function _initAutoload() {
        $autoloader = new Zend_Application_Module_Autoloader ( array (
            'namespace' => 'Default_', 
            'basePath' => dirname ( __FILE__ ) 
        ) );
        return $autoloader;
    }

    protected function _initRestRoute() {
        $this->bootstrap ( 'Request' );
        $front = $this->getResource ( 'FrontController' );
        $restRoute = new Zend_Rest_Route ( $front, array (), array (
            'default' => array ('books' ) 
        ) );
        $front->getRouter ()->addRoute ( 'rest', $restRoute );
    }

    protected function _initRequest() {
        $this->bootstrap ( 'FrontController' );
        $front = $this->getResource ( 'FrontController' );
        $request = $front->getRequest ();
        if (null === $front->getRequest ()) {
            $request = new Zend_Controller_Request_Http ();
            $front->setRequest ( $request );
        }
        return $request;
    }

}

Can anyone see what might be causing the getAction to be called when browsing to that link ???

  • 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-17T18:04:19+00:00Added an answer on May 17, 2026 at 6:04 pm

    edit should follow the identifier, so the correct edit URL is http://localhost/books/1/edit

    • 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 a REST style interface that takes XML documents via
I have a web service class that the rest of the framework depends on
We are trying to implement a REST API for an application we have now.
I have a REST data service where I want to allow the users to
We have a REST API which clients routinely POST and PUT data to. When
I have a C# WCF REST Service which allows the addition of a bookmark,
I have a system where I query a REST / Atom server for documents.
Does anyone have links to documentation or guides on making the decision between REST
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.