Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • AccountsGridViewProfileWidget
  • ActionMenu
  • ActionsGridViewProfileWidget
  • ActionsQuickCreateRelationshipBehavior
  • ActiveDateRangeInput
  • ApplicationConfigBehavior
  • Attachments
  • ChatBox
  • CommonControllerBehavior
  • ContactMapInlineTags
  • ContactsGridViewProfileWidget
  • CronForm
  • CSaveRelationsBehavior
  • DateRangeInputsWidget
  • DocsGridViewProfileWidget
  • DocViewer
  • DocViewerProfileWidget
  • EButtonColumnWithClearFilters
  • EmailDeliveryBehavior
  • EmailProgressControl
  • EncryptedFieldsBehavior
  • EventsChartProfileWidget
  • FileUploader
  • FontPickerInput
  • Formatter
  • FormView
  • GridViewWidget
  • History
  • IframeWidget
  • ImportExportBehavior
  • InlineActionForm
  • InlineEmailAction
  • InlineEmailForm
  • InlineEmailModelBehavior
  • InlineQuotes
  • JSONEmbeddedModelFieldsBehavior
  • JSONFieldsDefaultValuesBehavior
  • LeadRoutingBehavior
  • LeftWidget
  • LoginThemeHelper
  • LoginThemeHelperBase
  • MarketingGridViewProfileWidget
  • MediaBox
  • MessageBox
  • MobileFormatter
  • MobileFormLayoutRenderer
  • MobileLayoutRenderer
  • MobileLoginThemeHelper
  • MobileViewLayoutRenderer
  • ModelFileUploader
  • NewWebLeadsGridViewProfileWidget
  • NormalizedJSONFieldsBehavior
  • NoteBox
  • OnlineUsers
  • OpportunitiesGridViewProfileWidget
  • Panel
  • ProfileDashboardManager
  • ProfileGridViewWidget
  • ProfileLayoutEditor
  • ProfilesGridViewProfileWidget
  • Publisher
  • PublisherActionTab
  • PublisherCalendarEventTab
  • PublisherCallTab
  • PublisherCommentTab
  • PublisherEventTab
  • PublisherSmallCalendarEventTab
  • PublisherTab
  • PublisherTimeTab
  • QuickContact
  • QuickCreateRelationshipBehavior
  • QuotesGridViewProfileWidget
  • RecordAliasesWidget
  • RecordViewLayoutManager
  • RecordViewWidgetManager
  • RememberPagination
  • Reminders
  • ResponseBehavior
  • ResponsiveHtml
  • SearchIndexBehavior
  • ServicesGridViewProfileWidget
  • SmallCalendar
  • SmartActiveDataProvider
  • SmartDataProviderBehavior
  • SmartSort
  • SocialForm
  • SortableWidgetManager
  • SortableWidgets
  • TagBehavior
  • TagCloud
  • TemplatesGridViewProfileWidget
  • TimeZone
  • TopContacts
  • TopSites
  • TransformedFieldStorageBehavior
  • TranslationLogger
  • TwitterFeed
  • TwoColumnSortableWidgetManager
  • UpdaterBehavior
  • UpdatesForm
  • UserIdentity
  • UsersChartProfileWidget
  • WorkflowBehavior
  • X2ActiveGridView
  • X2ActiveGridViewForSortableWidgets
  • X2AssetManager
  • X2AuthManager
  • X2ChangeLogBehavior
  • X2ClientScript
  • X2Color
  • X2DateUtil
  • X2FixtureManager
  • X2FlowFormatter
  • X2GridView
  • X2GridViewBase
  • X2GridViewForSortableWidgets
  • X2GridViewSortableWidgetsBehavior
  • X2LeadsGridViewProfileWidget
  • X2LinkableBehavior
  • X2ListView
  • X2PillBox
  • X2ProgressBar
  • X2SmartSearchModelBehavior
  • X2TimestampBehavior
  • X2TranslationBehavior
  • X2UrlRule
  • X2WebModule
  • X2Widget
  • X2WidgetList
  • Overview
  • Package
  • Class
  • Tree

Class CSaveRelationsBehavior

CSaveRelationsBehavior class.

The CSaveRelationBehavior enables ActiveRecord model to save HasMany and ManyMany relational active records along with the main model

Requirements: Yii Framework 1.0.4 or later

Installation: Extract the release file under protected/components

Usage:

  • Add the following code to the models you wish to add this behavior to:

public function behaviors(){ return array('CSaveRelationsBehavior' => array('class' => 'application.components.CSaveRelationsBehavior')); } In your controler, to save the relations data, simply call $model->setRelationRecords('relationName',$data); $model->save();

  • For ManyMany relations, $data is either an array of foreign key values (ie. array(2,5,43)) or

