CakePHP的2.5.4:表后重定向的URL提交 [英] Cakephp 2.5.4: Redirection url after form submit

查看:264
本文介绍了CakePHP的2.5.4:表后重定向的URL提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的形式提交给 www.example.com/users/signup ,但我的网页提交的 www.example.com/test/users/signup 。 CakePHP是安装在测试文件夹。我已经测试文件夹内创建htaccess的。 这是我的htaccess的:

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>

查看:

<?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'));
?>

如果你要问任何疑问,请随时问。

推荐答案

/注册是我连接routes.php文件的路径 - 这是一个pretty的URL,所以我没有缺省的/ {}控制器/ {行动}格式。如果该网站是不是在子文件夹中,任何形式我生成与$这个 - >形式 - >创建()职位/注册。但是,如果在子文件夹中,我可以看到/注册,但该页面所有生成的URL包括子文件夹。我希望自己的网站工作,仿佛没有子文件夹,然后运行,就好像是在根。设置配置::写(App.baseUrl,'/');并获得成功。

/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.

解决方案是:配置::写(App.baseUrl,'/');

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

这篇关于CakePHP的2.5.4:表后重定向的URL提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