Several functions that will do the same thing

0

I have the following function

function about_about(){
    $this->render();
}

However, I have another 100 pages, which will only have render() , how can I make a function just to save code and time? Where I define the pages that will be displayed and give render() , remembering that about_about , in this example, is the name of the page that comes with url , in this case, the method name.

    
asked by anonymous 08.06.2016 / 02:57

1 answer

2

Yes, using the concept of Object Inheritance , which is part of the < a href="http://php.net/manual/en_us/language.oop5.php"> object orientation .

To create the class inheritance you can do this:

Create a file, for example: comum.php , with the following content:

<?php
class base  extends CI_Controller {
    function render() {
        echo 'Comum a todas as classes.';
    }
}

In your controller, you will use:

<?php
include 'comum.php'; // incluir o arquivo da classe base
$about = new base();
$about->render();

The result will be the output of the method that was extended from the base class:

Comum a todas as classes.

I hope to have helped and wish good luck on your project!

    
08.06.2016 / 13:26