Hello, my code is not working in CakePHP framework and it is showing an error message.
URL:
http://domainname.com/About/param1/param2
Code:
class AboutController extends AppController {
public $name = 'About';
public $helpers = array('Html');
public function index($arg1, $arg2)
{
print_r($this->request->params['pass']);
$this->set('title_for_layout','Sarasavi Bookshop - About Sarasavi Bookshop');
$this->set('nameforfiles','about');
}
}
Error message:
Missing Method in AboutController
Error: The action param1 is not defined in controller AboutController
Error: Create AboutController::param1() in file: app\Controller\AboutController.php.
<?php
class AboutController extends AppController {
public function param1() {
}
}
Notice: If you want to customize this error message, create app\View\Errors\missing_action.ctp
After creating the function param1 I can get param2, But I need to get param1 and param2 both, in index function without create another action.
Please help me,
Thanks
Your original code would work if you went to http://domainname.com/About/index/param1/param2
If you don’t want the
indexin the url, as I assume you don’t, then you need to define a route.Add this to your routes:
to automatically route requests that don’t specify an action but do have params to go to your
indexaction. You will need to add a route for any newAboutactions to stop requests for them from going to index by default though.