Basic controller

Hi! First time using picora and I am trying to get some very basic things working but I got some error I don't really understand. Here is what I am trying to do: get the value of a variable being passed from the url to the controller. Here is what I have added so far (everything else is a default picora installation):

ApplicationController.php


public function test($id)
{
    echo $id ;
    die() ;
}
public function testindex()
{
    echo 'hello, world!' ;
    die() ;
}

config.php


PicoraDispatcher::addRoute(array
                                  (
                                   '/'          => array('Application', 'welcome'  ),
                                   '/test/'     => array('Application', 'testindex'),
                                   '/test/:id/' => array('Application', 'test'     )
                                  )
                           );

The url http://localhost/picora/test/ works as expected but http://localhost/picora/test/99/ fails and gives this message:

Warning: Missing argument 1 for ApplicationController::test() in D:\htdocs\picora\controllers\ApplicationController.php on line 16 Line 16:

 public function test($id){

What am i doing wrong?

Posted July 27th, 2007 at 7:49am by ffogol

shouldn?t it be

//'/test/:id/' => array('Application', 'test' ) '/test/$id/' => array('Application', 'test' ) or is this a new thing in the new version?

Posted August 13th, 2007 at 10:00am by ruben

meant

"/test/$id/' => array('Application', 'test' )" with an $

have to get used to this forum :)

Posted August 13th, 2007 at 10:01am by ruben

no, read the informations on the project page. ":" is the right thing. sorry I havn't much experience with the new versions. all seems so different :)

Posted August 13th, 2007 at 10:16am by ruben

Same problem here ... :(

It seems there are changes in calluserfunc() between PHP-versions. I use PHP 5.2.3 (built: Jul 11 2007)

Posted August 21st, 2007 at 2:11pm by Aaron

Here are a quick & dirty fix for this Problem:

PicoraDispatcher.php


$response = call_user_func($callback, $instance->params);

After this edit, your controller-method looks like this:


public function test($params){  
    echo $params['id'];
    // ...
}

I haven't yet tested this change good enought, so if something else crashed or doesn't work anymore, let me know.

Posted August 21st, 2007 at 2:29pm by Aaron

forget the line: Its line 79. We need an "edit"-Button here soon :)

Posted August 21st, 2007 at 2:31pm by Aaron

Login or Register to Post