CakePHP

How to call Model’s method from within the View in CakePHP

Calling Model’s method is against the CakePHP conventions. Model methods should be called in controller function and then result should be set as variable to use in view.  But due to any reason if you need to call directly in view then you can use below script:

 App::import("Model", "PublicHoliday");  // here PublicHoliday is model name, change with your own Model name
 $HolidayModel = new PubHoliday();
 $is_holiday= $HolidayModel->check_if_holiday($date_value); // here check_if_holiday is a method inside PublicHoliday Model
 

Implement its and let me know if any issue, thanks.

Comments (1)

  1. i do this above code but not working plz send how to call from controller to view

Comment here