Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何对照它查看数据';cakephp中的关联id?_Php_Html_Cakephp_Cakephp 1.3_Cakephp 2.0 - Fatal编程技术网

如何对照它查看数据';cakephp中的关联id?

如何对照它查看数据';cakephp中的关联id?,php,html,cakephp,cakephp-1.3,cakephp-2.0,Php,Html,Cakephp,Cakephp 1.3,Cakephp 2.0,桌子 我想根据它的相关id查看数据,例如,如果产品有两个计划,它将在该产品的列表中。那样 Tables Product Plan ProductPlan id |name id |name id | product_id | plan_id 1 aplha 1 a 1 1 2 2 bravo 2

桌子

我想根据它的相关id查看数据,例如,如果产品有两个计划,它将在该产品的列表中。那样

    Tables

 Product        Plan            ProductPlan
 id |name       id |name        id  | product_id | plan_id     
 1    aplha      1   a          1        1          2             
 2    bravo      2   b          2        4          c   
 3    charlie    4   c   
 4    delta
查看代码为

      alpha  |  delta   |  
       a          c
       b
)


我该怎么做?提前感谢。

您必须从控制器传递三个变量。 该变量包含三个不同的表数据

我是否理解“产品有许多计划,计划有许多产品”(多对多)()。在这种情况下,必须在模型中声明此关系

 array(
'Product' => array(
    'product_id' => '1',
    'name' => 'Event Manager',
    'slug' => 'event-manager',
    'is_visible' => true
),
'Plan' => array(
    (int) 0 => array(
        'plan_id' => '1',
        'name' => 'FREE',
        'description' => '30 Days Trial',
        'amount' => '0.00',
        'expiry_days' => '30',
        'created' => '2012-01-12 16:51:21',
        'modified' => '2012-01-12 16:51:22',
        'PlansProduct' => array(
            'plan_product_id' => '1',
            'product_id' => '1',
            'plan_id' => '1'
        )
    ),
    (int) 1 => array(
        'plan_id' => '2',
        'name' => 'BRONZE',
        'description' => '60 Days Trial',
        'amount' => '10.00',
        'expiry_days' => '60',
        'created' => '2012-01-12 16:52:24',
        'modified' => '2012-01-12 16:52:25',
        'PlansProduct' => array(
            'plan_product_id' => '2',
            'product_id' => '1',
            'plan_id' => '2'
        )
    )
)
如果关系是“一对多”,则声明如下:

//models/product.php
class Product extends AppModel{
    public $hasAndBelongsToMany = array(
        'Plan' =>
            array(
                'className'              => 'Plan',
                'joinTable'              => 'ProductPlan',
                'foreignKey'             => 'id',
                'associationForeignKey'  => 'id',
                'unique'                 => true,
                'conditions'             => '',
                'fields'                 => '',
                'order'                  => '',
                'limit'                  => '',
                'offset'                 => '',
                'finderQuery'            => '',
                'deleteQuery'            => '',
                'insertQuery'            => ''
            )
    );
}

您需要将一个名为“product_id”的外键添加到“Plan”表中。

但问题是如何设置我需要的视图want@usii在控制器中选择它,使用$this->render(“nameofview”);
//models/product.php
class Product extends AppModel{
    public $hasAndBelongsToMany = array(
        'Plan' =>
            array(
                'className'              => 'Plan',
                'joinTable'              => 'ProductPlan',
                'foreignKey'             => 'id',
                'associationForeignKey'  => 'id',
                'unique'                 => true,
                'conditions'             => '',
                'fields'                 => '',
                'order'                  => '',
                'limit'                  => '',
                'offset'                 => '',
                'finderQuery'            => '',
                'deleteQuery'            => '',
                'insertQuery'            => ''
            )
    );
}
class Product extends AppModel {
    public $hasMany = array(
        'Plan' => array(
            'className'     => 'Plan',
            'foreignKey'    => 'product_id'
        )
    );
}