如何在cakephp 2.0中保留我的产品ID

如何在cakephp 2.0中保留我的产品ID,cakephp,cakephp-2.0,Cakephp,Cakephp 2.0,我有两张桌子位置和汽车,我想要的是: 当我点击汽车图片时(View/Cars/View.ctp) 重定向到位置添加表单(View/Locations/add.ctp),同时保留我先前选择的汽车ID 您必须使用cakephpHtmlhelper在url中传递汽车的id 在您的/Views/Car/view.ctp中添加 echo $this->Html->image("cars/car_id.jpg", array( "alt" => "Cars", 'url'

我有两张桌子
位置
汽车
,我想要的是:

  • 当我点击汽车图片时(View/Cars/View.ctp)

  • 重定向到位置添加表单(View/Locations/add.ctp),同时保留我先前选择的汽车ID


您必须使用cakephp
Html
helper在url中传递汽车的
id

在您的
/Views/Car/view.ctp中添加

echo $this->Html->image("cars/car_id.jpg", array(
    "alt" => "Cars",
    'url' => array('controller' => 'locations', 'action' => 'add', car_id)
));
在您的
控制器/位置\u controller.ctp

function add($car_id){
    $this->set('car_id', $car_id);
    //Or do what ever you want with the id
}
更新

在你看来,改变这个说法

echo $this->Html->input("cars/car_id", array(
    "alt" => "Cars",
    'url' => array('controller' => 'locations', 'action' => 'add', 'car_id')
));
对此

echo $this->Html->image("cars/".$car['Car']['id'].".jpg", array(
    "alt" => "Cars",
    'url' => array('controller' => 'locations', 'action' => 'add', $car['Car']['id'])
));
请注意,我假设您的图像文件夹结构,请告诉我这是否有效。

这是位置控制器
此位置/add.ctp:

请分享您现有的汽车代码/view.ctp、carscocontroller-view方法、locations/add.ctp和locationscocontroller-add方法。这是Car/view.ctp:请编辑您的问题并添加代码片段,您可以编辑您的答案以设置该尾码的格式,因为您可以看到,评论中的内容不可读。另外,如果不是答案,请将其添加到您的问题中,而不是作为答案。我现在发布了所有类:locationscontroller、carscontroller、cars/view.ctp和locations/view.ctp,不,她不工作,问题如下: