Usefull Yii plugin
A quick update. Today I found a very nice Yii plugin which allows for profiling of your sql queries. Very usefull if you want to analyze the performance of your application.
The plugin can be found at : http://www.yiiframework.com/extension/dbprofiler/
What would you like to know?
Since I'm too busy too look into an interesting subject to blog about I would like to give my readers a chance to pick a subject. No need to hold back it can be anything as long as it has something to do with computers or computer law. Here's a possible lists of subjects to get you started:
- Effects of law X on the internet (or your I.T. business)
- Hardware questions
- PHP frameworks
- Programming structures such as MVC, using factories etc.
- Using sourcecontrol & IDEs
- etc....
So if you have something which you would like to know, please leave a comment and I will see if I can answer the question.
Yii framework RBAC part 2
In my previous post I talked about setting up a right structure. In this post I will show you how to use this data to control what user can and can't do.
Yii framework RBAC
In this blog post I will be showing how to create an access control list and use Role Based Access Control in Yii framework.
Yii Gridview with custom fields
Today's post will be in english in the hope that I may help more people than just dutch people, that and it's a subject which was a bit more annoying to figure out than guide #1024 to setting up a webserver.
Either way let's get started!
Today I was working on a project which uses the Yii framework (I recommend you check it out if you haven't already). I was having some problems with my CGridView (a class used to create a grid view).
The case: I wanted to have some searchable column for my table however I'd since my users aren't going to remember every user id I needed a way for people to search by username instead of user id.
The model: First off you need to make sure you have the right relations in you model. In my case this meant that my relations() function in my model (which extends from CActiveRecord ofcourse) had to contain the following:
return array(
...
'user' => array(self::BELONGS_TO, 'Users','user_id'),
);
'user' is going to be the name of the relation, this can be "cheescake" or "icecreamsandwich" if you so desire..
'Users' is the model you wish to create the relation with
'user_id' is the column which is used as a foreign key.. e.g. table1.user_id = table2.user_id
The view: Next in your view in your CGridView definition add the following
'columns'=>array(
'date',
array(
'name'=>'user_id'
'value'=>'$data->user->user_name'
)
)
'date' this is just a normal field
'name' the name of the field, you should use a model property name
'value' this is the value that shall be shown to the user
'$data->user->user_name' The $data refers to the model, user then refers to the user relation and it then collects from that the username. Look out that you do not forget to put this value between quotation marks.
Back to the model: In the model go to the function named search() in you should find some statements such as "$criteria->compare('column',$this->value);" This creates a CDbCriteria object to query the database. What we want to do is join the users table onto our query so we need to add "$criteria->with = array('users');". Finally we need to add the query criteria to query for username. Replace the rule "$criteria->compare('user_id',$this->user_id);" with something like "$criteria->compare('user_name',$this->user_id,true)" The true on the end ensure that the comparison is LIKE and not = therefor partial matches will also be shown.
Feel free to ask questions but try to read the documentation first :)
01/17/12 11:11:00 am, 