Cakephp 2.5.4: Redirection url after form submit

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

I want to submit the form to www.example.com/users/signup but my page is submitting to www.example.com/test/users/signup. Cakephp is installed in test folder. I have created htaccess inside test folder. This is my htaccess:

<IfModule mod_rewrite.c>  RewriteEngine on  RewriteRule    ^$ test/    [L]  RewriteRule    (.*) test/$1 [L]  RewriteRule    ^$ /test/users/signup  [L]  RewriteRule users/signup /users/signup [L] </IfModule> 

View:

<?php  echo $this->Form->create('User',array('url'=>array('controller'=>'users','action'=>'signup')), array('id' => 'signup',  'role' => 'form','class'=>'form-signin'));   echo $this->Form->input('User.email',array('type'=>'email','required'=>'required','class'=>'form-control','placeholder'=>'Email'));  echo $this->Form->input('User.password',array('type'=>'password','required'=>'required','class'=>'form-control','placeholder'=>'Password')); ?>  <button type="submit" class="btn btn-lg btn-primary btn-block">Sign up</button> <?php echo $this -> Form -> end(); ?> 

I created the routes:

<?php  Router::connect('/users/signup', array('controller' => 'users', 'action' => 'signup')); ?> 

If you want to ask any query please feel free to ask.

回答1:

/signup is the route I connected in routes.php - it's a "pretty url" so I don't have the default /{controller}/{action} format. If the site is not in a sub-folder, any form I generate with $this->Form->create() POSTs to /signup. However, when in the sub-folder, I can see the page at /signup but all generated URLs include the sub-folder. I want the site to work as though there is no sub-folder and behave as though it's in the root. Setting Configure::write('App.baseUrl, '/'); did the trick.

Solution is: Configure::write('App.baseUrl, '/');



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!