【发布时间】:2014-07-03 02:41:52
【问题描述】:
这是我的 SignupController.php 代码:
<?php class SignupController extends \Phalcon\Mvc\Controller {
public function indexAction()
{
}
public function registerAction()
{
$user = new Users();
//Store and check for errors
$success = $user->save($this->request->getPost(), array('name', 'email'));
if ($success) {
echo "k";
} else {
echo "Sorry, the following problems were generated: ";
foreach ($user->getMessages() as $message) {
echo $message->getMessage(), "<br/>";
}
}
$this->view->disable();
} }
那么这是我注册文件夹中的 index.php:
<html>
<head><title>trial</title> <script type="text/javascript" src="public/js/jquery.js"></script>
<script type="text/javascript" src="public/js/ext.js"></script>
<body>
<div id="signup/-feedback"></div>
<form id="signupForm" name="loginForm" method="post" action="signup/register">
<table width="300" border="0" align="center" cellpadding="2" cellspacing="0" >
<td colspan="3" align="center" height="50"><strong>Registration form</strong></td> <br />
<tr>
<th>Name:</th>
<td><input name="name" type="Variable" class="input2" id="name" /></td>
<div id="underInput" />
</tr>
<tr>
<th>Email:</th>
<td><input name="email" type="Variable" class="input2" id="email" /></td>
</tr>
<td> </td>
<td><input type="submit" name="Submit" value="Register" />
<input type="reset" name="Submit2" value="Clear" /></td>
</tr>
</table>
</body>
</html>
这是我的 ext.js:
$('signupForm').submit(function(){
var name = $ ('#name').val();
$('#signup_feedback').html('Registration success', + name + 'has been registered. You may now do 10 cartwheels XD');
});
我该怎么办?
这是我的公共文件夹中的 index.php:
try {
//Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
//Create a DI
$di = new Phalcon\DI\FactoryDefault();
//Setup the database service
$di->set('db', function(){
return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
"host" => "localhost",
"username" => "root",
"password" => "123",
"dbname" => "test_db"
));
});
//Setup the view component
$di->set('view', function(){
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../app/views/');
return $view;
});
//Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
$url = new \Phalcon\Mvc\Url();
$url->setBaseUri('/');
return $url;
});
//Handle the request
$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();
} catch(\Phalcon\Exception $e) {
echo "PhalconException: ", $e->getMessage();
}
有什么办法可以解决~~~非常感谢
【问题讨论】:
-
我想你忘记了什么......$('#signupForm') 注册表格是一个 ID,所以不要忘记添加 '#'
-
我已经更改了它,但无论我做什么,它总是重定向到注册。我想尝试不会重新加载我的页面的代码,但我输入的所有数据都将注册到我的数据库中。它只会显示它是使用 jquery 注册的注释。提前谢谢你:)
-
这是一个更清晰的解释......在这种情况下,删除“
-
如果我删除了
-
是的,类似的东西,如果你卡住了,去试试,我可以为你写一个简单的例子