Yii execute code after method

In order to execute a specific code after a Yii controller method (action) called you can proceed by using the following method: afterAction

You cannot specify the action or not

here’s an example:

with the same principle you can call the method: beforeAction

do not forget however to return true before end of the method

Facebooktwitterredditpinterestlinkedinmail

Yii CSqlDataProvider sort

In order to sort Yii CSqlDataProvider you have to pass CSort() object to it.

In case the CSqlDataProvider is not sorted you should probably check your query passed to the object. Pay attention not to add a semicolon at the end of your query.

 

Facebooktwitterredditpinterestlinkedinmail

Redirect with Timer in PHP

How you can make a redirect with PHP after a specific number of seconds ?

There are three options available:
The first one is to use a meta refresh

or a javascript function:

You can however use the PHP function header with the following sintax:

Facebooktwitterredditpinterestlinkedinmail

Google Maps: address geocoding using php

The following code shows how to geocode an address to obtain google maps latitude and longitude values:

et voilà!

Facebooktwitterredditpinterestlinkedinmail

Joomla: email validation

The following code shows how to validate an email with Joomla API

Facebooktwitterredditpinterestlinkedinmail

Joomla params/forms YES/NO radio button option

Here below the code for a YES/NO radio button option suitable for example for published option in your table records:

YES is the default option in this specific case.

Facebooktwitterredditpinterestlinkedinmail

Joomla – get user groups programmatically

The following code illustrates how to access groups an user is subscribed with Joomla ACL. Groups ids are returned in an array

To test the code, do not forget to lougout and login again should you have modified the user group from the back-end

user-groups2

Facebooktwitterredditpinterestlinkedinmail

Joomla: get Objects (database, user, application)

Here below the code to programmatically obtain:

Access to Database Object

Access to User Object:

Access to App Object:

Access to Document Object:

 

Facebooktwitterredditpinterestlinkedinmail

Joomla: get UserGroupId by name programmatically

You can obtain Joomla UserGroup id by name with the following code:

 

Facebooktwitterredditpinterestlinkedinmail

Joomla: redirect user to Login programmatically

If you want your component function to be accessed by your user prior to login programmatically you can use the following code:

You can include the function in your helper class

helpers/yourcomponent.php

You can call the function in your MVC code with the following instructions:

 

Facebooktwitterredditpinterestlinkedinmail