Welcome Guest, Not a member yet? Register   Sign In
Problem running a sample application
#1

[eluser]charme[/eluser]
Hi everyone.

I just started with CI and got a problem in realizing a small sample application.
I made an abstract class which extends model. I made this as a base class for my application.
Then i extend a class from that abstract class. And now the problems begin.
If I dont include the abstract class in the new class, i get the error that my abstract class wasnt found. Both are available in the models folder.


The next thing is, if i use a controller which has the same name like the class it is made for. Then i receive a "Cannot redeclare class" error.

I use xampp 1.7.3 and CI 1.7.2

Thank you !


Here is the code of the classes:

Code:
abstract class GObject extends Model{
    var $id;
    var $ObjectState;

    protected function __construct() {
        parent::Model();
        //$this->load->database();
    }
    
    public function getId() {
        return $this->id;
    }

    public function setId($id) {
        $this->id = $id;
    }

    public function getObjectState() {
        return $this->ObjectState;
    }

    public function setObjectState($ObjectState) {
        $this->ObjectState = $ObjectState;
    }

    public abstract function getAll();
}
?>

Code:
include_once 'GObject.php';
class Kunde extends GObject{

   function Kunde(){
       parent::__construct();;
   }  

   public function getAll(){
       $q = $this->db->get('Kunde');
       if($q->num_rows() > 0){
           foreach ($q->result() as $row){
               $data[] = $row;
           }
           return $data;
       }
   }

}


Code:
class Kunde extends Controller{

    function Kunde(){
        parent::Controller();

        //$this->load->scaffolding('Kunde');
    }

    function index(){
        $this->load->model('Kunde');
        $data['query'] = $this->Kunde->getAll();
        $this->load->view('view_kunde', $data);
    }
}
#2

[eluser]techgnome[/eluser]
Right... you can't do this:
class Kunde extends GObject{
and
class Kunde extends Controller{

In short you're declaring the class Kunde as both a lemon and an apple... I'd consider renaming your model.

-tg
#3

[eluser]charme[/eluser]
[quote author="techgnome" date="1284658751"]Right... you can't do this:
class Kunde extends GObject{
and
class Kunde extends Controller{

In short you're declaring the class Kunde as both a lemon and an apple... I'd consider renaming your model.

-tg[/quote]

And what about the problerm with the include?
#4

[eluser]techgnome[/eluser]
the include is fine...

when you include the file, your base class is included... that would be GObject... which you then proceed to extend - again, that's fine.. but the name of the Class is Kunde.... and PHP is telling you "hey wait a minute! You already have defined a class called Kunde" (your controller) ... If you change the name of your Kunde model class, then you should be OK.

Like this:

Code:
include_once 'GObject.php';
class Kunde_model extends GObject{

And then change the loader in the controller:
Code:
$this->load->model('Kunde_model');

-tg
#5

[eluser]charme[/eluser]
ty




Theme © iAndrew 2016 - Forum software by © MyBB