Class CComponent
CComponent is the base class for all components.
CComponent implements the protocol of defining, using properties and events.
A property is defined by a getter method, and/or a setter method. Properties can be accessed in the way like accessing normal object members. Reading or writing a property will cause the invocation of the corresponding getter or setter method, e.g
$a=$component->text; // equivalent to $a=$component->getText(); $component->text='abc'; // equivalent to $component->setText('abc');
The signatures of getter and setter methods are as follows,
// getter, defines a readable property 'text' public function getText() { ... } // setter, defines a writable property 'text' with $value to be set to the property public function setText($value) { ... }
An event is defined by the presence of a method whose name starts with 'on'. The event name is the method name. When an event is raised, functions (called event handlers) attached to the event will be invoked automatically.
An event can be raised by calling CComponent::raiseEvent()
method, upon which the
attached event handlers will be invoked automatically in the order they are
attached to the event. Event handlers must have the following signature,
function eventHandler($event) { ... }
where $event includes parameters associated with the event.
To attach an event handler to an event, see CComponent::attachEventHandler()
. You
can also use the following syntax:
$component->onClick=$callback; // or $component->onClick->add($callback);
where $callback refers to a valid PHP callback. Below we show some callback examples:
'handleOnClick' // handleOnClick() is a global function array($object,'handleOnClick') // using $object->handleOnClick() array('Page','handleOnClick') // using Page::handleOnClick()
To raise an event, use CComponent::raiseEvent()
. The on-method defining an event is
commonly written like the following:
public function onClick($event) { $this->raiseEvent('onClick',$event); }
where <span class="php-var">$event</span>
is an
instance of CEvent
or its child class. One can then raise the event by
calling the on-method instead of CComponent::raiseEvent()
directly.
Both property names and event names are case-insensitive.
CComponent supports behaviors. A behavior is an instance of IBehavior
which is attached to a component. The methods of the behavior can be invoked as
if they belong to the component. Multiple behaviors can be attached to the same
component.
To attach a behavior to a component, call CComponent::attachBehavior()
; and to
detach the behavior from the component, call CComponent::detachBehavior()
.
A behavior can be temporarily enabled or disabled by calling CComponent::enableBehavior()
or CComponent::disableBehavior()
, respectively. When disabled, the
behavior methods cannot be invoked via the component.
Starting from version 1.1.0, a behavior's properties (either its public member variables or its properties defined via getters and/or setters) can be accessed through the component it is attached to.
Direct known subclasses
CAccessRule, CAction, CBehavior, CCacheDependency, CChainedCacheDependency, CChainedLogFilter, CConsoleCommand, CConsoleCommandRunner, CDataProvider, CDataProviderIterator, CDateFormatter, CDbColumnSchema, CActiveFinder, CDbCommand, CDbCommandBuilder, CDbCriteria, CDbDataReader, CDbExpression, CDbMigration, CDbSchema, CDbTableSchema, CDbTransaction, CEvent, CApplicationComponent, CFilter, CFormElement, CGettextFile, CGridColumn, CHttpCookie, CList, CLocale, CLogFilter, CLogger, CLogRoute, CAuthAssignment, CMap, CMemCacheServerConfiguration, CModel, CModule, CNumberFormatter, CPagination, CQueue, CSort, CStack, CTheme, CAuthItem, CUploadedFile, CValidator, CWebService, CWsdlGenerator, Expression, FieldFormatterBase, FieldInputRenderer, JSONResponse, MassAction, MobileRecentItems, CBaseActiveRelation, PanelItem, QueryParamGenerator, RequestUtil, TranslationLogger, X2FlowItem, X2StaticDropdown, X2StaticField, CBaseController, CBaseUrlRule, CBaseUserIdentityIndirect known subclasses
Accounts, AccountsController, ActionMetaData, CDbConnection, CDbFixtureManager, CDbHttpSession, CDbLogRoute, CDbMessageSource, CDefaultValueValidator, CDetailView, CDirectoryCacheDependency, CDummyCache, CEAcceleratorCache, ActionOverdueTrigger, CEmailLogRoute, CEmailValidator, CErrorEvent, CErrorHandler, CExceptionEvent, CExistValidator, CExpressionDependency, CExtController, CFileCache, CFileCacheDependency, Actions, CFileLogRoute, CFileValidator, CFilterChain, CFilterValidator, CFilterWidget, CFlexWidget, CForm, CFormatter, CFormButtonElement, CFormElementCollection, ActionsController, CFormInputElement, CFormModel, CFormStringElement, CGettextMessageSource, CGettextMoFile, CGettextPoFile, CGlobalStateCacheDependency, CGridView, Changelog, ChartSetting, ActionsGridViewProfileWidget, ChartsModule, ChartWidget, CHasManyRelation, CHasOneRelation, ChatBox, CHelpCommand, CHtmlPurifier, CHttpCacheFilter, CHttpRequest, CHttpSession, ActionsModule, CInlineAction, CInlineFilter, CInlineValidator, CInputWidget, CJuiAccordion, CJuiAutoComplete, CJuiButton, CJuiDatePicker, CJuiDialog, CJuiDraggable, ActionsQuickCreateRelationshipBehavior, CJuiDroppable, CJuiInputWidget, CJuiProgressBar, CJuiResizable, CJuiSelectable, CJuiSlider, CJuiSliderInput, CJuiSortable, CJuiTabs, CJuiWidget, ActionsWidget, CLinkColumn, CLinkPager, CListPager, CListView, CLocalizedFormatter, CLogRouter, CManyManyRelation, CMarkdown, CMaskedTextField, CMemCache, ActionText, CMenu, CMessageSource, CMissingTranslationEvent, CModelBehavior, CModelEvent, CMssqlColumnSchema, CMssqlCommandBuilder, CMssqlSchema, CMssqlTableSchema, CMultiFileUpload, ActionToRecord, CMysqlColumnSchema, CMysqlCommandBuilder, CMysqlSchema, CMysqlTableSchema, CNumberValidator, COciColumnSchema, COciCommandBuilder, COciSchema, COciTableSchema, CommentsWidget, AccountsGridViewProfileWidget, ActionUncompleteTrigger, CommonControllerBehavior, CommonFieldsBehavior, CommonSiteControllerBehavior, ContactForm, ContactList, ContactMapInlineTags, Contacts, ContactsController, ContactsGridViewProfileWidget, ContactsModule, ActiveDateRangeInput, ContactsNameBehavior, ControllerPermissionsBehavior, COutputCache, COutputEvent, COutputProcessor, CPgsqlColumnSchema, CPgsqlCommandBuilder, CPgsqlSchema, CPgsqlTableSchema, CPhpAuthManager, Admin, CPhpMessageSource, CPortlet, CPradoViewRenderer, CProfileLogRoute, CRangeValidator, CreatePageFormModel, CreateWebFormAction, Credentials, CRedisCache, CRegularExpressionValidator, AdminController, CRequiredValidator, Criteria, CronCommand, CronForm, CryptSetupCommand, CSafeValidator, CSaveRelationsBehavior, CSecurityManager, CSqlDataProvider, CSqliteColumnSchema, AjaxGetModelAutocompleteAction, CSqliteCommandBuilder, CSqliteSchema, CStarRating, CStatePersister, CStatRelation, CStringValidator, CSysLogRoute, CTabView, CTextHighlighter, CThemeManager, AmorphousModel, CTimestampBehavior, CTreeView, CTypedList, CTypedMap, CTypeValidator, CUniqueValidator, CUnsafeValidator, CUrlManager, CUrlRule, CUrlValidator, Api2Controller, CUserIdentity, CViewAction, CViewRenderer, CWebApplication, CWebLogRoute, CWebModule, CWebServiceAction, CWebUser, CWidget, CWidgetFactory, ApiController, CWinCache, CXCache, CZendDataCache, DatabaseBackupAction, DateRangeInputsWidget, DetailView, DocFolders, Docs, DocsController, DocsGridViewProfileWidget, ApiHook, DocsModule, DocViewer, DocViewerProfileWidget, Dropdowns, DummyCommand, EButtonColumnWithClearFilters, EditMobileFormsFormModel, EmailAccount, EmailDeliveryBehavior, EmailDropboxSettings, ApplicationConfigBehavior, EmailOpenTrigger, EmailProgressControl, EmailsWidget, EncryptedFieldsBehavior, ERememberFiltersBehavior, EventActiveForm, EventCommentPublisherFormModel, EventFormModel, EventPublisherFormModel, Events, AccountsModule, ArrayValidator, EventsChartProfileWidget, EventsData, EventsWidget, EventsWidgetFieldFormatter, ExportFixtureCommand, FailedLogins, FieldFormatter, Fields, FileFieldBehavior, FileSystemObjectBehavior, AssociatedMediaBehavior, FileSystemObjectDataProvider, FileUploader, FileUploadsFilter, FiltersForm, FontPickerInput, FormLayout, FormView, GetActionsBetweenAction, GetItemsAction, GlobalCSSFormModel, Attachments, GlobalImportFormModel, GMailAccount, GoogleProject, GridViewDbSettingsBehavior, GridViewSessionSettingsBehavior, GridViewWidget, Groups, GroupsController, GroupsModule, GroupToUser, AutomaticTranslationCommand, History, IframeWidget, ImportExportBehavior, Imports, InboundEmailTrigger, InlineActionForm, InlineEmail, InlineEmailAction, InlineEmailForm, InlineEmailModelBehavior, BaseDocsMassAction, InlineQuotes, InlineRelationshipsGridView, InlineRelationshipsWidget, InlineTagsWidget, JSONEmbeddedModel, JSONEmbeddedModelFieldsBehavior, JSONFieldsBehavior, JSONFieldsDefaultValuesBehavior, LeadRouting, LeadRoutingBehavior, BaseTagTrigger, LeftWidget, Locations, LoggedTimeWidget, LoginForm, MacroTrigger, MailgunAccount, MailjetAccount, MandrillAccount, Maps, MarketingController, BaseUserTrigger, MarketingGridViewProfileWidget, MarketingModule, MassActionFormModel, MassAddToList, MassCompleteAction, MassMoveFileSysObjToFolder, MassRemoveFromList, MassRenameFileSysObj, MassUncompleteAction, Media, BaseWorkflowStageTrigger, MediaBox, MediaController, MediaFieldFormatter, MediaModule, MediaSelector, MenuList, MessageBox, MigrateCustomCommand, MobileAction, MobileActiveForm, BaseWorkflowTrigger, MobileActiveRecordFieldFormatter, MobileActivityAction, MobileActivityFeedListView, MobileCaptcha, MobileController, MobileCreateAction, MobileDeleteAction, MobileFieldFormatter, MobileFieldInputRenderer, MobileFormLayoutRenderer, BaseX2FlowEmail, MobileIndexAction, MobileLayoutRenderer, MobileLayouts, MobileModule, MobilePagination, MobileProfileViewAction, MobilePublisherAction, MobileRecordIndexPager, MobileResetPasswordAction, MobileTopicsCreateAction, ActionActiveForm, BaseX2FlowWorkflowStageAction, MobileTopicsDeleteReplyAction, MobileTopicsIndexAction, MobileTopicsPager, MobileTopicsUpdateAction, MobileTopicsUpdateReplyAction, MobileTopicsViewAction, MobileUpdateAction, MobileViewAction, MobileViewEventAction, MobileViewLayoutRenderer, BugReports, ModelFileUploader, ModelPermissionsBehavior, ModuleModelNameValidator, ModulePanelItem, Modules, MultiChildNode, MultiTypeAutocomplete, NewListFromSelection, NewWebLeadsGridViewProfileWidget, NormalizedJSONFieldsBehavior, BugReportsController, NoteActiveForm, NoteBox, NoteFormModel, Notes, Notification, NotificationsController, OnlineUsers, OpportunitiesController, OpportunitiesGridViewProfileWidget, OpportunitiesModule, BugReportsModule, Opportunity, OutboundEmailTrigger, OutlookEmailAccount, Panel, PasswordReset, PasswordResetForm, PhoneNumber, Product, ProductFeature, ProductsController, CAccessControlFilter, ProductsModule, Profile, ProfileController, ProfileDashboardManager, ProfileGridViewWidget, ProfileInfo, ProfileLayoutEditor, ProfilesGridViewProfileWidget, ProfileWidgetLayout, Publisher, CActiveDataProvider, PublisherActionTab, PublisherCalendarEventTab, PublisherCallTab, PublisherCommentTab, PublisherEventTab, PublisherSmallCalendarEventTab, PublisherTab, PublisherTimeTab, PublisherWidget, QuickContact, CActiveForm, QuickCreateRelationshipBehavior, QuickCRUDBehavior, Quote, QuoteProduct, QuotesController, QuotesGridViewProfileWidget, QuotesModule, QuotesWidget, RecentItemPanelItem, RecentItems, CActiveRecord, RecordAliases, RecordAliasesCreateAction, RecordAliasesDeleteAction, RecordAliasesWidget, RecordCreateTrigger, RecordDeleteTrigger, RecordIndexListView, RecordLimitBehavior, RecordTagAddTrigger, RecordTagRemoveTrigger, CActiveRecordBehavior, RecordUpdateTrigger, RecordView, RecordViewLayoutManager, RecordViewTrigger, RecordViewWidgetLayout, RecordViewWidgetManager, Relationships, RelationshipsBehavior, RelationshipsController, RelationshipsGridModel, CActiveRelation, RelationshipsJoin, RememberPagination, Reminders, RepairUserDataCommand, RequiredIfNotSetValidator, ResponseBehavior, Roles, RoleToPermission, RoleToUser, RoleToWorkflow, ActionActiveFormBase, CalendarController, RunMigrationScriptCommand, SampleDataCommand, SearchController, SearchIndexBehavior, SendgridAccount, ServiceRoutingBehavior, Services, ServicesController, ServicesGridViewProfileWidget, ServicesModule, CalendarEvent, ServiceWebFormDesigner, SESAccount, Session, SessionLog, Settings, SettingsPanelItem, SiteController, SmallCalendar, SmartActiveDataProvider, SmartDataProviderBehavior, CalendarEventActiveForm, SmartSort, Social, SocialForm, SortableWidget, SortableWidgetManager, SortableWidgets, StudioController, TagBehavior, TagCloud, Tags, CalendarEventFormModel, TempFile, Templates, TemplatesController, TemplatesGridViewProfileWidget, TemplatesModule, TestEmailAction, TestEmailActionForm, ThemeBuildCommand, TimeActiveForm, TimeFormModel, CalendarModule, TimeZone, Tips, TopContacts, TopicReplies, Topics, TopicsController, TopicsFieldFormatter, TopicsListView, TopicsModule, TopicsWidgetLayout, CallActiveForm, TopSites, Tours, TrackEmail, TransactionalViewFieldFormatter, TransactionalViewWidget, TransformedFieldStorageBehavior, TriggerLog, TwitterApp, TwitterFeed, TwitterFeedWidget, CallFormModel, TwoColumnSortableWidgetManager, UpdateCommand, UpdaterAction, UpdaterBehavior, UpdaterPackageCommand, UpdateStageAction, UploadLogoFormModel, URL, User, UserIdentity, CallsWidget, UserLoginTrigger, UserLogoutTrigger, UsersChartProfileWidget, UsersController, UsersModule, ValidLinkValidator, ViewLog, WebActivityWidget, WebForm, WebFormAction, Campaign, WebFormDesigner, WebLeadFormDesigner, WebleadTrigger, WebUpdaterAction, WidgetLayout, Widgets, Workflow, WorkflowBehavior, WorkflowCompleteStageTrigger, WorkflowCompleteTrigger, CampaignAttachment, WorkflowController, WorkflowModule, WorkflowRevertStageTrigger, WorkflowStage, WorkflowStageDetailsWidget, WorkflowStartStageTrigger, WorkflowStartTrigger, X2ActiveForm, X2ActiveGridView, X2ActiveGridViewForSortableWidgets, ActionCompleteTrigger, CampaignEmailClickTrigger, X2ActiveRecord, X2ActiveRecordBehavior, X2ActiveRecordFieldFormatter, X2AddressBehavior, X2AjaxHandlerFilter, X2AssetManager, X2AuthCache, X2AuthManager, x2base, X2BaseListViewBehavior, CampaignEmailOpenTrigger, X2ButtonColumn, X2CalendarPermissions, X2ChangeLogBehavior, X2CheckBoxColumn, X2ConditionList, X2ConsoleCommand, X2Controller, X2ControllerBehavior, X2ControllerPermissionsBehavior, X2DataColumn, CampaignMailingBehavior, X2DataColumnGeneric, X2DbCriteria, X2DuplicateBehavior, X2FileCache, X2FixtureManager, X2Flow, X2FlowAction, X2FlowApiCall, X2FlowCreateAction, X2FlowCreateEvent, CampaignUnsubscribeTrigger, X2FlowCreateNotif, X2FlowEmail, X2FlowRecordComment, X2FlowRecordCreate, X2FlowRecordCreateAction, X2FlowRecordDelete, X2FlowRecordListAdd, X2FlowRecordListRemove, X2FlowRecordReassign, X2FlowRecordTag, CApcCache, X2FlowRecordUpdate, X2FlowSplitter, X2FlowSwitch, X2FlowTrigger, X2FlowTriggerBehavior, X2FlowWorkflowCompleteStage, X2FlowWorkflowRevertStage, X2FlowWorkflowStartStage, X2FormModel, X2GridView, CApplication, X2GridViewBase, X2GridViewFieldFormatter, X2GridViewForSortableWidgets, X2GridViewGeneric, X2GridViewMassActionAction, X2GridViewSortableWidgetsBehavior, X2HttpRequest, X2Leads, X2LeadsController, X2LeadsDataColumn, CArrayDataProvider, X2LeadsGridViewProfileWidget, X2LeadsModule, X2LinkableBehavior, X2List, X2ListCriterion, X2ListItem, X2ListView, X2MarketingChartModel, X2MergeableBehavior, X2MessageSource, CAssetManager, X2MobileControllerBehavior, X2MobileProfileControllerBehavior, X2MobileQuotesControllerBehavior, X2MobileSiteControllerBehavior, X2MobileTopicsControllerBehavior, X2Model, X2ModelConversionAction, X2ModelConversionBehavior, X2ModelConversionWidget, X2ModelForeignKeyValidator, CAttributeCollection, X2ModelUniqueIndexValidator, X2NonWebUser, X2PermissionsBehavior, X2PillBox, X2PipelineChartModel, X2ProgressBar, X2SalesChartModel, X2Settings, X2SmartSearchModelBehavior, X2StarRating, CAuthManager, X2StaticFieldsBehavior, X2TimestampBehavior, X2TranslationBehavior, X2UrlManager, X2UrlRule, X2UrlValidator, X2Validator, X2WebApplication, X2WebModule, X2WebUser, ActionFormModel, CBaseListView, X2Widget, X2WidgetBehavior, X2WidgetList, YahooEmailAccount, CBasePager, CBelongsToRelation, CBooleanValidator, CBreadcrumbs, CButtonColumn, CCache, CCacheHttpSession, CCaptcha, CCaptchaAction, ActionFormModelBase, CCaptchaValidator, CCheckBoxColumn, CClientScript, CClipWidget, CCompareValidator, CConfiguration, CConsoleApplication, CConsoleCommandBehavior, CConsoleCommandEvent, CContentDecorator, ActionMenu, CController, CCookieCollection, CCubridColumnSchema, CCubridSchema, CCubridTableSchema, CDataColumn, CDateValidator, CDbAuthManager, CDbCache, CDbCacheDependencyCopyright: 2008-2013 Yii Software LLC
License: http://www.yiiframework.com/license/
Author: Qiang Xue <qiang.xue@gmail.com>
Since: 1.0
Located at x2engine/framework/base/CComponent.php
public
mixed
|
#
__get( string $name )
Returns a property value, an event handler list or a behavior based on its name. Do not call this method. This is a PHP magic method that we override to allow using the following syntax to read a property or obtain event handlers: $value=$component->propertyName; $handlers=$component->eventName; |
public
mixed
|
|
public
boolean
|
|
public
mixed
|
|
public
mixed
|
|
public
|
|
public
|
#
attachBehaviors( array $behaviors )
Attaches a list of behaviors to the component. Each behavior is indexed by
its name and should be an instance of array( 'class'=>'path.to.BehaviorClass', 'property1'=>'value1', 'property2'=>'value2', ) |
public
|
|
public
|
#
attachBehavior( string $name, mixed $behavior )
Attaches a behavior to this component. This method will create the behavior
object based on the given configuration. After that, the behavior object will be
initialized by calling its |
public
|
#
detachBehavior( string $name )
Detaches a behavior from the component. The behavior's |
public
|
|
public
|
|
public
|
#
enableBehavior( string $name )
Enables an attached behavior. A behavior is only effective when it is enabled. A behavior is enabled when first attached. |
public
|
#
disableBehavior( string $name )
Disables an attached behavior. A behavior is only effective when it is enabled. |
public
boolean
|
#
hasProperty( string $name )
Determines whether a property is defined. A property is defined if there is a getter or setter method defined in the class. Note, property names are case-insensitive. |
public
boolean
|
#
canGetProperty( string $name )
Determines whether a property can be read. A property can be read if the class has a getter method for the property name. Note, property name is case-insensitive. |
public
boolean
|
#
canSetProperty( string $name )
Determines whether a property can be set. A property can be written if the class has a setter method for the property name. Note, property name is case-insensitive. |
public
boolean
|
|
public
boolean
|
|
public
|
|
public
|
|
public
boolean
|
#
detachEventHandler( string $name, callable $handler )
Detaches an existing event handler. This method is the opposite of |
public
|
#
raiseEvent( string $name,
Raises an event. This method represents the happening of an event. It invokes all attached handlers for the event. |
public
mixed
|
#
evaluateExpression( mixed $_expression_, array $_data_ = array() )
Evaluates a PHP expression or callback under the context of this component. |