????? ??????????? Yii2 - PowerPoint PPT Presentation

About This Presentation
Title:

????? ??????????? Yii2

Description:

... Define specific renderer smarty\ViewRenderer handles *.tpl twig ... PHP 7 8 ... – PowerPoint PPT presentation

Number of Views:551
Avg rating:3.0/5.0
Slides: 42
Provided by: pkli
Category:
Tags: smarty | yii2

less

Transcript and Presenter's Notes

Title: ????? ??????????? Yii2


1
????? ???????????Yii2
?????? ?.?.
  • YiiSoft

2
??????? ??????????
  • ?????????? ???????????????? ?? ??????? ????????
  • ????? ????????????? ??? ???????????? ??????
    ?????????
  • ???? ??? ??????????? ????????? ???????? ?
    ?????????
  • ??????? ? ??????????? ???????????? ? ????????

3
  • ???????? ??????????????
  • PHP 5.4
  • ???
  • ???????????
  • ????????
  • ??????? ??????????????

4
?????????? ?????????????
5
???????????? ???????
  • // Autoload via Composer by PSR-4
  • model new yii\base\Model()
  • // Yii built-in autoload by PSR via alias
  • YiisetAlias(_at_app, /var/www/myproject)
  • someObj new app\models\Customer()
  • // include /var/www/myproject/models/Customer.php

6
????? ? PHP
  • class Object
  • public publicProperty
  • private _privateProperty
  • public function setPrivateProperty(value)
  • this-gt_privateProperty value
  • public function getPrivateProperty()
  • return this-gt_privateProperty

7
  • class Object
  • public function __get(propertyName)
  • methodName 'get . propertyName
  • if (method_exists(this, methodName))
  • return call_user_func(this,
    methodName)
  • else
  • throw new Exception("Missing property
    propertyName'!")
  • public function __set(propertyName, value)
  • methodName 'set . propertyName
  • if (method_exists(this, methodName))
  • return call_user_func(this,
    methodName, value)
  • else
  • throw new Exception("Missing property
    propertyName'!")

8
  • object new Object()
  • object -gtpublicProperty 'Public value'
  • echo (object-gtpublicProperty)
  • object-gtprivateProperty 'Private value'
  • echo (object-gtprivateProperty)

9
?????????? ????????
  • function createObject(array config)
  • className config'class'
  • if (empty(className))
  • throw new Exception(Missing
    parameter "class"!')
  • unset(config'class')
  • object new className()
  • foreach (config as namegtvalue)
  • object-gtname value //
    ????????????
  • return object

10
??????? ?????? ??????? ????? ??????
  • config
  • 'class gt yii\web\UrlManager',
  • 'enablePrettyUrl gt true,
  • 'showScriptName gt false,
  • 'rules gt
  • '/ gt 'site/index',
  • 'ltcontroller\wgt/ltid\dgt gt
    'ltcontrollergt/view',
  • ,
  • object YiicreateObject(config)

11
Dependency Injection (DI)
12
(No Transcript)
13
  • config
  • 'name gt 'My Web Application',
  • 'components gt
  • 'user gt
  • enableAutoLogin gt true,
  • ,
  • ,
  • (new yii\web\Application(config))-gtrun()
  • application Yiiapp
  • user Yiiapp-gtget(user)

14
MVC ? Yii2
15
????????????? web ???????
16
?????????? ???????????
  • class View extends Component
  • public function renderFile(viewFile, data
    null)
  • require(viewFile)

lthtmlgt ltbodygt lth1gtData lt?php echo data
?gtlt/h1gt lthr /gt lt?php this-gtrender(main_menu.php
) ?gt lt/bodygt lt/htmlgt
17
????????? ???????????
18
?????? (Widget)
  • lt?php echo GridViewwidget(
  • 'dataProvider' gt dataProvider,
  • 'options' gt 'class' gt 'detail-grid-view
    table-responsive',
  • 'filterModel' gt searchModel,
  • 'columns' gt
  • 'time',
  • 'level',
  • 'category',
  • 'message',
  • ,
  • ) ?gt

19
Asset Management
20
  • class YiiAsset extends AssetBundle
  • public sourcePath '_at_yii/assets'
  • public js
  • 'yii.js',
  • public depends
  • 'yii\web\JqueryAsset',
  • class JqueryAsset extends AssetBundle
  • public sourcePath '_at_bower/jquery/dist'
  • public js
  • 'jquery.js',

21
??????
22
?????? ? ???? ?????? ????? PDO
23
?????????? ???? ??????
24
Select Query Shortcut
25
Active Record
26
  • // ??????? ???????
  • allUsers Userfind()-gtall()
  • // ??????? ????? ??????
  • newUser new User()
  • newUser-gtname new user
  • newUser-gtsave()
  • // ?????????? ???????????? ??????
  • existingUser Userfind()-gtwhere(namegttest
    user)-gtone()
  • existingUser-gtemail newemail_at_domain.com
  • existingUser-gtsave()
  • // ?????????? ???????? ?????????
  • bio existingUser-gtprofile-gtbio
  • // ?????? ???????? ?????????
  • allUsers Userfind()-gtwith(profile)-gtall()

27
?????? ???????? ?????????
28
NOSQL Active Record
  • MongoDB
  • Redis
  • ElasticSearch
  • Sphinx

29
Cross-DBMS ?????????
30
??????? (Events) ? Yii
31
????????? ???????
32
  • function handleBeforeInsert(Event event)
  • sender event-gtsender
  • // ???????? ????????? ??????????? ???????
  • sender-gtcreate_date date('Y-m-d',
    strtotime('NOW'))
  • user new User()
  • // ????????? ?????????? ???????
  • user-gton(beforeInsert, handleBeforeInsert)
  • user-gtname test name
  • user-gtsave()
  • echo user-gtcreate_date // ????? 2015-03-21

33
???????? ?????????????? ????????????
34
????????? (Behavior)
35
?????????? ??????????
  • class Component
  • private _behaviors
  • public function __call(method, arguments)
  • // ???? ??????????? ????? ?????
    ?????????
  • foreach (this-gt_behaviors as behavior)
  • if (method_exists(behavior,
    method))
  • return behavior-gtmethod(argumen
    ts)
  • throw new Exception(Missing method
    method)

36
  • class ArBehaviorExample extends Behavior
  • public function behaviorMethod()
  • this-gtowner-gtcreate_date date('Y-m-d',
    strtotime('NOW'))
  • user new User()
  • // ????????? ?????????
  • behavior new ArBehaviorExample()
  • user-gtattachBehavior(behavior)
  • // ???????? ????? ?????????
  • user-gtbehaviorMethod()
  • echo user-gtcreate_date // ????? 2015-03-21

37
????????? ???????
  • class ExampleBehavior extends Behavior
  • public function events()
  • return
  • beforeInsert gt handleBeforeInsert
    ,
  • afterInsert gt handleAfterInsert
  • public function handleBeforeSave(Event
    event)
  • // ????????? ??????? beforeInsert

38
???????? ??????????? ?????
39
?????????? AuthClient
40
?????????????? ??????????
  • Gii
  • Debug
  • Boostrap
  • JUI
  • Codeception
  • Imagine
  • ApiDoc

41
Yii2
  • Composer Bower
  • ???????????? ????????? ? DI
  • MVC
  • ?????????? assets
  • PDO ? Active Record
  • NOSQL ? Active Record
  • Cross-DBMS ?????????
  • ???????
  • ?????????
  • ??????????? ??????????
Write a Comment
User Comments (0)
About PowerShow.com