php - how to retrieve a value that is entered on localhost from another model -
first of all, let me clarify myself. baked on cakephp , entering values on localhost in application. basicly, there 2 models called location
, temp_readings
.
in location
model, there temperature limits called high_temp
, low_temp
. , name of location. enter values, (e.g. name= fridge, low_temp= 3, high_temp= 7
)
in temp_readings
model, enter temperature value specific location, (e.g. temperature= 10, location= frigde
).
if temp value out of limits, app sending warning email me.
i work on temp_readings.php
script doing , need put condition sending email.
i think, can value of temperature writing;
$temperature = $this->data['temp_readings']['temperature'];
since working in temp_readings.php
.
however, cannot values of low_temp
, high_temp
, saved under location model.
how can low_temp , high_temp values work in temp_readings.php?
here part of temp_readings.php (i dont know if helps)
class temp_readings extends appmodel { function aftersave($created, $options = array()) { //pr($this); //$temperature = $this->data['temperaturereading']['temperature']; //$low_temp= //$high_temp= if ($temperature > $high_temp && $temperature < $low_temp) { $email = new cakeemail('gmail'); $email->from(array('****@gmail.com' => 'my site')); $email->to('***@gmail.com'); $email->subject('temperature warning!'); $email->send('temperature @ critical value of'); } }
you should have belongsto
relationship between temp_readings
, location
, so:
class temp_readings extends appmodel { public $belongsto = [ 'location' // don't know data structure, you'll need add details here ]; /* ... */ }
then, after saving:
function aftersave($created, $options = array()) { $temperature = $this->data['temperaturereading']['temperature'] ; $location = $this->data['location'] ; /* ... */ }
of course, code needs changes because don't know database structure should give hint on should do.
Comments
Post a Comment