不能用cakePHP编写数据库。

时间:2022-10-20 15:53:10

I am new to cakePHP and am just starting to use it for my new job. I have created an edit_company action in my Orders Controller. I updated the acos table to allow this action. Now the problem is, I can't access any sort of 'edit' action. It says "You are not authorized to access that location" whenever I try to acccess any action that writes or updates database. edit,edit_products,edit_shipping, etc...

我是cakePHP的新手,刚开始在我的新工作中使用它。我已经在我的Orders控制器中创建了edit_company操作。我更新了acos表以允许此操作。现在的问题是,我不能访问任何“编辑”操作。每当我尝试处理任何写或更新数据库的操作时,它说“您无权访问该位置”。编辑、edit_products edit_shipping等等……

The view action works just fine.

视图动作工作得很好。

This was not happening before.

这种情况以前从未发生过。

Heres a bit of the code:

这里有一些代码:

class OrdersController extends AppController{
        public $uses = array('Order');
    public $hideActions = array('campaign','customer','shipping','review_order','place_order','products','payment','confirmation','cancel','edit_status','edit_order_type','edit_products','edit_tax','add_product','cancel_shipping_label','track_label','view_label','reprint_label','edit_shipping','create_shipping_label');
    public $components = array('Payflow','Printer');
    public $actionMap = array(
        'create' => array('add','create','campaign','customer','shipping','review_order','place_order','payment','products'),
                'read'=> array('index', 'view', 'display','confirmation','track_label','search'),
        'update' => array('edit','cancel','edit_status','edit_order_type','edit_products','edit_company','edit_tax','add_product','cancel_shipping_label','reprint_label','edit_shipping','create_shipping_label'),
        'delete' => array('delete','back_orders_by_state')
    );
    public function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->allow('permissions','gen_acos');   
    }
    public function permissions(){
        $this->Acl->allow('Admin','Controllers/Orders');
        $this->Acl->allow("Sales","Controllers/Orders",'read');
        $this->Acl->allow("Sales","Controllers/Orders",'create');
        $this->Acl->allow("Sales","Controllers/Orders",'update');
        $this->Acl->deny("Shipping","Controllers/Orders",'update');
        $this->Session->setFlash("Permissions Updated.");
        $this->redirect("/orders/");
    }
    public function edit_shipping($id){
        $sm_conditions = array();
        if(!$this->Acl->check(array('User' => array('UserID' => $this->Auth->user("UserID"))), 'Controllers/Orders','delete')){
            $sm_conditions['Restricted'] = 1;
        }
        $shipping_method_ids = $this->Order->ShippingMethod->find("list",array("conditions"=>$sm_conditions,"fields"=>array("ShippingMethodID","ShippingMethodName")));
        $order = $this->Order->read(null,$id);

        $this->set("order",$order);
        $this->set("shipping_method_ids",$shipping_method_ids);
        if($this->request->is('put')){
            if($this->Order->save($this->data,null,array("ShippingAddress","ShippingMethodID"))){
                $this->Session->setFlash("Order Shipping Updated.");
                $this->Order->Note->create();
                $this->Order->Note->save(
                    array("Note"=>array('OrderID'=>$id,"UserID"=>$this->Auth->user("UserID"),"NoteBody"=>"Order Shipping Information updated.","CreatedDate"=>date("Y-m-d H:i:s")))
                );
                $this->redirect("/orders/view/$id");
            }
        }else{
            $this->request->data = $order;
        }
    }


    public function create_shipping_label($id){
        $order = $this->Order->read(null,$id);
        $this->set("order",$order);
        if($this->request->is('put')){
            $this->Order->save(array(
                "Order"=>array(
                    "OrderID"=>$id,
                    "LabelPrinted"=>false,
                    "OrderStatusID"=>2,
                    "Notes"=>(!empty($this->data['Order']['Notes']))?$this->data['Order']['Notes']:null
                )
            ));
            $this->Session->setFlash("A new shipping label will be created momentarily.");
            $this->Order->Note->create();
            $this->Order->Note->save(
                array("Note"=>array('OrderID'=>$id,"UserID"=>$this->Auth->user("UserID"),"NoteBody"=>"New shipping label will be created. ".((!empty($this->data['Order']['Notes']))?$this->data['Order']['Notes']:null),"CreatedDate"=>date("Y-m-d H:i:s")))
            );
            $this->redirect("view/".$id);
        }else{
            $this->request->data = $order;
        }
    }
    public function cancel($id){
        $order = $this->Order->read(null,$id);
        if($this->request->is('post')){
            //Check if note given
            $this->Order->Note->data = $this->data;
            if($this->Order->Note->validates()){

                //Delete from Call table
                $this->loadModel("Call");
                $this->Call->deleteAll(array('Call.OrderID'=>$id));
                //Add a note
                $user_id = $this->Auth->user("UserID");
                $this->Order->Note->create();
                $this->Order->Note->save(
                    array("Note"=>array('OrderID'=>$id,"UserID"=>$user_id,"NoteBody"=>"Order Canceled. ","CreatedDate"=>date("Y-m-d H:i:s")))
                );
                $this->Order->Note->create();
                $this->Order->Note->save(
                    array("Note"=>array('OrderID'=>$id,"UserID"=>$user_id,"NoteBody"=>"Reason For Cancellation: ".$this->data['Note']['NoteBody'],"CreatedDate"=>date("Y-m-d H:i:s")))
                );
                //Create a refund request if payment type is in TxType (1,2,3,7,11,9)
                $txTypes = array(1,2,3,7,11,9);
                $paid = 0;
                foreach($txTypes as $txType){
                    $payments = Set::extract("/Payment[TransactionTypeID=$txType]/PaymentAmount",$order);
                    $paid += array_sum($payments);
                }
                if($paid>0){
                    $this->Order->refund($id,$paid);
                }
                //Change Status to Cancel (4) & LabelPrinted = 0
                $this->Order->save(array("Order"=>array("OrderID"=>$id,"LabelPrinted"=>0,"OrderStatusID"=>4)));
                //Update the total price
                $this->Order->updateOrderTotal($id);
                $this->Session->setFlash("Order was successfully canceled.");
                $this->redirect("/orders/view/".$id);
            }
        }
        $this->set("order",$order);
    }
    public function edit_products($id){
        $order = $this->Order->read(null,$id);
        $this->set("order",$order);
        if($this->request->is("post")){
            $error = false;
            while($error==false && ($oe=array_shift($this->request->data['OrderEntry']))){
                if(!$this->Order->OrderEntry->save(array("OrderEntry"=>$oe))){
                    $error = true;
                }
            }
            if($error==false){
                $this->Session->setFlash("Products Updated.");
                $this->Order->updateOrderTotal($id);
                $this->redirect("/orders/view/$id");
            }
        }


}
    public function edit_company () {

    }

    public function edit ($id=null) {
        $order = $this->Order->read(null,$id);
        $this->set("order",$order);
        if($this->request->is("post")){
                $error = false;
                while($error==false && ($oe=array_shift($this->request->data['OrderEntry']))){
                        if(!$this->Order->OrderEntry->save(array("OrderEntry"=>$oe))){
                                $error = true;
                        }
                }
                if($error==false){
                        $this->Session->setFlash("Products Updated.");
                        $this->Order->updateOrderTotal($id);
                        $this->redirect("/orders/view/$id");
                }
        }

    }

