English 中文(简体)
声明发表时的深度
原标题:deep nested if statement issues

Ok, So I m负责撰写任务组织者书,Im在标注子方面有一些问题,如完整或不完整。

if($_POST[ finished ]){ // $_POST[ finished ] is an html array of check boxes
            $subtask = Subtask::find_all_by_task_id($task->id);
            foreach($subtask as $stask){
                foreach($_POST[ finished ] as $fin){ 
                    if($stask->id == $fin){
                        $stask->finished_at = date( Y-m-d H:i:s , time());
                        $stask->save();
                    } elseif($stask->id != $fin){
                        $stask->finished_at = "";
                        $stask->save();
                    }
                }
            }
        } else { // This works as expected when un-checking all checkboxes
            $subtask = Subtask::find_all_by_task_id($task->id);
            foreach($subtask as $stask){
                if($stask->finished_at != null){
                    $stask->finished_at = null;
                    $stask->save();
                }
            }
        }

我认为,如果发言在两个价值上滚动(此时仅是两个子塔),那么所有其他定值都不会等到上。 如果说的话,我如何确定解决这一问题的最佳途径。 我尝试了几处改动,但没有结果。

最佳回答

因此,简单的工作/解决办法就是这样。

function completetask($tasktype, $id, $return_uri =  edittask ){
    if($tasktype == "subtask"){
        $task = Subtask::find($id);
        if($task->finished_at == null){
            $task->finished_at = date("Y-m-d H:i:s", time());
            $task->save();
            switch($return_uri){
                case  showtask :
                    redirect( taskdisplay/showtask/  . $task->task_id);
                    break;
                case  edittask :
                    redirect( admintask/edittask/  . $task->task_id);
                    break;
                default:
                    redirect( admintask/edittask/  . $task->task_id);
            }

        } else {
            $task->finished_at = null;
            $task->save();
            switch($return_uri){
                case  showtask :
                    redirect( taskdisplay/showtask/  . $task->task_id);
                    break;
                case  edittask :
                    redirect( admintask/edittask/  . $task->task_id);
                    break;
                default:
                    redirect( admintask/edittask/  . $task->task_id);
            }
        }
    } else {
        $task = Task::find($id);
        if($task->finished_date == null && $task->taskcomplete == 0){
            $task->finished_date = date("Y-m-d H:i:s", time());
            $task->taskcomplete = 1;
            $task->save();
            redirect( admintask/edittask/  . $task->id);
        } else {
            $task->finished_date = null;
            $task->taskcomplete = 0;
            $task->save();      
            redirect( admintask/edittask/  . $task->id);
        }

    }


}
问题回答

暂无回答




相关问题
Entity Framework with File-Based Database

I am in the process of developing a desktop application that needs a database. The application is currently targeted to SQL Express 2005 and works wonderfully. However, I m not crazy about having ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How are Models (in MVC) and DAOs supposed to interact?

How are models and DAOs supposed to interact? I m in the process of putting together a simple login module and I m unsure where to put the "business logic." If I put the logic with the data in the ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签