0

I am using TankAuth with Codeigniter, and I was wondering if it is alright to call library specific methods from the view, as opposed to passing them from the controller? For example,

$this->tank_auth->is_logged_in() 

Called from the view is so much more convenient for outputting dynamic HTML than passing the variables from the controller. However, is it safe? Is it an acceptable practice?

tereško
  • 58,060
  • 25
  • 98
  • 150
styke
  • 2,116
  • 2
  • 23
  • 51
  • Its better from your Controller to set template variable $user (for example) which to equals false when user is not logged in, or array with user information when he is logged in :) This way you will be able to know if its false or to use his user data.. – Svetoslav Apr 10 '13 at 09:10
  • as @Svetlio suggested it is better to do it in the controller and in my opinion always will be better(if you use some complex structure of authentication) to put it in a model and make the controller only to pass the information to it and then get legitime results. Controller is not the data police: http://www.survivethedeepend.com/zendframeworkbook/en/1.0/the.model#zfbook.the.model.controllers.are.not.the.data.police (it does not on apply onlly for ZF but all other frameworks as well IMHO) – DaGhostman Dimitrov Apr 10 '13 at 09:14

1 Answers1

0

There is no reason why you cannot do that but its against the MVC concept. You could have these kind of things set in the constructor of an extended controller so you have variables like $is_logged_in available in all your controllers to make it easier.

AJReading
  • 1,193
  • 20
  • 35
  • It's not "against MVC concepts", just against what most frameworks which don't understand MVC want. The view can have access to anything it needs to *visualize the current state of the app*. If that means calling methods on objects, fine. It just shouldn't do anything *"active"* with those objects. The controller having to set everything in variables is quite the anti-MVC pattern. – deceze Apr 10 '13 at 09:13