[英]Need Help figuring issue when updating
我在使用cakephp更新记录时遇到问题,这是第二次发生,无法弄清它是什么。.当我单击“提交”以始终更新记录时,始终将我发送到登录名,并且无论是登录我登录或注销我..我不明白..并且它从不更新记录,它只是跳转到登录内容...注册页面同样的东西..它在工作之前..我唯一改变的..是在app_controller中,而不是指定允许的控件,我只是为所有对象添加了“ *”,而现在却不允许更新或保存任何内容。.之所以这样做,是因为在pages / contact_us或pages / about_us下的其他页面他们也被Auth阻止,但是带有“ *”的消息消失了。
在我的App_Controller中,我将其设置为允许在before过滤器中进行所有操作,在控制器本身中,我也再次使用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> </div>';
echo $this->Html->script('padminbottom.js');
}
?>
请帮忙解决这个问题,我已经研究过了,去了CakePHP Cookbook,没什么...
如果要允许每个控制器的每个动作,则app_controller中的beforeFilter
应该像
function beforeFilter() {
$this->Auth->allow('*');
$this->Auth->autoRedirect = false;
}
指定$this->allowedActions
是另一回事,在这种情况下,您的Auth的authorize
变量应设置为'controller'。 这意味着,每当用户请求操作时,都将检查其正确的用户名和密码。 之后,将由每个控制器实现的isAuthorize()
函数检查该用户,以基于一些其他逻辑授予访问权限。
由于您没有使用该功能,因此无需指定allowedAction
。 如果您使用控制器进行授权,则指定allowedActions
将默认允许某些操作,而无需在Controller::isAuthorize()
检查它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.