Call a controller inside a template and another controller in Fatfree framework

StackOverflow https://stackoverflow.com/questions/16255894

  •  13-04-2022
  •  | 
  •  

سؤال

i'd like to know if i can call a controller action inside a template, and inside another controller in fatFree framework (F3).

هل كانت مفيدة؟

المحلول

I'm not sure if i understand you corrently, but calling a Class method in Template would go like this:

{{ MyConroller->doSomething() }}

Of cause you could call one controller within another too... just use raw php

$obj = new MyController(); $obj->foo();

or use the F3 call method $f3->call('MyController->doSomething');

Also check out the new API docs.

http://fatfreeframework.com/base#call

It's still under construction, but hopefully you'll find more information about this or any other framework part very soon.

نصائح أخرى

Many MVC purists would balk at the idea of a View (template) calling methods on the Controller. They would say that the controller needs to provide the data that the view needs, or at least give it the Model, so that it can retrieve data from there.

Furthermore, the View probably shouldn't be doing anything (or asking another component to do anything), other than generating the display. But can query the Model for data. But maybe by doSomething() you do mean getSomeData().

While I'm not an MVC purist I do agree with the idea of keeping logic and functionality out of the view if at all possible.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top