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. 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 edit refers to a view script named edit.php. To render a view, call CController::render() with the name of the view. Inside the view script, we can access the controller instance using $this. We can also use the following push approach to pass data to the view: $this->render('edit', array( 'var1'=>$value1, 'var2'=>$value2, )); In the above, the render() method will extract the second array parameter into variables. 1. Layout is a special view that is used to decorate views. <? CController Render.
Look up a class, method, property or event CController manages a set of actions which deal with the corresponding user requests. Through the actions, CController coordinates the data flow between models and views. When a user requests an action 'XYZ', CController will do one of the following: 1. Method-based action: call method 'actionXYZ' if it exists; 2. Class-based action: create an instance of class 'XYZ' if the class is found in the action class map (specified via actions(), and execute the action; 3.
If the user does not specify an action, CController will run the action specified by defaultAction, instead. CController may be configured to execute filters before and after running actions. Filters can be individual objects, or methods defined in the controller class. Array( 'accessControl - login', 'ajaxOnly + search', array( 'COutputCache + list', 'duration'=>300, ), ) The above example declares three filters: accessControl, ajaxOnly, COutputCache. Public Properties Property Details. CWidget. Look up a class, method, property or event CWidget is the base class for widgets. A widget is a self-contained component that may generate presentation based on model data. It can be viewed as a micro-controller that embeds into the controller-managed views.
Compared with controller, a widget has neither actions nor filters. Usage is described at CBaseController and CBaseController::widget. Public Properties Hide inherited properties Property Details public string $actionPrefix; the prefix to the IDs of the actions. Returns the controller that this widget belongs to. public string getId(boolean $autoGenerate=true)public void setId(string $value) Returns the ID of the widget or generates a new one if requested. Returns the owner/creator of this widget. public mixed $skin; the name of the skin to be used by this widget. Returns the directory containing the view files for this widget. Method Details Constructor. Returns a list of actions that are used by this widget. If(is_file($viewFile. Renders a view. CBaseListView.
Look up a class, method, property or event CBaseListView is the base class for CListView and CGridView. CBaseListView implements the common features needed by a view wiget for rendering multiple models. Public Properties Hide inherited properties Property Details the data provider for the view. public string $emptyTagName; the HTML tag name for the container of the emptyText property. public string $emptyText; the message to be displayed when dataProvider does not have any data. public boolean $enablePagination; whether to enable pagination. Public boolean $enableSorting; whether to enable sorting. See Also sortableAttributes public array $htmlOptions; the HTML options for the view container tag. public string $itemsCssClass; the CSS class name for the container of all data item display.
Public string $loadingCssClass; the CSS class name that will be assigned to the widget container element when the widget is updating its content via AJAX. Public array|string $pager; the configuration for the pager. CGridView. Look up a class, method, property or event CGridView displays a list of data items in terms of a table. Each row of the table represents the data of a single data item, and a column usually represents an attribute of the item (some columns may correspond to complex expression of attributes or static text). CGridView supports both sorting and pagination of the data items. The sorting and pagination can be done in AJAX mode or normal page request. A benefit of using CGridView is that when the user browser disables JavaScript, the sorting and pagination automatically degenerate to normal page requests and are still functioning as expected.
CGridView should be used together with a data provider, preferrably a CActiveDataProvider. The minimal code needed to use CGridView is as follows: $dataProvider=new CActiveDataProvider('Post'); $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, )); The above code first creates a data provider for the Post ActiveRecord class. ... CGridColumn. Look up a class, method, property or event CGridColumn is the base class for all grid view column classes. A CGridColumn object represents the specification for rendering the cells in a particular grid view column.
In a column, there is one header cell, multiple data cells, and an optional footer cell. Child classes may override renderHeaderCellContent, renderDataCellContent and renderFooterCellContent to customize how these cells are rendered. Public Properties Hide inherited properties Property Details public string $cssClassExpression; a PHP expression that is evaluated for every data cell and whose result is used as the CSS class name for the data cell. $row the row number (zero-based) $data the data model for the row $this the column object The PHP expression will be evaluated using evaluateExpression. A PHP expression can be any PHP code that has a value. Public array $filterHtmlOptions; the HTML options for the filter cell tag. public string $footer; the footer cell text. Public string $id; CButtonColumn.
Look up a class, method, property or event CButtonColumn represents a grid view column that renders one or several buttons. By default, it will display three buttons, "view", "update" and "delete", which triggers the corresponding actions on the model of the row. By configuring buttons and template properties, the column can display other buttons and customize the display order of the buttons. Public Properties Hide inherited properties Property Details public string $afterDelete; a javascript function that will be invoked after the delete ajax call. The function signature is function(link, success, data) link references the delete link.success status of the ajax call, true if the ajax call was successful, false if the ajax call failed. data the data returned by the server in case of a successful call or XHR object in case of error. Example: array( class'=>'CButtonColumn', 'afterDelete'=>'function(link,success,data){ if(success) alert("Delete completed successfuly"); }', ), Method Details if(!
Using CButtonColumn. Introduction ¶ CGridView is a one of most flexible widgets in Yii and example its flexibility is CButtonColumn used to build buttons for steering model in each grid row. Here in this how-to we will explain ways user can customize CButtonColumn to flexibly fit it to its needs. Basic customization ¶ In default look CButtonColumn contains three buttons in this order: {view}, {update} and {delete}. Their meaning and behaviour should be obvious. The easiest way to customize look and behaviour of them is to use series of CButtonColumn properties, like: updateButtonImageUrl (path to image for update button), updateButtonLabel (label for the update button; not HTML-encoded), updateButtonOptions (HTML options for this button, used in the way as many htmlOptions property for many widgets) and updateButtonUrl (a PHP expresion that is evaluated for button and whose result is used as the URL). Respective properties you'll find for other default buttons.
A few remarks: More flexible customizing ¶ CActiveForm. Look up a class, method, property or event CActiveForm provides a set of methods that can help to simplify the creation of complex and interactive HTML forms that are associated with data models. The 'beginWidget' and 'endWidget' call of CActiveForm widget will render the open and close form tags. Most other methods of CActiveForm are wrappers of the corresponding 'active' methods in CHtml. Calling them in between the 'beginWidget' and 'endWidget' calls will render text labels, input fields, etc. For example, calling CActiveForm::textField would generate an input field for a specified model attribute. What makes CActiveForm extremely useful is its support for data validation. CActiveForm supports data validation at three levels: server-side validation: the validation is performed at server side after the whole page containing the form is submitted.
All these validations share the same set of validation rules declared in the associated model class. <? Protected Properties Property Details if(! CJuiWidget. Look up a class, method, property or event This is the base class for all JUI widget classes. Public Properties Hide inherited properties Property Details public mixed $cssFile; the theme CSS file name. Public array $htmlOptions; the HTML attributes that should be rendered in the HTML tag representing the JUI widget. public array $options; the initial JavaScript options that should be passed to the JUI plugin. public mixed $scriptFile; the main JUI JavaScript file.
Public string $scriptUrl; the root URL that contains all JUI JavaScript files. Public string $theme; the JUI theme name. Public string $themeUrl; the root URL that contains all JUI theme folders. Method Details Initializes the widget. Source Code:framework/zii/widgets/jui/CJuiWidget.php#108 (show) $cs->registerCoreScript('jquery'); if(is_string($this->scriptFile)) $this->registerScriptFile($this->scriptFile); elseif(is_array($this->scriptFile)) { foreach($this->scriptFile as $scriptFile) $this->registerScriptFile($scriptFile); }} CJuiDatePicker. Look up a class, method, property or event CJuiDatePicker displays a datepicker. CJuiDatePicker encapsulates the JUI datepicker plugin. To use this widget, you may insert the following code in a view: $this->widget('zii.widgets.jui.CJuiDatePicker',array( 'name'=>'publishDate', // additional javascript options for the date picker plugin 'options'=>array( 'showAnim'=>'fold', ), 'htmlOptions'=>array( 'style'=>'height:20px;' ), )); By configuring the options property, you may specify the options that need to be passed to the JUI datepicker plugin.
Please refer to the JUI DatePicker API documentation for possible options (name-value pairs) and JUI DatePicker page for general description and demo. Property Details public array $defaultOptions; The default options called just one time per request. Public boolean $flat; If true, shows the widget as an inline calendar and the input as a hidden field. public string $i18nScriptFile; The i18n Jquery UI script file. Public string $language; Method Details.
jQuery Datepicker. CJuiDatePicker in CActiveForm. CJuiDatePicker/CActiveForm Yii Framework CJuiDatePicker Example For many of our web applications, we utilize the Yii Framework extensively. A great feature of the framework is the CActiveForm, which allows you to link up your Model to your View in a very easy manner. (See Model-View-Controller Architecture on Wikipedia for a good explanation of this concept.) If you also use the Yii Framework, you might find yourself in a dilemma that we recently experienced. We had a date field on our form, and wanted to use the CJuiDatePicker widget so that users get a nifty dropdown where they can select a date. We also wanted to link it to the model, defaulting it to the field in our database if there was already an instance of the object. Do you know of other ways to accomplish this? CJuiDatePicker Yii Forum. CTreeView. Look up a class, method, property or event CTreeView displays a tree view of hierarchical data.
It encapsulates the excellent tree view plugin for jQuery ( To use CTreeView, simply sets data to the data that you want to present and you are there. CTreeView also supports dynamic data loading via AJAX. To do so, set url to be the URL that can serve the tree view data upon request. Public Properties Hide inherited properties Property Details public string|integer $animated; animation speed. The javascript options public boolean $collapsed; whether the tree should start with all branches collapsed. Public string $control; container for a tree-control, allowing the user to expand, collapse and toggle all branches with one click. Public string $cookieId; The cookie name to use when persisting via persist:"cookie". Public mixed $cssFile; the CSS file used for the widget.
Public array $data; public array $htmlOptions; public array $options; CHtml Wiki. "By Example" cookbook pages will provide coding examples for many of the commonly used classes within Yii. We will try to provide as many usage examples as possible for keep these pages as helpful as possible. Smarthead will be pulling these from the forum when he is not finding the answers on his own. Please request examples using the comments below or ask for an example in the forum. Thanks. Avaiable methods: CHtml::link() method ¶ public static string link(string $text, mixed $url='#', array $htmlOptions=array ( )) Generates a hyperlink tag. Example 1: Linking to a controller action HTML Output: <a href="index.php? Example 2: Linking to a controller action with querystring parameters <?
<a href="index.php? Example 3: Linking to a controller action with multiple querystring parameters <? <a href="index.php? Example 4: Link opening a new page <? <a target="_blank" href="index.php? Just remove the 'controller' part from the string In this case, add an slash "/" at the start of the string url <? <? <? <p><? <? CHtml. Look up a class, method, property or event CHtml is a static class that provides a collection of helper methods for creating HTML views. Property Details public static string $afterRequiredLabel; the HTML code to be appended to the required label. public static string $beforeRequiredLabel; the HTML code to be prepended to the required label. public static boolean $closeSingleTags; whether to close single tags. Public static integer $count; the counter for generating automatic input field names. public static string $errorContainerTag; the tag name for the error container tag.
Public static string $errorCss; the CSS class for highlighting error inputs. Public static string $errorMessageCss; the CSS class for displaying error messages (see error). public static string $errorSummaryCss; the CSS class for displaying error summaries (see errorSummary). public static $liveEvents; Sets the default style for attaching jQuery event handlers. If set to true (default), event handlers are delegated. Method Details. CForm. Form Builder.