an array of associative arrays giving the composite foreign keys values of the related model (ie. array(array('pk1'=>2,'pk2'=>'fr'),array('pk1'=>5,'pk2'=>'en')) You will typically get this data from some checkboxes values listing the ids of the related model

  • For HasMany relations, $data should be set as an array of associative arrays giving the attributes values

of the related model (ie. array(array('id'=>123, 'name'=>'someValue', 'visible'=>true), array('id'=>456, 'name'=>'someOtherValue', 'visible'=>false)); You can get this data by using the tabular input technique within the form of the main model (http://www.yiiframework.com/doc/guide/form.table)

In both cases, the foreign keys related to the main model will automatically be populated with its primary key(s) value(s). Most of the time, you will call the setRelationRecords that way: $model->setRelationRecords('relationName',is_array(@$_POST['ModelName']) ? $_POST['ModelName'] : array());

By default, the behavior will handle the save operation in a transactional way so that if anything goes wrong during the save of some related data your relational integrity will not be affected. If you prefer to handle this yourself, you can set the 'transactional' property of the behavior to false. Also, if any error occurs during the save process, the hasError property will be set to true.

Additional features:

  • $model->addSaveRelation('relationName'[,'customErrorMessage'])

You can use this method to force the save of some relation. You can also set the error message of the relation by using the second parameter (see setSaveRelationMessage below)

  • $model->removeSaveRelation('relationName')

Simply do the oposite

  • $model->setSaveRelationMessage('relationName','customErrorMessage')

Set the message to be shown in the error summary of the main model

CComponent
Extended by CBehavior implements IBehavior
Extended by CModelBehavior
Extended by CActiveRecordBehavior
Extended by CSaveRelationsBehavior
Package: application\components
License: CSaveRelationsBehavior
Author: Alban Jubert <alban.jubert@trinidev.fr>
Version: 1.0.3
Link: http://www.trinidev.fr/
Located at x2engine/protected/components/CSaveRelationsBehavior.php
Methods summary
public
# setRelationRecords( mixed $relation, mixed $data = null, mixed $merge = false )
public
# addSaveRelation( mixed $relation, mixed $message = null )
public
# removeSaveRelation( mixed $relation )
public
# setRelationScenario( mixed $relation, mixed $scenario )
public
# setSaveRelationMessage( mixed $relation, mixed $message )
public
# beforeValidate( CModelEvent $event )

Responds to CModel::onBeforeValidate event. Override this method and make it public if you want to handle the corresponding event of the owner. You may set CModelEvent::isValid to be false to quit the validation process.

Responds to CModel::onBeforeValidate event. Override this method and make it public if you want to handle the corresponding event of the owner. You may set CModelEvent::isValid to be false to quit the validation process.

Parameters

$event
CModelEvent
$event event parameter

Overrides

CModelBehavior::beforeValidate()
public
# beforeSave( CModelEvent $event )

Responds to CActiveRecord::onBeforeSave event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner. You may set CModelEvent::isValid to be false to quit the saving process.

Responds to CActiveRecord::onBeforeSave event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner. You may set CModelEvent::isValid to be false to quit the saving process.

Parameters

$event
CModelEvent
$event event parameter

Overrides

CActiveRecordBehavior::beforeSave()
public
# afterSave( CEvent $event )

Responds to CActiveRecord::onAfterSave event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner.

Responds to CActiveRecord::onAfterSave event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner.

Parameters

$event
CEvent
$event event parameter

Overrides

CActiveRecordBehavior::afterSave()
public
# beforeDelete( CEvent $event )

Responds to CActiveRecord::onBeforeDelete event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner. You may set CModelEvent::isValid to be false to quit the deletion process.

Responds to CActiveRecord::onBeforeDelete event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner. You may set CModelEvent::isValid to be false to quit the deletion process.

Parameters

$event
CEvent
$event event parameter

Overrides

CActiveRecordBehavior::beforeDelete()
public
# afterDelete( CEvent $event )

Responds to CActiveRecord::onAfterDelete event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner.

Responds to CActiveRecord::onAfterDelete event. Override this method and make it public if you want to handle the corresponding event of the CBehavior::owner owner.

Parameters

$event
CEvent
$event event parameter

Overrides

CActiveRecordBehavior::afterDelete()
Methods inherited from CActiveRecordBehavior
afterFind(), beforeCount(), beforeFind(), events()
Methods inherited from CModelBehavior
afterConstruct(), afterValidate()
Methods inherited from CBehavior
attach(), detach(), getEnabled(), getOwner(), setEnabled()
Methods inherited from CComponent
__call(), __get(), __isset(), __set(), __unset(), asa(), attachBehavior(), attachBehaviors(), attachEventHandler(), canGetProperty(), canSetProperty(), detachBehavior(), detachBehaviors(), detachEventHandler(), disableBehavior(), disableBehaviors(), enableBehavior(), enableBehaviors(), evaluateExpression(), getEventHandlers(), hasEvent(), hasEventHandler(), hasProperty(), raiseEvent()
Properties summary
public array $relations array()
#
public boolean $transactional true
#
public boolean $hasError false
#
public boolean $deleteRelatedRecords true
#
Magic properties inherited from CActiveRecordBehavior
$owner
Magic properties inherited from CBehavior
$enabled
X2CRM Documentation API documentation generated by ApiGen 2.8.0