Wiki articles in category Tips

Showing 121-140 of 158 items.

Using counters with ActiveRecord

Created 8 years ago by davi_alexandre, updated 5 years ago by marcovtwout.

Let's say, for example, that you are developing a blog or some kind of CMS and you want to track the number of times each post was viewed (maybe to show a list of the most viewed ones).

11 1
17 followers
Viewed: 37 383 times
Version: 1.1
Category: Tips

Adding a date range search for CGridView the easy way

Created 7 years ago by mikewalen, updated 6 years ago by mikewalen.
  1. Create an Active Record Behavior that builds the criteria for the search() method and attach it to your model
  2. Modify the search() method of the model to merge the behavior's criteria in with the rest of the searchable attributes
  3. Modify the _search form view to add the date range inputs
6 0
11 followers
Viewed: 37 828 times
Version: 1.1
Category: Tips

Using CJuiDialog to edit rows in a CGridView

Created 9 years ago by Russell England, updated 9 years ago by Russell England.

I used Zaccarias excellent article as the base http://www.yiiframework.com/wiki/145/cjuidialog-for-create-new-model/

Solution

First follow the wiki above to create all the required code. Then make the following modifications in your...

3 1
11 followers
Viewed: 37 843 times
Version: 1.1
Category: Tips

Easy way to redirect http:\\localhost\yii2-basic to http:\\localhost\yii2-basic\web\index.php

Created 5 years ago by Scott_Huang, updated 5 years ago by Scott_Huang.

First of all, install yii2 basic template according below link:

1 0
5 followers
Viewed: 39 124 times
Version: 2.0
Category: Tips

Display a nice exception message on ajax requests

Created 8 years ago by Maurizio Domba Cerin, updated 8 years ago by Maurizio Domba Cerin.

in Yii versions previous to 1.1.9 exceptions was handled differently during ajax request and displayed by CApplication::displayException(). This way the exception message displayed on ajax requests could not be customized.
The message for the CGridView delete request with YII_DEBUG set to true l...

12 0
19 followers
Viewed: 44 485 times
Version: 1.1
Category: Tips

Update and Delete buttons on Breadcrumb

Created a year ago by Daniel.

The definition of breadcrumbs according to its documentation is as follow: Breadcrumbs displays a list of links indicating the position of the current page in the whole site hierarchy.

0 0
1 follower
Viewed: 44 623 times
Version: 2.0
Category: Tips

How to use a component before every action of a controller

Created 7 years ago by transistor, updated 7 years ago by transistor.

I guess this is a tip on how to execute some code before every action in a controller, because I will tell you how I did it and maybe you can use the idea in your project.

2 0
4 followers
Viewed: 44 907 times
Version: 1.1
Category: Tips

Putting Function To Be Called In View

Created 9 years ago by junxiong, updated 9 years ago by junxiong.

Sometimes we need some complicated view to be displayed (such as generating complicated table). Most people suggest that in MVC the View must be as simple as possible (don't have too much loops, etc). So what we have to do is to hide away the complex code by putting it at somewhere else. The following are few places options to keep the function:

5 1
5 followers
Viewed: 45 096 times
Version: 1.1
Category: Tips
Tags: render, view

A simple action for CJuiAutoComplete

Created 9 years ago by tydeas_dr, updated 8 years ago by Thiago Souza.

Simple as that. I have placed this action in my extension folder like:

15 1
19 followers
Viewed: 45 470 times
Version: 1.1
Category: Tips

1:n relations sometimes require CDbCriteria.together

Created 8 years ago by fsb, updated 6 years ago by fsb.

There are situations in which Active Record will generate nonsense queries from what a nieve Yii user might think is reasonable code. One such situation is a CActiveDataProvider using CDbCriteria to get data from parent and 1:n child table with a condition on the child table.

15 0
12 followers
Viewed: 46 667 times
Version: 1.1
Category: Tips

Update two models with one view

Created 8 years ago by sensorario, updated 8 years ago by SebK.

Suppose to have two models: Users and Emails. You do not want to store email in a Users model. And User can have 0 or many emails. This is the form generated to create a new user (just username).

9 2
13 followers
Viewed: 48 645 times
Version: 1.1
Category: Tips

An easy way to display a success page using flash messages

Created 9 years ago by qiang, updated 9 years ago by qiang.

We often need to display a success page after the user has submitted a form without problem. We may show some welcome message after a user registers a new account. There are many ways to implement this workflow. In this article, I will explain a method that exploits flash messages.

21 0
29 followers
Viewed: 49 062 times
Version: 1.1
Category: Tips
14 0
20 followers
Viewed: 49 254 times
Version: 1.1
Category: Tips

FORM with GET method causes repeated stacking of URL Parameters

Created 6 years ago by Kartik V, updated 6 years ago by toph.

// In Yii 1.x $form = $this->beginWidget('CActiveForm', [

'id' => 'order-search-form',
'method' => 'get',

]); echo $form->textInput($searchModel, 'id'); echo CHtml::submitButton('Find', ['class' => 'btn btn-primary']); $this->endWidget(); `

4 2
40 followers
Viewed: 49 730 times
Version: all
Category: Tips

Adding Yii Search to Your Browser Search Box

Created 9 years ago by qiang, updated 2 years ago by CeBe.

The official Yii project site now supports OpenSearch. This means you can customize your browser's search box to enable direct search of the content in yiiframework.com. For example, by entering a Yii class name in the browser's search box, the corresponding class API page will be shown in the browser.

25 0
6 followers
Viewed: 52 120 times
Version: all
Category: Tips

Assigning dynamic roles to a user Using yii Rights module at the time of user creation and using some special advanced features of yii rights

Created 7 years ago by Rajith R, updated 7 years ago by Rajith R.

After Installing Yii Users and Rights to Newly Created Yii app we have to assign dynamic roles to a user at the time of user creation .

7 0
13 followers
Viewed: 52 659 times
Version: 1.1
Category: Tips

Ajax update

Created 9 years ago by zaccaria, updated 9 years ago by zaccaria.

Often happens to have the need of change a part of the page with ajax.

16 2
14 followers
Viewed: 53 460 times
Version: 1.1
Category: Tips
Tags: AJAX

CGridView: Update/create records in a CJuiDialog

Created 8 years ago by Joblo, updated 8 years ago by Joblo.

My article Display the full record in a CJuiDialog uses ajax to view a record in dialog on clicking the 'view-icon'.

12 0
26 followers
Viewed: 53 829 times
Version: 1.1
Category: Tips

Activating Bootstrap 3 Tooltips & Popover for your Yii Site.

Created 6 years ago by Kartik V, updated 2 years ago by alrazi.

Step 1: Initialize the Bootstrap Tooltip & Popover plugins in your view layout file @web\views\layouts\main.php. Add this to somewhere in the beginning head section (after you have loaded the Jquery using your AppAsset or something similar).

2 2
47 followers
Viewed: 55 707 times
Version: 2.0
Category: Tips

How to filter CGridView with From Date and To Date datepicker

Created 8 years ago by kiran sharma, updated 7 years ago by kiran sharma.

This artical is related to allow user to filter CGridView with date range using datepicker on submit button. Here I use Yii Cookie to preserve date in datepicker textbox after submitting the form.

9 0
26 followers
Viewed: 58 751 times
Version: 1.1
Category: Tips