yii自定義元件

2021-10-11 11:04:14 字數 2358 閱讀 6923

1.我們在backend檔案下新建components目錄作為自定義元件的檔案

2.然後再資料夾下新建sms.php檔案,檔案中的**為

<?php

namespace

backend\components

;use

yii\base\component

;class

sm***tends

component

}

3.配置檔案中配置

'sms123'

=>

['class'

=>

'backend\components\sms'

]

具體的**如下,不用複製全部的**,複製配置,放到自己的配置檔案中,我們這裡是配置在檔案main-local.php中

<?php

$config=[

'components'

=>

['request'

=>

[// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation

'cookievalidationkey'

=>

'bbrwmnbskmmsofkxsxr9a8dkal4jhaug',]

,'view'

=>

[// 'theme' => [

// // 'basepath' => '@backend/web/duanwu',

// 'pathmap' => [

// '@backend/template' => [

// '@backend/template/chunjie',

// '@backend/template/duanwu'

// ]

// ]

// ],

// 'defaultextension' => 'html'],

'i18n'

=>

['translations'

=>[=

>

['class'

=>

'yii\i18n\phpmessagesource'

,'basepath'

=>

'@backend/messages'

,'filemap'

=>[=

>,=

>

'error.php',]

,],]

,],'urlmanager'

=>

['enableprettyurl'

=>

true

,'showscriptname'

=>

false

,'enablestrictparsing'

=>

false,]

,// 'errorhandler' => [

// 'erroraction' => 'test/index17'

// ]

'sms123'

=>

['class'

=>

'backend\components\sms']]

,// 'controllernamespace' => 'backend\control',

'defaultroute'

=>

'test'

,'viewpath'

=>

'@backend/template'

,// 'layoutpath' => '@backend/template/public'

// 'layout' => false

// 'layout' => 'common'

'language'

=>

'zh-cn'

,'modules'

=>

['shop'

=>

['class'

=>

'backend\modules\shop\module',]

]];if

(!yii_env_test

)return

$config

;

4.使用自定義元件

咋控制器中使用自定義元件

public

function

actionindex18()

自定義元件

myedittext 清除輸入的資料 setcompunddrawable 設定edittext ontouchevent ondraw 作用 繪製view顯示的內容,由系統自動呼叫 常用類 paint,canvas invalidate,postinvalidate 貪吃蛇原理 改變集合中的資料,...

自定義元件

自定義控制項 1.抽取layout如 list item home.xml 2.寫乙個類繼承1中的layout,實現父類 相對布局 的構造方法 3.使用 自定義控制項的屬性 1.布局檔案裡自定義乙個命名空間 xmlns my 2.在res的values目錄下描述自定義屬性的檔案 3.在布局檔案裡寫你...

自定義元件

自定義控制項 1.抽取layout如 list item home.xml 2.寫乙個類繼承1中的layout,實現父類 相對布局 的構造方法 3.使用 自定義控制項的屬性 1.布局檔案裡自定義乙個命名空間 xmlns my 2.在res的values目錄下描述自定義屬性的檔案 3.在布局檔案裡寫你...