Could anyone help me with this problem? Thanks!

有人能帮我解决这个问题吗?谢谢!

1 个解决方案

#1


2  

You are only giving non authenticaded users permission to access two actions:

您只允许非认证用户访问两个操作:

    public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('permissions','gen_acos');   
    }

Add the new actions or log the user in before accesing the actions:

在操作之前添加新动作或记录用户:

Giving permission to not authenticated users to your new actions:

向未经认证的用户授权您的新操作:

public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('permissions','gen_acos','edit_products','edit','cancel','create_shipping_label','edit_shipping');   
    }

If you don't want to grant access to non authenticated users to these actions login before trying to access them.

如果您不想在尝试访问这些操作之前授予对未经身份验证的用户的访问权限,请登录它们。

You can check more about Auth here

你可以在这里查看更多关于Auth的信息

Also check this example that is part of the Blog Tutorial

还要检查这个例子,它是Blog教程的一部分

#1


2  

You are only giving non authenticaded users permission to access two actions:

您只允许非认证用户访问两个操作:

    public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('permissions','gen_acos');   
    }

Add the new actions or log the user in before accesing the actions:

在操作之前添加新动作或记录用户:

Giving permission to not authenticated users to your new actions:

向未经认证的用户授权您的新操作:

public function beforeFilter(){
    parent::beforeFilter();
    $this->Auth->allow('permissions','gen_acos','edit_products','edit','cancel','create_shipping_label','edit_shipping');   
    }

If you don't want to grant access to non authenticated users to these actions login before trying to access them.

如果您不想在尝试访问这些操作之前授予对未经身份验证的用户的访问权限,请登录它们。

You can check more about Auth here

你可以在这里查看更多关于Auth的信息

Also check this example that is part of the Blog Tutorial

还要检查这个例子,它是Blog教程的一部分