We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Router issue

i have create 2 modules in one project: forum/apps/backend & forum/apps/frontend.

in public/index.php i have set the router code as below:

$di->set('router', function(){ $router = new Router(); $router->setDefaultModule('frontend'); $router->add( "/backend", array( 'module' => 'backend', 'controller' => 'index', 'action' => 'index' ) ); $router->add( "/backend/:controller/:action/:params", array( 'module' => 'backend', 'controller' => 1, 'action' => 2, 'params' => 3, ) );

return $router;

});

and the backend index is : www.forum.com/backend

and backend/views/index/index.phtml code as below:

<form method="post" action="backend/index/index"> <table align="center" cellpadding="0" cellspacing="0" border="1" width="600" height="150"> <tr align="center"> <td>管理员账号</td> <td><input type="text" name="aname"></td> </tr> <tr align="center"> <td>管理员密码</td> <td><input type="password" name="apassword"></td> </tr> <tr><td colspan='2'><input type="hidden" name="<?php echo $this->security->getTokenKey();?>" value="<?php echo $this->security->getToken();?>"><p></p></td></tr> <tr align="center"> <td colspan='2'><input type="submit" value="登录"> <input type="reset" value="重置"></td> </tr> </table> </form>

but i double click the submit in index.phtml ,the url change to :

https://www.forum.com/backend/index/backend/index/index

how to set the correct router,whatever cilck how many the submit button,the url also https://www.forum.com/backend or https://www.forum.com/backend/index/index

below is backend modlue index controller code:

<?php namespace forum\backend\controllers; use Phalcon\Mvc\Controller; use Phalcon\Mvc\Model; use forum\backend\models\Admin;

class IndexController extends Controller{ public function indexAction(){ if($this->request->isPost()){ if($this->security->checkToken()) {
$aname = $this->request->getPost('aname'); $apassword = $this->request->getPost('apassword'); $admin = Admin::findFirst("aname = '$aname'"); if($admin){ if($apassword == $admin->apassword) { $this->response->redirect("backend/index/main"); }else { $this->response->redirect("backend/index/index"); } }else { $this->response->redirect("backend/index/index"); } } } }

 public function mainAction(){

 }

}



85.5k

https://docs.phalcon.io/en/latest/reference/routing.html#setting-default-paths


$router->setDefaultController('index');
$router->setDefaultAction('index');

?