Created
August 26, 2010 09:16
-
-
Save clemherreman/551121 to your computer and use it in GitHub Desktop.
Symfony getter overloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Company | |
* | |
* This class has been auto-generated by the Doctrine ORM Framework | |
* | |
* @package winston | |
* @subpackage model | |
* @author Clement Herreman <[email protected]> | |
* @version SVN: $Id$ | |
*/ | |
class Company extends BaseCompany | |
{ | |
/** | |
* Return the Company logo. If none, return the placeholder. | |
*/ | |
public function getLogo() | |
{ | |
if ($this->hasLogo()) | |
return parent::_get('logo'); | |
else | |
return sfConfig::get('app_company_logo_placeholder'); | |
} | |
/** | |
* Tells if this Company has a Logo. | |
* @return bool True if this Company has a logo, else false. | |
*/ | |
public function hasLogo() | |
{ | |
$logo = parent::_get('logo'); | |
//Todo : check if $logo is a readable file | |
return !empty($logo); | |
} | |
public function save(Doctrine_Connection $conn = null) | |
{ | |
if ( $this->hasLogo()) | |
{ | |
//Here some code where I crop the logo, deleted for easy debugging. | |
//ERREUR : at fixtures loading : | |
//SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'company_id' cannot be null | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Company: | |
actAs: | |
Sluggable: | |
fields: [name] | |
unique: true | |
Timestampable: | |
updated: { disabled: true } | |
columns: | |
name: { type: string(255), notnull: true } | |
logo: { type: string } | |
relations: | |
Campaigns: | |
type: many | |
class: Campaign | |
local: id | |
foreign: company_id | |
onDelete: cascade | |
Profiles: | |
type: many | |
class: sfGuardUserProfile | |
local: id | |
foreign: company_id | |
onDelete: cascade | |
Functionnalities: | |
class: Functionnality | |
local: functionnality_id | |
foreign: company_id | |
refClass: Subscription | |
foreignAlias: Companies | |
DefaultMediaSources: | |
class: MediaSource | |
local: id | |
foreign: company_id | |
refClass: CompanyMediaSource | |
foreignAlias: Companies |
For those interested in : the exception can be avoided by replacing $this->_get('logo');
with parent::_get('logo');
See gist.
Thank you @n1k0 !
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remark : I checked my fixtures twice, and even when I keep only the
Company
fixtures, I still get an exception.It only stop crashing when I delete the
$this->hasLogo()
in thesave()
method