Ölümcül hata: \ xampp \ htdocs \ giftshoes \ system \ database \ doktrin \ Doctrine \ Record.php hattında 1424 on: C olmayan bir nesne üzerinde bir üye işlev getAttribute () Çağrı

1 Cevap php

I am getting following error message when using Doctrine ORM in Codeigniter. Please help me... ------------------Doctrin Table Defination-------------

abstract class BaseShoes extends Doctrine_Record
{
    public function setTableDefinition()
    {
        $this->setTableName('shoes');
        $this->hasColumn('sku', 'integer', 11, array('primary' => true, 'autoincrement' => false));
        $this->hasColumn('name', 'string', 255);
        $this->hasColumn('keywords', 'string', 255);
        $this->hasColumn('description', 'string');
        $this->hasColumn('manufacturer', 'string', 20);
        $this->hasColumn('sale_price', 'double');
        $this->hasColumn('price', 'double');
        $this->hasColumn('url', 'string');
        $this->hasColumn('image', 'string');
        $this->hasColumn('category', 'string', 50);
    }

    public function setUp() {

    }
}

------------------------ Doctrin Tablo Kodu -------------------

class ShoesTable extends Doctrine_Table
{
    function getAllShoes($from = 0, $total = 15)
    {
        $q = Doctrine_Query::create()
        ->from('Shoes s')
        ->limit($total)
        ->offset($from);

        return $q->execute(array(), Doctrine::HYDRATE_ARRAY);
    }

}

----------------- Model Kodu -----------------

class Shoes extends BaseShoes
{
    function  __construct() {
        $this->table = Doctrine::getTable('shoes');
    }
    public function getAllShoes()
    {
        $this->table->getAllShoes();
    }
}

------------------- HATA Ben -------------------- alıyorum

( ! ) Fatal error: Call to a member function getAttribute() on a non-object in C:\xampp\htdocs\giftshoes\system\database\doctrine\Doctrine\Record.php on line 1424
Call Stack
#   Time    Memory  Function    Location
1   0.0011  327560  {main}( )   ..\index.php:0
2   0.0363  3210720 require_once( 'C:\xampp\htdocs\giftshoes\system\codeigniter\CodeIgniter.php' )  ..\index.php:116
3   0.0492  3922368 Welcome->Welcome( ) ..\CodeIgniter.php:201
4   0.0817  6234096 CI_Loader->model( ) ..\welcome.php:14
5   0.0824  6248376 Shoes->__construct( )   ..\Loader.php:184
6   0.0824  6248424 Doctrine_Core::getTable( )  ..\Shoes.php:5
7   0.0824  6248424 Doctrine_Connection->getTable( )    ..\Core.php:1080
8   0.0824  6254304 Doctrine_Table->__construct( )  ..\Connection.php:1123
9   0.0841  6396128 Doctrine_Table->initDefinition( )   ..\Table.php:249
10  0.0841  6397472 Shoes->__construct( )   ..\Table.php:301
11  0.0841  6397680 Doctrine_Access->__set( )   ..\Access.php:0
12  0.0841  6397680 Doctrine_Record->set( ) ..\Access.php:60

1 Cevap

Sanırım bu:

  • Shoes extends BaseShoes - Evet, biz görebilirsiniz
  • BaseShoes extends Doctrine_Record

Doctrine_Record bir sürü şey yapan bir __construct() yöntemi vardır.

Eğer Eğer sınıfların birinde __construct() yöntemini yeniden tanımlamak, kendi üst sınıfında tanımlanmış oluyor __construct() yöntemini geçersiz kılar.


Here :

  • Lütfen Shoes::__construct() yöntemi
  • overrides BaseShoes::__construct()
  • kendisini yok ki, bu Doctrine_Record::__construct() ile aynıdır
  • olan bazı oldukça önemli Doktrin ile ilgili şeyler yapmak gibi görünüyor ;-)


Not tested, but calling the parent's constructor in your own constructor could help :

class Shoes extends BaseShoes
{
    function  __construct() {
        parent::__construct();
        $this->table = Doctrine::getTable('shoes');
    }
    public function getAllShoes()
    {
        $this->table->getAllShoes();
    }
}


And, as a reference, quoting the Constructors and Destructors page of the PHP manual :

Note: Parent constructors are not called implicitly if the child class defines a constructor.
In order to run a parent constructor, a call to parent::__construct() within the child constructor is required.


Still, as a sidenote, I am not sure that defining your own constructor in a Model class, with Doctrine, is such a good idea -- and I've never seen this done, actually, as far as I remember...

Ve burada bir blog-post on the Doctrine's blog , that seems to indicate I'm right (quoting, emphasis mine):

[...] someone asked about the constructor of entities in Doctrine 2 and whether or not it could be used.
I think this is something worth writing about since in Doctrine 1 this was not possible. The constructor was hi-jacked from you and used internally by Doctrine.


And here's the section of Doctrine's 1.2 manual that's relevant : Overriding the Constructor :

Doctrine doesn't allow you to override the Doctrine_Record::__construct() method but provides an alternative
[...]