saving changes in shape

Post Reply
skif88
Jr. Bludit
Posts: 6
Joined: Thu Apr 08, 2021 2:26 pm

Hello.
I wrote a parser plugin. I get the data and save it to a file in json format. I also get it all out.
In the control panel, I display data through a table: name, price 1, name 2, price 2.
Name 1, price 1 are the data that is parsed and saved, and name 2 and price 2 are the data that I want to enter and save them to the same file, but I can't save them in any way.
I just don't understand how to save them to a file in bludit.
Sorry for my english (google translate)
Безымянный.png
Безымянный.png (21.23 KiB) Viewed 1046 times
i have used many save options but none work

Code: Select all

<?php

class priceList extends Plugin {

	public function init() {
		$this->dbFields = array(
			'last_data_now'=>'1',
		);
	}
	
	public function form() {
	    //$this->price_parser_new();
	   
	    $pricelist = file_get_contents('array.txt');
	    $outmsv=json_decode($pricelist, true);
	    $i = 0;
	    echo '<table><tbody><tr>
	    <td>Наименование</td>
	    <td>Розничная цена</td>
	    <td>Наименование KRDMET</td>
	    <td/>Цена KRDMET<td>
	    </tr>
	    ';
	    foreach($outmsv as $list) {
	        echo '<tr>';
	        echo '<td><input name="'.$list['Наименование'].'" value="'.$list['Наименование'].'" type="text"></td>';
	        echo '<td><input name="'.$list['Розничная цена'].'" value="'.$list['Розничная цена'].'" type="text"></td>';
	        echo '<td><input name="'.$list['Наименование KRDMET'].'" value="'.$list['Наименование KRDMET'].'" type="text"></td>';
	        echo '<td><input name="'.$list['Цена KRDMET'].'" value="'.$list['Цена KRDMET'].'" type="text"></td>';
	        echo '</tr>';
	        
	        if(++$i == 3) break;
	    }
	    
	} 
	
//Обработка цен сайта ферратек
    public function price_parser_new() {
        
    //вывод ошибок
        error_reporting(E_ALL);
        ini_set('display_errors', 1);
        
    //подключение страницы и вывод данных
        require_once ('phpQuery-onefile.php');
        $html = phpQuery::newDocument(file_get_contents('https://www.ferratek.com/price'));
        
    //извлечение нужных данных  
        //акутальная дата цен
        $last_data = $html->find('#block-views-block-glavnaya-vygruzka-block-1 div  div div.import-header p:eq(0)')->text();
        
        $this->last_data_now = $last_data;
        
        //блоки с данными
        $all_metal = $html->find('div.priceContent');
        
        //цикл разбива на массив
        foreach ($all_metal as $info) {
            $metal[] = array (
                "Наименование" => trim($name[] = pq($info)->find('div.name')->text()),
                "Оптовая цена" => trim($opt_price[] = pq($info)->find('div.priceBlock:eq(0)')->text()),
                "Розничная цена" => trim($roz_price[] = pq($info)->find('div.priceBlock:eq(1)')->text()),
                "Наименование KRDMET" => "",
                "Цена KRDMET" => "0",
                "Показыват в списке" => 0
                );
        }
        
    //запись в файл полученных цен
        //файл записи
        $filename = 'array.txt';
        
        //Запись.
        $data = json_encode($metal);  // JSON формат сохраняемого значения.
        file_put_contents($filename, $data);
        
        echo $last_data.'<br/>';
        
        echo '<input id="last_data_now" name="last_data_now" type="text" value="'.$this->getValue('last_data_now').'">';
    }

}
?>
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

skif88 wrote: Thu Apr 08, 2021 2:46 pm I just don't understand how to save them to a file in bludit.
file_put_contents should work.

See for example the plugin Simple Stats:

https://github.com/bludit/bludit/blob/b ... n.php#L203

Is there an error message in the log or error file?
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
skif88
Jr. Bludit
Posts: 6
Joined: Thu Apr 08, 2021 2:26 pm

Edi wrote: Thu Apr 08, 2021 5:33 pm
skif88 wrote: Thu Apr 08, 2021 2:46 pm I just don't understand how to save them to a file in bludit.
file_put_contents should work.

See for example the plugin Simple Stats:

https://github.com/bludit/bludit/blob/b ... n.php#L203

Is there an error message in the log or error file?
I do not understand how to save it to bludit.
How to transfer data written in the form in it. What function?
Post Reply