Hei,
holder på å prøve å lære meg php oop, og det har gått ok greit. Men har støtt på et problem jeg har sett meg blind på. Håper noen codegenier her inne kunne se over for å finne feilen som gir:
"faen... firma existerer ikke tydeligvis...
Firmanavn:
Notice: Undefined variable: cdata in /Applications/XAMPP/xamppfiles/htdocs/utvikling/cprofile.php on line 22
Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/utvikling/cprofile.php on line 22
Firma id:
Notice: Undefined variable: cdata in /Applications/XAMPP/xamppfiles/htdocs/utvikling/cprofile.php on line 23
Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/utvikling/cprofile.php on line 23
"
Har echoet ut for å finne ut hvor det failer, og har markert det i koden.
Her er filene mine:
cprofile.php
Company.php
Tror det skal være all koden det er problem i, om jeg tar feil så kan jeg legge ut det som trengs. Databasen har feltene: cid, cname, cjoined
Håper noen her inne kan se over. tusen takk
Tablenavnet er forøvrig: companies
Fant noen feil selv, her er oppdatert Company.php (fremdles samme feilmelding)
holder på å prøve å lære meg php oop, og det har gått ok greit. Men har støtt på et problem jeg har sett meg blind på. Håper noen codegenier her inne kunne se over for å finne feilen som gir:
"faen... firma existerer ikke tydeligvis...
Firmanavn:
Notice: Undefined variable: cdata in /Applications/XAMPP/xamppfiles/htdocs/utvikling/cprofile.php on line 22
Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/utvikling/cprofile.php on line 22
Firma id:
Notice: Undefined variable: cdata in /Applications/XAMPP/xamppfiles/htdocs/utvikling/cprofile.php on line 23
Notice: Trying to get property of non-object in /Applications/XAMPP/xamppfiles/htdocs/utvikling/cprofile.php on line 23
"
Har echoet ut for å finne ut hvor det failer, og har markert det i koden.
Her er filene mine:
cprofile.php
Kode
<?php require_once 'core/init.php'; if(!$cname = Input::get('company')) { //Redirect::to('index.php'); echo "$cname er best"; } else { $company = new Company($cname); if(!$company->existsCompany()) { echo 'faen... firma existerer ikke tydeligvis...'; // DET ER TYDELIGVIS HER DET FAILER... NOE ER GALT MED ELSE STATMENTET MITT.... :( //Redirect::to(404); } else { $cdata = $company->dataCompany(); } ?> <h3>Firmanavn:<?php echo escape($cdata->cname); ?></h3> <p>Firma id: <?php echo escape($cdata->cid); ?></p> <?php }
Kode
<?php class Company { private $_db, $_cdata; public function updateCompany($fields = array(), $id = null) { if(!$id && $this->isLoggedIn()) { $id = $this->data()->id; } if(!$this->_db->update('companies', $id, $fields)) { throw new Exception('There was a problem updating the company.'); } } public function createCompany($fields = array()) { if(!$this->_db->insert('companies', $fields)) { throw new Exception('There was a problem creating a new company.'); } } public function findCompany($company = null) { if($company) { $field = (is_numeric($company)) ? 'id' : 'username'; $data = $this->_db->get('companies', array($field, "=", $company)); if($data->count()) { $this->_data = $data->first(); return true; } } return false; } public function existsCompany() { return (!empty($this->_data)) ? true : false; } public function dataCompany() { return $this->_data; } }
Håper noen her inne kan se over. tusen takk
Tablenavnet er forøvrig: companies
Fant noen feil selv, her er oppdatert Company.php (fremdles samme feilmelding)
Kode
<?php class Company { private $_db, $_cdata; public function updateCompany($fields = array(), $id = null) { if(!$this->_db->update('companies', $id, $fields)) { throw new Exception('There was a problem updating the company.'); } } public function createCompany($fields = array()) { if(!$this->_db->insert('companies', $fields)) { throw new Exception('There was a problem creating a new company.'); } } public function findCompany($company = null) { if($company) { $field = (is_numeric($company)) ? 'id' : 'cname'; $cdata = $this->_db->get('companies', array($field, "=", $company)); if($cdata->count()) { $this->_cdata = $cdata->first(); return true; } } return false; } public function existsCompany() { return (!empty($this->_cdata)) ? true : false; } public function dataCompany() { return $this->_cdata; } }
Sist endret av SecondLife; 20. juni 2014 kl. 15:29.
Grunn: Automatisk sammenslåing med etterfølgende innlegg.