CakePHP保存无格式 [英] CakePHP save without form

查看:111
本文介绍了CakePHP保存无格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个照片库我想设置一张图片作为专辑的封面。我在相册表中有一个字段cover_id,已通过模型链接到照片。我把album_id和photo_id传递给控制器​​。我想更新通过参数传递的album.cover_id,通过params传递的photo_id。有没有办法做到这一点,或者一种方式使链接成为一个形式,而不是看起来像或改变很多的CSS?

I have a photo gallery I'm trying to set a picture as the cover for the album. I have a field cover_id in the albums table that has already been linked to the photos through the model. I'm passing the album_id and photo_id to the controller. I want to update the album.cover_id passed thru the params with the photo_id passed thru the params. Is there a way to do this or a way to make the link a form without having it look like or form or changing much of the CSS?

推荐答案

保存数据和表单是两个独立的事情,你可以使用一个没有其他。您可以通过POST(通常是表单)或GET(在URL中)将变量从浏览器传递到服务器。混合和匹配,做任何你想做的。例如:

Saving data and forms are two separate things, you can use one without the other. You can pass variables from the browser to the server either via POST (usually a form) or GET (in the URL). Mix and match that to do whatever you want to do. For example:

echo $html->link('Set as cover', array('controller' => 'albums', 'action' => 'set_cover', 42, 123));




URL: / albums / set_cover / 42 / 123



class AlbumsController extends AppController {

    function set_cover($album_id, $photo_id) {
        $this->Album->save(array('id' => $album_id, 'cover_id' => $photo_id));
    }

}

这篇关于CakePHP保存无格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