1 year ago

Using PHP functions in view

Posted 1 year ago by ochirach


I have a php function (named 'weeks_in_month') that calculates and returns the number of weeks in a month (parameters: month,year). I want to use this functions result within the view i.e

$number_of_weeks_in_current_month = weeks_in_month($current_month_number, $current_year);

There are $number_of_weeks_in_current_month week(s) in this month

How can I go about this? Is a new controller needed for this? or is this a job for Service Injection? This views controller currently has the 1 function to return the view from a get request.

I will want to store globally used functions like these within a single file for future use

Please sign in or create an account to participate in this conversation.