Tuesday, November 30, 2010

Re: Missing Method??

Hi,

Whenever you access URL like /books then it automatically goes to /books/index internally. It means if you want to provide parameter in URL for 'index' action of controller then your URL should be like /books/index/1 instead of /books/1. Otherwise you need to use route to point URLs like /books/1 to /books/index/1 internally, more help is at http://book.cakephp.org/view/945/Routes-Configuration

Amit Badkas

PHP Applications for E-Biz: http://www.sanisoft.com



On Wed, Dec 1, 2010 at 8:20 AM, Hans Wiriya Tsai <hansw.id@gmail.com> wrote:
I m trying to make a controller and a view without model. Here are the code:
Controller:
<?php
class BooksController extends AppController {
       var $name = 'Books';
       var $uses = array();

       function index($id = 0) {
               $books = array (
                               '0' => array(
                                               'book_title' => 'OOP with PHP5',
                                               'author' => 'Hasin Hayder',
                                               'isbn' => '1847192564',
                                               'release_date' => 'December 2007'
                                       ),
                               '1' => array(
                                               'book_title' => 'Building website with Joomla',
                                               'author' => 'Hagen Grraf',
                                               'isbn' => '1847192577',
                                               'release_date' => 'March 2006'
                                       )
               );
               $id = intval($id);
               if($id < 0 || $id >= count($books)) {
                       $id = 0;
               }
               $this->set($books[$id]);
               $this->set('page_heading', 'Book Store');
               $this->pageTitle = 'Welcome to the Packt Book Store!';
       }
}

View:

<h2><?php echo $page_heading; ?></h2>
<dl>
       <lh><?php echo $book_title; ?></lh>
       <dt>Author:</dt><dd><?php echo $author; ?></dd>
       <dt>ISBN:</dt><dd><?php echo $isbn; ?></dd>
       <dt>Release Date:</dt><dd><?php echo $releaseDate; ?></dd>
</dl>

Those are example from CakePHP Application Development, but
unfortunately the book was using Cake 1.2.x while I have 1.3.6
version. If I try to open it via
http://http://localhost/applogic/books/ looks OK, but if I try
http://http://localhost/applogic/books/1 an error occur like:

Missing Method in BooksController
Error: The action 1 is not defined in controller BooksController

Error: Create BooksController::1() in file:
app/controllers/books_controller.php.

<?php
class BooksController extends AppController {

       var $name = 'Books';


       function 1() {

       }

}
?>

Something not compatible between those 2 version?

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: