需要帮助在更新时发现问题

时间:2011-12-11 18:37:36

标签: cakephp

我在使用cakephp更新记录方面遇到问题,这是第二次发生并且无法弄清楚它是什么..当我点击“提交”以更新记录时,总是将我发送到登录状态它要么登录我,要么让我退出..我不明白..它永远不会更新记录它只是跳转到登录的东西......注册页面同样的事情..它之前工作..我唯一改变的事情..是在app_controller而不是指定控件允许我只为所有添加'*'现在它不允许更新或保存任何东西..我这样做的原因是因为其他页面在页面/ contact_us或页面/ about_us他们也被Auth阻止但是'*'它已经消失了..

在我的App_Controller中,我已将其设置为允许在过滤器中的所有内容,也在控制器本身中我有一个beforeFilter再次说同样的事情..我已经尝试了一切..这是我的代码

App_Controller

<?php
class AppController extends Controller {    

    var $helpers = array('Html', 'Form', 'Javascript', 'Session'); 
    var $components = array('Auth', 'Session');

    function beforeFilter() {

       $this->Auth->allowedActions = array('*');
       $this->Auth->autoRedirect = false;

      } 
}
?>

我更新的控制器之一

<?php

class DishRatingsController extends AppController {

      function list_ratings() { 

         $this->loadModel('Dish');
         $this->set('list_ratings', $this->Dish->find('all')); 
         $this->layout = 'master_layout';

      }

      function  rate_dish($id = null)
      {
        $this->layout = 'master_layout';

        $this->set('rate_dishes', $this->DishRating->find('all', array(
            'conditions' => array(
               'Dish.id' => $id
          )
        )));

         if(!empty($this->data)) {         
             if($this->DishRating->save($this->data)) {                        
                $this->Session->setFlash("Rating Saved!");             
                 $this->redirect(array('action' => 'dish_ratings'));                  
             }         

        // set master layout
     }
    }

    function beforeFilter() {
       parent::beforeFilter(); 
       $this->Auth->allowedActions = array('*');

      } 

}

和我的查看提交按钮的位置

<?php

 echo $this->Form->create('DishRating', array('action' => 'rate_dish'));

 echo '<div><h3>Rate this Dish...</h3><p>You can rate this dish on this page and view other ratings from out customers...   </p></div>
    <table id="recipes">
     <tr>
         <td style="padding:10px;">';
         //<input type="hidden" name="userID" value="'.$rate_dishes[0]["DishRating"]["user_id"].'">
         echo $this->Form->hidden('id', array('value'=> $rate_dishes[0]["DishRating"]["user_id"]));
         //<input type="hidden" name="dish_id" value="'.$dish_rateid.'">
         echo $this->Form->hidden('rate_id', array('value'=> $rate_dishes[0]["DishRating"]["dish_id"]));
         echo '
         <span style="font-size: 20px; vertical-align:top;">Comments</span>
         </td>
         <td style="padding:10px;">';
         echo $this->Form->input('comments', array('type' => 'textarea', 'escape' => false , 'rows'=>'2','cols'=>'40', 'div' =>'false', 'label'=>''));
         //<textarea name="comments" cols="40" rows="2"></textarea>
         echo '</td>
         <td>
         <div>
          <input name="star1000" value "1" type="radio" class="star"/>
          <input name="star1000" value="2" type="radio" class="star"/>
          <input name="star1000" value="3" type="radio" class="star"/>
          <input name="star1000" value="4" type="radio" class="star"/>
          <input name="star1000" value="5" type="radio" class="star"/> 
          </div>
         </td>
         <td>';
          // <input type="submit" value="Submit" name="submitrating" class="button"/>
         echo $this->Form->end(array('value'=>'Submit','name'=>'submitrating', 'type' =>'submit', 'class'=>'button'));
         echo '</td>
    <tr>
    </table>'; 

      print("<table id='results'><tr><th>User Name</th><th>Comments</th><th>Star Rating</th></tr>");
     $j = 0;

         foreach ($rate_dishes as $key => $rate_dish):

         print("<tr>");   
         print("<td width='20px'>");
         print("<p style='font-size:14px; color:blue; padding:0;'>".$rate_dishes[$j]['User']['username']."</p>");

         print("</td>");          
         print("<td width='100px'>");
         print("<p style='font-size:14px; color:blue; padding:0;'>".$rate_dishes[$j]['DishRating']['rate_comments']."</p>");
         print("</td>");
         print("<td width='100px'>");
         print("<div>");
         for($i = 1; $i < 6;$i++)
         {
          if($i != $rate_dishes[$j]['DishRating']['rate_num'])
          {
              echo  '<input name="star'.$j.'"  type="radio" class="star" disabled="disabled"/>';
          } 
          else 
          {
              echo  '<input name="star'.$j.'"  type="radio" class="star" disabled="disabled" checked="checked"/>';
          }
         }
         print("</div>");
         print("</td>");
         print("</tr>");
         $j++;
         endforeach;

         print("</table>");      

      if($j> 6)
     {
         echo '<div id="pageNavPosition"></div>
         <div>&nbsp;</div>';      


           echo $this->Html->script('padminbottom.js');
     }
  ?>

请帮忙解决这个问题,我已经研究过,去过cakePHP食谱,没什么......

1 个答案:

答案 0 :(得分:0)

如果您想允许每个控制器的每个操作,那么app_controller中的beforeFilter应该像

   function beforeFilter() {

       $this->Auth->allow('*');
       $this->Auth->autoRedirect = false;

  }

指定$this->allowedActions是另一回事,在这种情况下,您的Auth的authorize变量应设置为'controller'。这意味着无论何时用户请求操作,他/她都将被检查其正确的用户名,密码。之后,每个控制器实现的isAuthorize()功能将检查该用户,以根据一些额外的逻辑授予访问权限。

由于您未使用该功能,因此无需指定allowedAction。如果您使用控制器进行授权指定allowedActions,则默认情况下会允许某些操作,而不会在Controller::isAuthorize()中进行检查。