General Category > Bug Reports

Can not pass param to controller

(1/1)

changtraingheo:
I have example code:


--- Code: ---class Hello_Controller extends TinyMVC_Controller
{
  function index()
  {
    $this->view->display('index_view');
  }
 
  function ohyeah($var) {
echo "This is oh yeah: " . $var;
  }
}
--- End code ---

When i try run http://localhost/mvc/hello, it work well, but when i try run http://localhost/mvc/hello/ohyeah/123 i got this error:


--- Quote ---Error: E_WARNING
Message: Missing argument 1 for Hello_Controller::ohyeah(), called in D:\UniServer\www\mvc\tinymvc\sysfiles\TinyMVC.php on line 108 and defined
File: D:\UniServer\www\mvc\tinymvc\myapp\controllers\hello.php
Line: 19
--- End quote ---

mohrt:
The url segments are not passed in as parameters to the action method. You can get to url segments through tmvc::instance()->url_segments, or you can use the uri library to obtain segment data, or get them manually.

It would also be trivial to pass these through the action method as parameters as you are expecting, it is one line of code.

Navigation

[0] Message Index

Go to full version