2

This is my url link and device return corresponding value in browser body. Now I insert this data into my database table name IpRelay. First I explode my device return data. Then I am trying to insert exploded data.

Here is my code. But it doesn't work.

public function get_data(){
    $contents = file_get_contents('http://10.5.40.83');
    function multiexplode ($delimiters,$string) {
        $ready = str_replace($delimiters, $delimiters[0], $string);
        $launch = explode($delimiters[0], $ready);
        return  $launch;
    }
    $get_device_data = multiexplode(array(",",":",), $contents);

    $this->IpRelay->create();
    $this->IpRelay->set($this->request->data['get_device_data']);
    $save = $this->IpRelay->save();
    echo $save ? "I've created the link" : "Error creating link!";
    die($this->IpRelay->id);
}

I am new in cakephp and I am using cake version 2.7.5. Would you help me please.

url=> http://10.5.40.83/ 
device return value=> 10,5,40,83:0,11,0,0,556

enter image description here

2 Answers 2

1

Hope it is easier and helpful for your

$this->Model_name->read(null, 1);
$this->Model_name->set(
    array(
        'field_1'     => $get_device_data[0],
        'field_2'     => $get_device_data[1]
    )
);

$this->Model_name->save();
Sign up to request clarification or add additional context in comments.

Comments

1
$this->IpRelay->create();
$this->IpRelay->set($this->request->data['get_device_data']);
$save = $this->IpRelay->save();
echo $save ? "I've created the link" : "Error creating link!";
die($this->IpRelay->id);

Instead of above code I am using below this code and it works properly

$this->IpRelay->read(null, 1);
$this->IpRelay->set(array(
    'a'     => $get_device_data[0],
    'b'     => $get_device_data[1],
    'c'     => $get_device_data[2],
    'd'     => $get_device_data[3],
    'e'     => $get_device_data[4],
    'f'     => $get_device_data[5],
    'g'     => $get_device_data[6],
    'h'     => $get_device_data[7],
    'volt'  => $get_device_data[8]
));
$this->IpRelay->save();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.