您好我的蛋糕应用程序遇到了一些问题 - 我实现的形式很好地提交到数据库中,但是当我故意提供虚假凭据时它要求在Userscontroller中查看,但是我没有为表单操作创建一个视图,因为我的表单在我的主页上,有人可以帮助我。 祝福弗雷德。
UsersController
<?php
class UsersController extends AppController {
/*public $paginate = array(
'limit' => 25,
'conditions' => array('status' => '1'),
'order' => array('User.username' => 'asc' )
);
*/
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow();
}
public function login() {
//if already logged-in, redirect
if($this->Session->check('Auth.User')){
$this->redirect(array('action' => 'index'));
}
// if we get the post information, try to authenticate
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->Session->setFlash(__('Welcome, '. $this->Auth->user('username')));
$this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(__('Invalid username or password'));
}
}
}
public function logout() {
$this->redirect($this->Auth->logout());
}
public function index() {
$this->paginate = array(
'limit' => 6,
'order' => array('User.username' => 'asc' )
);
$users = $this->paginate('User');
$this->set(compact('users'));
}
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been created'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be created. Please, try again.'));
}
}
}
public function edit($id = null) {
if (!$id) {
$this->Session->setFlash('Please provide a user id');
$this->redirect(array('action'=>'index'));
}
$user = $this->User->findById($id);
if (!$user) {
$this->Session->setFlash('Invalid User ID Provided');
$this->redirect(array('action'=>'index'));
}
if ($this->request->is('post') || $this->request->is('put')) {
$this->User->id = $id;
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been updated'));
$this->redirect(array('action' => 'edit', $id));
}else{
$this->Session->setFlash(__('Unable to update your user.'));
}
}
if (!$this->request->data) {
$this->request->data = $user;
}
}
public function delete($id = null) {
if (!$id) {
$this->Session->setFlash('Please provide a user id');
$this->redirect(array('action'=>'index'));
}
$this->User->id = $id;
if (!$this->User->exists()) {
$this->Session->setFlash('Invalid user id provided');
$this->redirect(array('action'=>'index'));
}
if ($this->User->saveField('status', 0)) {
$this->Session->setFlash(__('User deleted'));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('User was not deleted'));
$this->redirect(array('action' => 'index'));
}
/*public function activate($id = null) {
if (!$id) {
$this->Session->setFlash('Please provide a user id');
$this->redirect(array('action'=>'index'));
}
$this->User->id = $id;
if (!$this->User->exists()) {
$this->Session->setFlash('Invalid user id provided');
$this->redirect(array('action'=>'index'));
}
if ($this->User->saveField('status', 1)) {
$this->Session->setFlash(__('User re-activated'));
$this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('User was not re-activated'));
$this->redirect(array('action' => 'index'));
}
* / }
&GT;
home.ctp
<div id="banner">
<div id="mapbox">
<?php echo $this->Html->image('map.png', array('alt' => 'logo', 'width' => "300", 'height' => "253")); ?>
</div><!--mapbox ends<!---->
<p>What's your problem?</p>
<ul>
<li><?php echo $this-> html->link('Share Problem', array('action' => 'problem'),array('class'=>'share_prob'));?></li>
</ul>
</div><!--banner ends-->
<div id="leftcol">
<p class="darkgry bold spacer">Browse problems by</p>
<ul class="browsprob">
<li><a class="locbtn" href="#">Location</a></li>
<li><a class="urgbtn" href="#">Urgency</a></li>
<li><a class="rewbtn" href="#">Reward</a></li>
<li><a class="chabtn" href="#">Charity</a></li>
<li><a class="relbtn" href="#">Reliability</a></li>
</ul>
<div id="innerleft">
<p class="title">Sign Up</p>
<p class="title2">Already have an account? <?php echo $this-> html->link('Login', array('action' => 'login'));?>
<div id="facebook">
<?php echo $this->Html->image('facebook.png', array('alt' => 'facebook logo')); ?>
</div>
<div id="linked">
<?php echo $this->Html->image('linked.png', array('alt' => 'linked logo')); ?>
</div>
</div>
<div id="register">
<div>
<?php echo $this->Form->create('User', array('action' => 'add'));?>
<div class="firstname">
<?php echo $this->Form->input('firstname', array('class' => 'input01'));?>
</div>
<div class="lastname">
<?php echo $this->Form->input('lastname', array('class' =>'input02'));?>
</div>
<div class = "firstname">
<?php echo $this->Form->input('location', array('class' => 'input03'));?>
</div>
<div class="firstname">
<?php echo $this->Form->input('username', array('class' =>'input03'));?>
</div>
<div class="email">
<?php echo $this->Form->input('email', array('class' => 'input03'));?>
</div>
<div class="lastname">
<?php echo $this->Form->input('password',array('class' => 'input02'));?>
</div>
<div class="email">
<?php echo $this->Form->input('password_confirm', array('label' => 'Confirm Password *', 'maxLength' => 255, 'title' => 'Confirm password', 'type'=>'password', 'class' =>'input03'));?>
</div>
<?php echo $this->Form->submit('Register', array('class' => 'inputbutton'));?>
<?php $this->Form->end()?>
<p class="tick">I agree to your T&C's <input class="box" type="checkbox" name="sports" value="soccer" /><br />
</div>
</div>
</div><!--leftcol ends-->
<div id="rightcol">
<div id="innerright">
<h3>TOP SOLVERS</h3>
<ul id="topsolv">
<li>
<?php echo $this->Html->image('top_solv.png', array('alt' => 'profile pic', 'width' => "121", 'height' => "121")); ?>
</li>
<li>
<?php echo $this->Html->image('top_solv.png', array('alt' => 'profile pic', 'width' => "121", 'height' => "121")); ?>
</li>
<li>
<?php echo $this->Html->image('top_solv.png', array('alt' => 'profile pic', 'width' => "121", 'height' => "121")); ?>
</li>
<li>
<?php echo $this->Html->image('top_solv.png', array('alt' => 'profile pic', 'width' => "121", 'height' => "121")); ?>
</li>
</ul>
<h3>Recently Solved</h3>
<ul id="solvedprob">
<li>
<?php echo $this->Html->image('prof_img.jpg', array('alt' => 'profile image', 'width' => "51", 'height' => "52")); ?>
<p class="bold">Problem</p>
<p class="bluebold">From User <span class="highlight">New User</span></p>
<p class="darkgry small">Posted on 01/01/13 at 00:00</p>
</li>
<li>
<?php echo $this->Html->image('prof_img.jpg', array('alt' => 'profile image', 'width' => "51", 'height' => "52")); ?>
<p class="bold">Problem</p>
<p class="bluebold">From User <span class="highlight">New User</span></p>
<p class="darkgry small">Posted on 01/01/13 at 00:00</p>
</li>
<li>
<?php echo $this->Html->image('prof_img.jpg', array('alt' => 'profile image', 'width' => "51", 'height' => "52")); ?>
<p class="bold">Problem</p>
<p class="bluebold">From User <span class="highlight">New User</span></p>
<p class="darkgry small">Posted on 01/01/13 at 00:00</p>
</li>
<li>
<?php echo $this->Html->image('prof_img.jpg', array('alt' => 'profile image', 'width' => "51", 'height' => "52")); ?>
<p class="bold">Problem</p>
<p class="bluebold">From User <span class="highlight">New User</span></p>
<p class="darkgry small">Posted on 01/01/13 at 00:00</p>
</li>
<li>
<?php echo $this->Html->image('prof_img.jpg', array('alt' => 'profile image', 'width' => "51", 'height' => "52")); ?>
<p class="bold">Problem</p>
<p class="bluebold">From User <span class="highlight">New User</span></p>
<p class="darkgry small">Posted on 01/01/13 at 00:00</p>
</li>
<li>
<?php echo $this->Html->image('prof_img.jpg', array('alt' => 'profile image', 'width' => "51", 'height' => "52")); ?>
<p class="bold">Problem</p>
<p class="bluebold">From User <span class="highlight">New User</span></p>
<p class="darkgry small">Posted on 01/01/13 at 00:00</p>
</li>
<p class="darkgry bold alignright">VIEW MORE
<?php echo $this->Html->image('more.gif', array('alt' => 'arrows', 'width' => "15", 'height' => "17")); ?>
</ul>
</div><!--innerright ends-->
</div><!--rightcol ends-->
答案 0 :(得分:0)
您的代码看起来很乱,您应该只留下问题所需的内容,而不仅仅是那里的所有东西(如评论部分,CSS,图像和不是)。
我认为您不了解代码的流程。在您的主页上,您将表单发布到/users/add
,因此当它失败时,您会在那里找不到视图。如果成功,您可以重定向到index
(在Users
中),我认为该视图存在。
另请查看您的UsersController::beforeFilter()
$this->Auth->allow();
,这意味着非经过身份验证的用户可以使用该控制器中的所有操作。这意味着任何人都可以更改任何人的密码或删除所有用户。