Welcome Guest, Not a member yet? Register   Sign In
using abstract classes and static methods
#1

[eluser]keevitaja[/eluser]
Hi,

i wonder how are abstract classes and static methods used in codeigniter? how do you make parent visible to child class? is this ok?

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

abstract class Mscrud {
  private static $db;
  private static $table;
  
  public function __construct() {
    self::$db = &get;_instance()->db;
    self::$table = strtolower(str_replace('_model', '', get_called_class()));
  }
  
  static function get() {
    print self::$table;
  }
}

/* End of file mscrud.php */
/* Location: ./application/models/mscrud.php */

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(APPPATH.'models/mscrud.php');

class Arved_model extends Mscrud {
}

/* End of file arved_model.php */
/* Location: ./application/models/arved_model.php */
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
  function index() {
    $this->load->model('arved_model');
    
    Arved_model::get();
  }
}

/* End of file home.php */
/* Location: ./application/controllers/home.php */
#2

[eluser]keevitaja[/eluser]
anyway, this is the end result:

http://ellislab.com/forums/viewthread/225378/




Theme © iAndrew 2016 - Forum software by © MyBB