开发者

How to display Session data and How to save session data to corresponding database tables in cakePHP

开发者 https://www.devze.com 2023-02-15 14:20 出处:网络
I want to display the students added, how to do this and I want to save all the students into database table students. And one more table called order which has relation with the the student domain cl

I want to display the students added, how to do this and I want to save all the students into database table students. And one more table called order which has relation with the the student domain class as below

class Order extends AppModel { 
    var $name="Ord开发者_JAVA百科er"; 
    var $belongsTo = array( 
        'Student' => array( 
            'className' =>'Student', 
            'foreignKey' => 'StudentId'
        )
    );
}

class Student extends AppModel { 
    var $name='Student'; 
    var $hasOne = array( 
        'Order' => array( 
            'className' => 'Order', 
            'foreignKey' => 'StudentId'
        )
    );
}

and I have created relation in database that foreign key studentId of order table references Id column of Student table. So now how to save both associated models?


you must pass a correct formatted data to save method of your model.

data format is something like

$data = array('Modelname' => array(
                   'col1'=>'val1',
                   'col1'=>'val2' )
             );
0

精彩评论

暂无评论...
验证码 换一张
取 消