sample in yii

Upload: gemark-almacen

Post on 02-Jun-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 Sample in YII

    1/4

    API

    :1.1.15

    The Definitive Guide to Yii

    ?????

    Getting Started

    Fundamentals

    o Model-View-Controller (MVC)

    o Entry Script

    o Application

    o Controller

    o Model

    o View

    o Component

    o Module

    o Path Alias and Namespace

    o Conventions

    o Development Workflow

    o Best MVC Practices

    Working with Forms Working with Databases

    Caching

    Extending Yii

    Testing

    Special Topics

    English|Russian

    View

    A view is a PHP script consisting mainly of user interface elements. It can contain PHP statements, but it

    is recommended that these statements should not alter data models and should remain relatively simple.

    http://yiiframework.ru/doc/guide/ru/indexhttp://yiiframework.ru/doc/guide/ru/indexhttp://yiiframework.ru/doc/blog/ru/start.overviewhttp://yiiframework.ru/doc/blog/ru/start.overviewhttp://yiiframework.ru/doc/cookbook/ru/indexhttp://yiiframework.ru/doc/cookbook/ru/indexhttp://www.yiiframework.com/doc/api/http://www.yiiframework.com/doc/api/http://www.yiiframework.com/extensions/http://www.yiiframework.com/extensions/http://yiiframework.ru/forum/http://yiiframework.ru/forum/http://www.yiiframework.com/download/http://www.yiiframework.com/download/http://www.yiiframework.com/download/http://yiiframework.ru/doc/guide/en/basics.mvchttp://yiiframework.ru/doc/guide/en/basics.mvchttp://yiiframework.ru/doc/guide/en/basics.entryhttp://yiiframework.ru/doc/guide/en/basics.entryhttp://yiiframework.ru/doc/guide/en/basics.applicationhttp://yiiframework.ru/doc/guide/en/basics.applicationhttp://yiiframework.ru/doc/guide/en/basics.controllerhttp://yiiframework.ru/doc/guide/en/basics.controllerhttp://yiiframework.ru/doc/guide/en/basics.modelhttp://yiiframework.ru/doc/guide/en/basics.modelhttp://yiiframework.ru/doc/guide/en/basics.viewhttp://yiiframework.ru/doc/guide/en/basics.viewhttp://yiiframework.ru/doc/guide/en/basics.componenthttp://yiiframework.ru/doc/guide/en/basics.componenthttp://yiiframework.ru/doc/guide/en/basics.modulehttp://yiiframework.ru/doc/guide/en/basics.modulehttp://yiiframework.ru/doc/guide/en/basics.namespacehttp://yiiframework.ru/doc/guide/en/basics.namespacehttp://yiiframework.ru/doc/guide/en/basics.conventionhttp://yiiframework.ru/doc/guide/en/basics.conventionhttp://yiiframework.ru/doc/guide/en/basics.workflowhttp://yiiframework.ru/doc/guide/en/basics.workflowhttp://yiiframework.ru/doc/guide/en/basics.best-practiceshttp://yiiframework.ru/doc/guide/en/basics.best-practiceshttp://yiiframework.ru/doc/guide/en/basics.viewhttp://yiiframework.ru/doc/guide/en/basics.viewhttp://yiiframework.ru/doc/guide/ru/basics.viewhttp://yiiframework.ru/doc/guide/ru/basics.viewhttp://yiiframework.ru/doc/guide/ru/basics.viewhttp://orphus.ru/http://twitter.com/yiiframework_ruhttp://yiiframework.ru/http://orphus.ru/http://twitter.com/yiiframework_ruhttp://yiiframework.ru/http://orphus.ru/http://twitter.com/yiiframework_ruhttp://yiiframework.ru/http://yiiframework.ru/doc/guide/ru/basics.viewhttp://yiiframework.ru/doc/guide/en/basics.viewhttp://yiiframework.ru/doc/guide/en/basics.best-practiceshttp://yiiframework.ru/doc/guide/en/basics.workflowhttp://yiiframework.ru/doc/guide/en/basics.conventionhttp://yiiframework.ru/doc/guide/en/basics.namespacehttp://yiiframework.ru/doc/guide/en/basics.modulehttp://yiiframework.ru/doc/guide/en/basics.componenthttp://yiiframework.ru/doc/guide/en/basics.viewhttp://yiiframework.ru/doc/guide/en/basics.modelhttp://yiiframework.ru/doc/guide/en/basics.controllerhttp://yiiframework.ru/doc/guide/en/basics.applicationhttp://yiiframework.ru/doc/guide/en/basics.entryhttp://yiiframework.ru/doc/guide/en/basics.mvchttp://www.yiiframework.com/download/http://yiiframework.ru/forum/http://www.yiiframework.com/extensions/http://www.yiiframework.com/doc/api/http://yiiframework.ru/doc/cookbook/ru/indexhttp://yiiframework.ru/doc/blog/ru/start.overviewhttp://yiiframework.ru/doc/guide/ru/index
  • 8/10/2019 Sample in YII

    2/4

    In the spirit of separating of logic and presentation, large chunks of logic should be placed in controllers or

    models rather than in views.

    A view has a name which is used to identify the view script file when rendering. The name of a view is the

    same as the name of its view script. For example, the view name editrefers to a view script

    named edit.php. To render a view, callCController::render()with the name of the view. The method will

    look for the corresponding view file under the directory protected/views/ControllerID.

    Inside the view script, we can access the controller instance using $this. We can thus pullin any

    property of the controller by evaluating $this->propertyNamein the view.

    We can also use the following pushapproach to pass data to the view:

    $this->render('edit', array(

    'var1'=>$value1,

    'var2'=>$value2,

    ));

    In the above, therender()method will extract the second array parameter into variables. As a result, in

    the view script we can access the local variables $var1and $var2.

    Layout

    Layout is a special view that is used to decorate views. It usually contains parts of a user interface that

    are common among several views. For example, a layout may contain a header and a footer, and embed

    the view in between, like this:

    ......header here......

    ......footer here......

    where $contentstores the rendering result of the view.

    Layout is implicitly applied when callingrender().By default, the view

    scriptprotected/views/layouts/main.phpis used as the layout. This can be customized by

    changing eitherCWebApplication::layoutorCController::layout.To render a view without applying any

    layout, callrenderPartial()instead.

    Widget

    A widget is an instance ofCWidgetor a child class ofCWidget.It is a component that is mainly for

    presentational purposes. A widget is usually embedded in a view script to generate a complex, yet self-

    contained user interface. For example, a calendar widget can be used to render a complex calendar user

    interface. Widgets facilitate better reusability in user interface code.

    To use a widget, do as follows in a view script:

    http://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CWebApplication#layouthttp://www.yiiframework.com/doc/api/CWebApplication#layouthttp://www.yiiframework.com/doc/api/CWebApplication#layouthttp://www.yiiframework.com/doc/api/CController#layouthttp://www.yiiframework.com/doc/api/CController#layouthttp://www.yiiframework.com/doc/api/CController#layouthttp://www.yiiframework.com/doc/api/CController#renderPartialhttp://www.yiiframework.com/doc/api/CController#renderPartialhttp://www.yiiframework.com/doc/api/CController#renderPartialhttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CController#renderPartialhttp://www.yiiframework.com/doc/api/CController#layouthttp://www.yiiframework.com/doc/api/CWebApplication#layouthttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#renderhttp://www.yiiframework.com/doc/api/CController#render
  • 8/10/2019 Sample in YII

    3/4

    ...body content that may be captured by the widget...

    or

    The latter is used when the widget does not need any body content.

    Widgets can be configured to customize their behavior. This is done by setting their initial property values

    when callingCBaseController::beginWidgetorCBaseController::widget.For example, when using

    aCMaskedTextFieldwidget, we might like to specify the mask being used. We can do so by passing an

    array of initial property values as follows, where the array keys are property names and array values are

    the initial values of the corresponding widget properties:

    To define a new widget, extendCWidgetand override itsinit()andrun()methods:

    classMyWidget extendsCWidget

    {

    publicfunctioninit()

    {

    // this method is called by CController::beginWidget()

    }

    publicfunctionrun()

    {

    // this method is called by CController::endWidget()

    }

    }

    Like a controller, a widget can also have its own view. By default, widget view files are located underthe viewssubdirectory of the directory containing the widget class file. These views can be rendered by

    callingCWidget::render(),similar to that in controller. The only difference is that no layout will be applied to

    a widget view. Also, $thisin the view refers to the widget instance instead of the controller instance.

    Tip:CWidgetFactory::widgetscan be used to configure widgets on a site-wide basis, allowing much

    easier base configuration. You can find more details on thetheming page

    http://www.yiiframework.com/doc/api/CBaseController#beginWidgethttp://www.yiiframework.com/doc/api/CBaseController#beginWidgethttp://www.yiiframework.com/doc/api/CBaseController#beginWidgethttp://www.yiiframework.com/doc/api/CBaseController#widgethttp://www.yiiframework.com/doc/api/CBaseController#widgethttp://www.yiiframework.com/doc/api/CBaseController#widgethttp://www.yiiframework.com/doc/api/CMaskedTextFieldhttp://www.yiiframework.com/doc/api/CMaskedTextFieldhttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CWidget#inithttp://www.yiiframework.com/doc/api/CWidget#inithttp://www.yiiframework.com/doc/api/CWidget#inithttp://www.yiiframework.com/doc/api/CWidget#runhttp://www.yiiframework.com/doc/api/CWidget#runhttp://www.yiiframework.com/doc/api/CWidget#runhttp://www.yiiframework.com/doc/api/CWidget#renderhttp://www.yiiframework.com/doc/api/CWidget#renderhttp://www.yiiframework.com/doc/api/CWidgetFactory#widgetshttp://www.yiiframework.com/doc/api/CWidgetFactory#widgetshttp://www.yiiframework.com/doc/api/CWidgetFactory#widgetshttp://yiiframework.ru/doc/guide/en/topics.theming#customizing-widgets-globallyhttp://yiiframework.ru/doc/guide/en/topics.theming#customizing-widgets-globallyhttp://yiiframework.ru/doc/guide/en/topics.theming#customizing-widgets-globallyhttp://yiiframework.ru/doc/guide/en/topics.theming#customizing-widgets-globallyhttp://www.yiiframework.com/doc/api/CWidgetFactory#widgetshttp://www.yiiframework.com/doc/api/CWidget#renderhttp://www.yiiframework.com/doc/api/CWidget#runhttp://www.yiiframework.com/doc/api/CWidget#inithttp://www.yiiframework.com/doc/api/CWidgethttp://www.yiiframework.com/doc/api/CMaskedTextFieldhttp://www.yiiframework.com/doc/api/CBaseController#widgethttp://www.yiiframework.com/doc/api/CBaseController#beginWidget
  • 8/10/2019 Sample in YII

    4/4

    System View

    System views refer to the views used by Yii to display error and logging information. For example, when a

    user requests for a non-existing controller or action, Yii will throw an exception explaining the error. Yii

    displays the exception using a specific system view.

    The naming of system views follows some rules. Names like errorXXXrefer to views for

    displayingCHttpExceptionwith error code XXX. For example, ifCHttpExceptionis raised with error code

    404, the error404view will be displayed.

    Yii provides a set of default system views located under framework/views. They can be customized by

    creating the same-named view files under protected/views/system.

    2009 2014,

    2008 2014,Yii Software LLC |

    http://www.yiiframework.com/doc/api/CHttpExceptionhttp://www.yiiframework.com/doc/api/CHttpExceptionhttp://www.yiiframework.com/doc/api/CHttpExceptionhttp://www.yiiframework.com/doc/api/CHttpExceptionhttp://www.yiiframework.com/doc/api/CHttpExceptionhttp://yiiframework.ru/forum/viewforum.php?f=5http://yiiframework.ru/forum/viewforum.php?f=5http://rmcreative.ru/http://rmcreative.ru/http://rmcreative.ru/http://www.yiisoft.com/http://www.yiiframework.com/doc/terms/http://www.yiiframework.com/doc/terms/http://www.yiiframework.com/doc/terms/http://www.yiiframework.com/doc/terms/http://www.yiisoft.com/http://rmcreative.ru/http://yiiframework.ru/forum/viewforum.php?f=5http://www.yiiframework.com/doc/api/CHttpExceptionhttp://www.yiiframework.com/doc/api/CHttpException