2

What is main difference between these two components in yii. Their purpose seems same to me. If access control is used to restrict some type of users on specific action then filters can also stop execution of an action for specific user i.e. if user isn't authenticated.

It seems same to me can anyone clearly differentiate it for me.

Ejaz Karim
  • 3,676
  • 6
  • 36
  • 49
  • 3
    Access control is aimed at managing, well, access control. It comes with a prepared mechanism for that. Filters are more flexible - they can run *before or after* the action, they can transform input, they can measure and record time spent, they can reject badly-formed requests... And yes, they can also be used for access control, if you really want to roll out your own mechanism for that. – DCoder Aug 25 '13 at 10:40
  • @DCoder I understand purposes of both components. So it is just like beforeSave() and afterSave() methods of CActiveRecord? We can transform data after/before action get executes or even can stop it from executing. – Ejaz Karim Aug 25 '13 at 11:06
  • Yes, that's a reasonable comparison. – DCoder Aug 25 '13 at 11:51
  • 4
    Actually, access control **is** a filter. One that runs before the action is executed. As DCoder explained it: filters can be used for many different things, before or after an action has been executed. Access control is one specialized filter implementation to solve a particular use case. – ben Aug 25 '13 at 12:25

1 Answers1

0

accessControl aim is authorization but filter can check request,for example run action if request type is POST.

Moein Hosseini
  • 4,309
  • 15
  • 68
  • 106