-1

大家好,我有一个 cakephp 页面,当您将鼠标悬停在链接上时,它会显示正确的链接,但是当您单击该链接时,它会将您带到一个完全不同/错误的页面。

我认为这是我的观点错误,所以我将在此处包含网站的相关部分,正在发生的事情是add link让用户fields/view不要fields/add_new

        <tr>
                <td align='center'><?php echo $templates['Template']['name'] ;?></td>
            <td align='center'><?php echo $templates['Template']['description']; ?> </td>
                <td align='center'>
                    <?php echo $this->Form->Html->link('Add', array('controller' => 'Fields','action'=>'add_new',$templates['Template']['id'])); ;?> |
                    <?php echo $this->Form->Html->link('View', array('controller' => 'Fields','action'=>'view',$templates['Template']['id'])); ;?> |
                    <?php echo $this->Form->Html->link('Edit', array('controller' => 'Templates','action'=>'edit',$templates['Template']['id'])); ;?> |
                    <?php echo $this->Form->Html->link('Delete', array('controller' => 'Templates','action'=>'delete',$templates['Template']['id'])); ;?></td> 
         <tr>





function add_new($id=null){
        //allows users to add another field to an existing template
        $this->set('title_for_layout', 'Create Fields');
        $this->set('stylesheet_used', 'homestyle');
        $this->set('image_used', 'eBOXLogoHome.png');
        $this->layout='home_layout';


        if(($this->Field->save($this->request->data)))
        {

        $id = $this->data['Field']['template_id'];

        $this->set('id',$id);
        $this->redirect(array('controller'=>'Fields', 'action'=>'view',$id));

        }
            $this->set('id',$id);
        }
4

2 回答 2

0

link函数是HtmlHelper类的一部分。所以你需要->Form从你的函数调用中删除:

<?php echo $this->Html->link('Add', array('controller' => 'fields', 'action'=>'add_new',$templates['Template']['id'])); ;?>

此外,Cake 约定要求控制器名称为小写,因此将控制器指定为:

('controller' => 'fields',

并不是

('controller' => 'Fields',

于 2012-10-01T01:09:43.407 回答
0
function add_new($id=null){
        //allows users to add another field to an existing template
        $this->set('title_for_layout', 'Create Fields');
        $this->set('stylesheet_used', 'homestyle');
        $this->set('image_used', 'eBOXLogoHome.png');
        $this->layout='home_layout';


        //this sets the parameter as a variable 
        $this->set('id', $id);
        //if the data posts to the databse
        if($this->request->is('post'))
        {
            //creates an instance of field in the database
            $this->Field->create(); 
            //if the field saves to the database
            if ($this->Field->save($this->request->data))
            {   //if the user clicks this button
                $id = $this->data['Field']['template_id'];

                $this->set('id',$id);
                $this->redirect(array('controller'=>'Fields', 'action'=>'view',$id));


            }

        }

    }
于 2012-10-01T09:50:41.140 回答