My Issue:
If my user session times out while an access restricted page is visible (say I left it open overnight), and the user then clicks on a button that performs an ajax call, the login required display appears within the div that the ajax update should happen in, rather than replacing the entire current page.
Potential Solutions:
Option 1) Extend the CWebUser and override the loginRequired() function to check for $request->isAjaxRequest (this would then need to redirect to a page which causes a javascript redirect)
Option 2) Modify the Site actionLogin to check the request type and render a different page which causes a javascript redirect.
Option 2 is the least invasive method, so I am going to go with that option and see how things work out ;)
Site Note: Could override the controller->redirect method, but I don't want to necessarily block all redirects -- I can forsee needing to have one ajax view action redirect to another ajax view action. If the controller override was used, it would have to be done on every controller - hardly efficient.
Wednesday, April 14, 2010
Wednesday, March 31, 2010
Posting with multiple models
I spent a good bit of time trying to figure out how to render multiple models in a form and have them each validate properly.
Knowing the solution, it seems quite obvious, but it took a while to track down the proper syntax.
In this example I have a custom CForm which contains a few different $model properties, in addition to the base form data.
To call the validation on multiple models in the form, simply modify any calls of
Knowing the solution, it seems quite obvious, but it took a while to track down the proper syntax.
In this example I have a custom CForm which contains a few different $model properties, in addition to the base form data.
To call the validation on multiple models in the form, simply modify any calls of
CActiveForm::validate($model);to use an array of models as the first parameter as such:
CActiveForm::validate( array($model, $model->subModel, $model->subModel2) );
Labels:
ajax,
CActiveForm,
models,
post,
validation,
yii
Friday, March 26, 2010
Themes for Mobile
Just an 'aha' or a 'well duh' moment (depending on how you look at it), but I realized today that I could set up a theme for 'mobile' friendly display.
So, I create my new mobile theme and adjust the views accordingly.
Then in my index.php I run a check for known mobile browsers against the $_SERVER['HTTP_USER_AGENT'] and if found, I set $config to /protected/config/mobile.php instead of main.php
Primary difference being the theme set, though I imagine I might add a few other differences over time.
So, I create my new mobile theme and adjust the views accordingly.
Then in my index.php I run a check for known mobile browsers against the $_SERVER['HTTP_USER_AGENT'] and if found, I set $config to /protected/config/mobile.php instead of main.php
Primary difference being the theme set, though I imagine I might add a few other differences over time.
Thursday, March 25, 2010
ActiveDataProvider w/ Scopes!
http://www.yiiframework.com/extension/active-data-provider-with-scopes/
Very easy to install!!
Scopes allow you to predefine filters for the record set and apply them and chain them without having to rewrite the conditions.
(Guide to named scopes)
i.e., in the model:
This extension simply allows you to use the same functionality with the DataProviders.
Simply import the EActiveDataProvider from the extensions directory.
Then, in the $criteria, I simply add the scope and call EActiveDataProvider instead of CActiveDataProvider.
The REALLY nice thing about the scopes is that if the business logic needs to change at some point, I can do so at a single point of entry -vs- customized criteria scattered around.
Very easy to install!!
Scopes allow you to predefine filters for the record set and apply them and chain them without having to rewrite the conditions.
(Guide to named scopes)
i.e., in the model:
public function scopes(){
return array(
'enabled'=>array(
'condition'=>'isEnabled=1',
),
'newest'=>array(
'order'=>'dateAdded DESC',
'limit'=>5
),
);
}
This extension simply allows you to use the same functionality with the DataProviders.
Simply import the EActiveDataProvider from the extensions directory.
Then, in the $criteria, I simply add the scope and call EActiveDataProvider instead of CActiveDataProvider.
The REALLY nice thing about the scopes is that if the business logic needs to change at some point, I can do so at a single point of entry -vs- customized criteria scattered around.
Yii and Themes
In the face of a total site redesign today, I realized I should begin using the themes features of Yii. This is where some of the true beauty of MVC comes into play.
Without a custom theme set up, the theme will default to the views in the /protected/views/ directory. Once you set up a theme, whenever it cannot find a specific view in the theme directory, it will go back to the default in the /protected/views/ directory and check there.
This is the guide reference on themes: http://www.yiiframework.com/doc/guide/topics.theming
Without a custom theme set up, the theme will default to the views in the /protected/views/ directory. Once you set up a theme, whenever it cannot find a specific view in the theme directory, it will go back to the default in the /protected/views/ directory and check there.
This is the guide reference on themes: http://www.yiiframework.com/doc/guide/topics.theming
Thursday, March 18, 2010
Custom Behavior Example/Test
Ok, so I originally thought I should write a widget for this, then I realized that this was a good example of a behavior that should be attachable to multiple components.
I want to give the ability for the page to trim a string if it's over a given length, and return the truncated string with an ellipsis or other marker. A quick search through the yii documentation/forums did not find anything already built that would do this (though I did find one article in polish that had a function for doing truncation ;) Alas, I do not read Polish).
I'm adding this link to the list of items to read on behaviors in Yii:
http://www.yiiframework.com/doc/guide/extension.use#behavior
I want to give the ability for the page to trim a string if it's over a given length, and return the truncated string with an ellipsis or other marker. A quick search through the yii documentation/forums did not find anything already built that would do this (though I did find one article in polish that had a function for doing truncation ;) Alas, I do not read Polish).
I'm adding this link to the list of items to read on behaviors in Yii:
http://www.yiiframework.com/doc/guide/extension.use#behavior
Events & Behaviors in Yii - Initial Notes
This one is a work in progress as I try to figure out how to use this aspect correctly. This are my "notes" from reading these documents.
I'm basing this on the following two document references:
http://www.yiiframework.com/doc/cookbook/44
http://www.yiiframework.com/doc/guide/basics.component (section on events)
I'm basing this on the following two document references:
http://www.yiiframework.com/doc/cookbook/44
http://www.yiiframework.com/doc/guide/basics.component (section on events)
Subscribe to:
Posts (Atom)