在MVC中,更新操作不起作用并存储值

时间:2016-05-20 11:12:40

标签: php sql model-view-controller

我从朋友那里接过一份工作。现在我正在研究MVC,我制作了一个看起来像他的表格:

<form method="post" action="QA/public/index.php?controller=QA&action=shabUpdate">
    <table class="clean">
        {data}
        <tr style="display:{display};">
            <td class="label">Specific:</td>
            <td>{remarks}</td>
        </tr>
    </table>

    {back}
    <input type="submit" />
</form>

在我的控制器中,我做了以下shabUpdateAction:

protected function shabUpdateAction()
    {
        $_POST['titel'] = $_POST['titel'];
        /*$_POST['inspectie'] = 'so sorry';
        $_POST['extraDocument'] = 'newIMG';*/

        $this->dbh->setShab($_POST, $_POST['partId']);

        $_SESSION['page'] = './QA/public/index';
        $_SESSION['getIndex'] = '?controller=QA&action=showInspectionDocument&templateId='.$_POST['templateId'];

        header('Location: http://stuffff/something/');
        exit();
    }

这是为了更新我的表单,当我访问表单页面时,我应该能够看到新信息(所做的新更改)。 但是,更新操作不起作用,并且不会重定向到正确的页面。

这是我的模型的一部分:

public function updateSshab($sdr)
    {
        $sql = "UPDATE `qa_template` 
                SET `inspection_requirement` = :requirement
                WHERE `part_id` = :partId AND `title` = :title;";
        $statement = $this->dbh->prepare($sql);
        $statement->bindParam(':requirement', $sdr['defectDescription']);
        $statement->bindParam(':partId', $sdr['partId']);
        $statement->bindValue(':title', 'SDR nummer: SDR' .$sdr['nr']);
        $statement->execute();      
    }

最后我的观点:

public function renderShowInspectionDocument()
    {
        setLastPage();

        $dochtml = '';


        $url = str_replace(end(explode('/', $_SERVER['HTTP_REFERER'])), '', $_SERVER['HTTP_REFERER']);
        //Template
        $template = file_get_contents('templates/inspectionDetails.tpl');

        //shab
        if(isset($this->data['shab']))
        {
            $shab= $this->data['shab']; 

            $dochtml .= '

                <tr>
                    <td class="label">Inspection:</td>
                    <td>
                        <input type="hidden" name="templateId" value="'.$shab['id'].'" />
                    <div id="testDiv" style="width:420px; font-weight:normal; border-left:1px solid black; border-bottom:1px solid black; padding:5px;"><a href="javascript:changeDiv(\'testDiv\', \'testDiv2\');" title="change" class="edit">'. nl2br($shab['inspection_requirement']) .'</a></div>

                    <div id="testDiv2" style="display=none">
                        <textarea name="inspection" class="width">'. nl2br($shab['inspection_requirement']) .'</textarea>
                    </div>
                    </td>
                </tr>
                <tr>
                    <td class="label">Inspection-tools:</td>
                    <td>
                        <input type="hidden" name="templateId" value="'.$shab['id'].'" />
                    <div id="testDiv22" style="width:420px; font-weight:normal; border-left:1px solid black; border-bottom:1px solid black; padding:5px;"><a href="javascript:changeDiv(\'testDiv22\', \'testDiv222\');" title="chang" class="edit">'. nl2br($shab['inspection_resources'])  .'</a></div>
                    <div id="testDiv222" style="display=none">
                        <textarea name="InspectieResources" class="width">'. nl2br($shab['inspection_resources']) .'</textarea>
                    </div>
                    </td>   
                </tr>           
                ';
        }

        $template = str_replace('{data}', $dochtml, $template);
        $template = str_replace('{terug}', backButtonQA(), $template);
        $template = str_replace('{display}', 'none', $template);
        echo $template;
    }

我的更新功能无法正常工作。我没有写nu我正在研究它我似乎无法弄清楚更新Action的问题,是否有我遗漏的东西?

0 个答案:

没有答案