Thursday, March 31, 2011

Published EStrongPassword Extension

Not really much to it, but I thought it was something that might be useful for others.

This is an entirely client side solution. IMHO it should not replace solid validation on the server side as well.

On a side note, I've been all over the place with various projects and exploring the new features of Yii 1.1.7. I'm particularly looking forward to the business applications available with the new RESTful URL Manager options.

Friday, March 18, 2011

Using Scopes with DataProviders

I used to use an extension called EActiveDataProvider to get this functionality, but that broke with the release of 1.1.2 or 1.1.3, I can't quite recall. Suddenly, today, it dawned on me that I could easily get this functionality once more, by simply calling the scope function of the model and then passing in the particular scope I was looking for as the criteria parameter of the CActiveDataProvider.

For example...

In model Post, I add a scope as follows:
public function scopes()
   return array(
         'order'=>'post_date DESC',

Then, in my controller where I want to output just this set of data:
public function actionStats()
    $p = new Post();
    $scopes = $p->scopes();
    $criteria = $scopes['stats'];

    // Note: I could probably just Post::model()->stats()  but I haven't 
    // tested that.

    $dataProvider = new CActiveDataProvider( 'Post', array('criteria'=>$criteria));

    ... business as usual

Where previously I was doing something like this to be able to take advantage of the scope:
$dataProvider = new CArrayDataProvider( Post::model()->stats()->findAll() );

While the CArrayDataProvider is an acceptable alternative, I find that it does have some peculiarities when used with a CGridView, which the CActiveDataProvider avoids.

(Note: My scope is actually quite different and more complex, but I thought this made a clearer example).


Apparently, I need to read more about active finders, because you can actually do THIS as well:
$dataProvider = new CActiveDataProvider( Post::model()->stats() );

Wednesday, March 9, 2011

Published ESitemap Extension

The extension can be found here: Yii Extensions: ESitemap

This is an extension that provides class based actions which can be applied to any controller to generate a valid sitemap document. It comes with both a sitemap.xml option and a 'human readable' option.

You can configure any ActiveRecord class to be used as a source of site links, simply pass in the configuration options for the proper view of the object you wish to display.

I'm looking for feedback and ways to improve, so please share any comments/suggestions that you may have, either here, on the ESitemap Extension, or on the forum thread for the extension.

Hope it's helpful!