We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Save multi

Hi all, My problem

foreach ($results as $key => $item) {
                    if ($key > 9) {
                        $MaSV = array(
                            'MaSV'      => $item[1],
                            'MaKhoaHoc' => $MaKhoaHoc,
                            'MaHeDaoTao'=> $MaHeDaoTao,
                            'MaKhoa'    => $MaKhoa,
                            'MaNganh'   => $MaNganh,
                            'MaLop'     => $MaLop,
                            'HoSV'      => $item[2],
                            'TenSV'     => $item[3],
                            'NgaySinh'  => $this->getFormat($item[5]),
                            'NoiSinh'   => $item[6],
                            'Email'     => $item[1].'@gmail.com',
                            'DiaChiTamTru'=>'Chua Xac Dinh',
                            'GhiChu'    => $item[3],           
                        );
                        echo "<pre>";
                        print_r($MaSV);
                        if($Hososinhvien->save($MaSV)==false) {
                        $this->flash->error("Oh No!");
                        }
                        $this->flash->error($Hososinhvien->getMessages());
                    }
                }          

after run code above, it is insert one element record Array one where $MaS

        Array(
        [MaSV] => 1469010007
        [MaKhoaHoc] => 14
        [MaHeDaoTao] => 5
        [MaKhoa] => 12
        [MaNganh] => 905
        [MaLop] => 901
        [oSV] => Tran Duy
        [TenSV] => Tuan
        [NgaySinh] => 1990-08-19
        [NoiSinh] => 
        [Email] => [email protected]
        [DiaChiTamTru] => Chua Xac Dinh
        [GhiChu] => Tuan
    )
    Array
    (
        [MaSV] => 1469010008
        [MaKhoaHoc] => 14
        [MaHeDaoTao] => 5
        [MaKhoa] => 12
        [MaNganh] => 905
        [MaLop] => 901
        [HoSV] => Tran Duy
        [TenSV] => Khanh
        [NgaySinh] => 1990-08-19
        [NoiSinh] => 
        [Email] => [email protected]
        [DiaChiTamTru] => Chua Xac Dinh
        [GhiChu] => Khanh
    )

but [MaSV] => 1469010008 not inser in database, I want to insert two element in array above, Thank all, I doesn't writen English very well



98.9k

The ORM doesn't implement a Table Data Gateway pattern. You have to create one instance per insert:

$Hososinhvien = new Hososinhvien();
if($Hososinhvien->save($MaSV)==false) {
   $this->flash->error("Oh No!");
}