如何从另一个类更新其他类的函数

问题描述 投票:0回答:1

我可以从其他类调用一个函数,但不能从其他类更新/覆盖它。有没有办法在不同的文件中更新不同文件中其他类的功能。谢谢

file A.php

    class FPDF{

        function header{

            //some code

        }

    }

file B.php

    Class Users extents basecontroller{

        function viewPDF{

            require_once(A.php)

            $pdf = new FPDF

            $pdf->Header()

        }

    }

    require_once(A.php);
    Class PDF extends FPDF
    {
        // Page header
        function Header()
        {
            // Logo
            // Line break
            $this->Ln(100);
        }
     }
php function codeigniter override
1个回答
0
投票

我认为你的文件结构应该是这样的

file A.php
    class FPDF{
        function header{
            //some code
        }
    }


file library/Pdf.php
    require_once(A.php);
    Class Pdf extends FPDF
    {
        // Page header
        function Header()
        {
            // Logo
            // Line break
            $this->Ln(100);
        }
     }  


file Users.php
    Class Users extents basecontroller{
        function viewPDF{
            $this->load->library('pdf');
            $this->pdf->Header()
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.