From f11ecb94bde8be588a281745b8239c9142ed4e34 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 16 Aug 2013 02:43:32 +0400 Subject: [PATCH] more docs on views, cross-references, intros for error handling and debugger --- docs/guide/debugger.md | 10 +++++++-- docs/guide/error.md | 4 ++++ docs/guide/form.md | 3 +++ docs/guide/index.md | 2 +- docs/guide/security.md | 8 ++++++- docs/guide/upgrade-from-v1.md | 10 ++++++--- docs/guide/view.md | 50 +++++++++++++++++++++++++++++++++++++++---- 7 files changed, 76 insertions(+), 11 deletions(-) diff --git a/docs/guide/debugger.md b/docs/guide/debugger.md index 0ece793..768f25d 100644 --- a/docs/guide/debugger.md +++ b/docs/guide/debugger.md @@ -1,8 +1,14 @@ Debug toolbar and debugger ========================== -Overview --------- +Yii2 includes a handy toolbar to aid faster development and debugging as well as debugger. Toolbar displays information +about currently opened page while using debugger you can analyze data collected before. + +Installing and configuring +-------------------------- + +How to use it +------------- Creating your own panels ------------------------ diff --git a/docs/guide/error.md b/docs/guide/error.md index c97fada..20bb23d 100644 --- a/docs/guide/error.md +++ b/docs/guide/error.md @@ -1,3 +1,7 @@ Error Handling ============== +Error handling in Yii is different from plain PHP. First of all, all non-fatal errors are converted to exceptions so +you can use `try`-`catch` to work with these. Second, even fatal errors are rendered in a nice way. In debug mode that +means you have a trace and a piece of code where it happened so it takes less time to analyze and fix it. + diff --git a/docs/guide/form.md b/docs/guide/form.md index e69de29..c1f1ba3 100644 --- a/docs/guide/form.md +++ b/docs/guide/form.md @@ -0,0 +1,3 @@ +Working with forms +================== + diff --git a/docs/guide/index.md b/docs/guide/index.md index df16890..601323a 100644 --- a/docs/guide/index.md +++ b/docs/guide/index.md @@ -67,7 +67,7 @@ More ==== - [Bootstrap widgets](bootstrap-widgets.md) -- [Form](form.md) +- [Working with forms](form.md) - [Model validation reference](validation.md) - [Caching](caching.md) - [Internationalization](i18n.md) diff --git a/docs/guide/security.md b/docs/guide/security.md index 0a3a14e..b3981fc 100644 --- a/docs/guide/security.md +++ b/docs/guide/security.md @@ -78,4 +78,10 @@ Securing Cookies ---------------- - validation -- httpOnly \ No newline at end of file +- httpOnly + +See also +-------- + +- [Views security](view.md#security) + diff --git a/docs/guide/upgrade-from-v1.md b/docs/guide/upgrade-from-v1.md index 15a00c7..2af5d31 100644 --- a/docs/guide/upgrade-from-v1.md +++ b/docs/guide/upgrade-from-v1.md @@ -149,11 +149,12 @@ $content = Yii::$app->view->renderFile($viewFile, $params); Also, there is no more `CClientScript` in Yii 2.0. The `View` class has taken over its role with significant improvements. For more details, please see the "assets" subsection. -While Yii 2.0 continues to use PHP as its main template language, it comes with built-in -support for two popular template engines: Smarty and Twig. The Prado template engine is +While Yii 2.0 continues to use PHP as its main template language, it comes with two official extensions +adding support for two popular template engines: Smarty and Twig. The Prado template engine is no longer supported. To use these template engines, you just need to use `tpl` as the file extension for your Smarty views, or `twig` for Twig views. You may also configure the -`View::renderers` property to use other template engines. +`View::renderers` property to use other template engines. See [Using template engines](template.md) section +of the guide for more details. Models @@ -209,6 +210,8 @@ Because of the above change, Yii 2.0 no longer has "safe" and "unsafe" validator If your model only has one scenario (very common), you do not have to overwrite `scenarios()`, and everything will still work like the 1.1 way. +To learn more about Yii 2.0 models refer to [Models](model.md) section of the guide. + Controllers ----------- @@ -216,6 +219,7 @@ Controllers The `render()` and `renderPartial()` methods now return the rendering results instead of directly sending them out. You have to `echo` them explicitly, e.g., `echo $this->render(...);`. +To learn more about Yii 2.0 controllers refer to [Controller](controller.md) section of the guide. Widgets ------- diff --git a/docs/guide/view.md b/docs/guide/view.md index 932b789..e3817ee 100644 --- a/docs/guide/view.md +++ b/docs/guide/view.md @@ -37,6 +37,30 @@ Intead of just scalar values you can pass anything else such as arrays or object Widgets ------- +Widgets are a self-contained building blocks for your views. A widget may contain advanced logic, typically takes some +configuration and data and returns HTML. There is a good number of widgets bundled with Yii such as [active form](form.md), +breadcrumbs, menu or [wrappers around bootstrap component framework](boostrap-widgets.md). Additionally there are +extensions providing additional widgets such as official one for jQueryUI components. + +In order to use widget you need to do the following: + +```php +// Note that you have to "echo" the result to display it +echo \yii\widgets\Menu::widget(array('items' => $items)); + +// Passing an array to initialize the object properties +$form = \yii\widgets\ActiveForm::begin(array( + 'options' => array('class' => 'form-horizontal'), + 'fieldConfig' => array('inputOptions' => array('class' => 'input-xlarge')), +)); +... form inputs here ... +\yii\widgets\ActiveForm::end(); +``` + +In the code above `widget` method is used for a widget that just outputs content while `begin` and `end` are used for a +widget that wraps content between method calls with its own output. In case of the form this output is the `
` tag +with some properties set. + Security -------- @@ -87,11 +111,11 @@ Alternative template languages There are offlicial extensions for [Smarty](http://www.smarty.net/) and [Twig](http://twig.sensiolabs.org/). In order to learn more refer to [Using template engines](template.md) section of the guide. -Using View object ------------------ +Using View object in templates +------------------------------ -An instance of `yii\base\View` is available in view templates as `$this` variable. Using it you can do many useful things -including setting page title and meta, registering scripts and accessing the context. +An instance of `yii\base\View` component is available in view templates as `$this` variable. Using it in templates you +can do many useful things including setting page title and meta, registering scripts and accessing the context. ### Setting page title @@ -314,3 +338,21 @@ echo $this->context->getRoute(); ### Caching blocks To learn about caching of view fragments please refer to [caching](caching.md) section of the guide. + +Customizing View component +-------------------------- + +Since view is also an application component named `view` you can replace it with your own component that extends +from `yii\base\View`. It can be done via application configuration file such as `config/web.php`: + +```php +return array( + // ... + 'components' => array( + 'view' => array( + 'class' => 'app\components\View', + ), + // ... + ), +); +```