Skip to content

Instantly share code, notes, and snippets.

@clemherreman
Created August 26, 2010 09:16
Show Gist options
  • Save clemherreman/551121 to your computer and use it in GitHub Desktop.
Save clemherreman/551121 to your computer and use it in GitHub Desktop.
Symfony getter overloading
<?php
/**
* Company
*
* This class has been auto-generated by the Doctrine ORM Framework
*
* @package winston
* @subpackage model
* @author Clement Herreman <clement@activcompany.fr>
* @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
}
}
}
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
@clemherreman
Copy link
Author

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 the save() method

@clemherreman
Copy link
Author

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