megane72 Posted March 21, 2014 Share Posted March 21, 2014 Hi, I need some hint or help to progress on my development of a new module. I'm trying to create an admin module that will create a new admin entry that when called will use curl to get informations from some b2b http supplier page and hopefully update the DB with those infos. Now I have succesfully created a new module starting from a skeleton module. It will install and create the new entry in admin menu: public function install() { $tab = new Tab(); // Need a foreach for the language $tab->name[$this->context->language->id] = $this->l('cURL Parsing'); $tab->class_name = 'CurlParsing'; $tab->id_parent = 17; $tab->module = $this->name; $tab->add(); // Don't know if the following hooks are needed, I leave those there anyway if (!parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('displayHeader') || !$this->registerHook('displayBackOfficeHeader') || !$this->registerHook('displayAdminHomeQuickLinks')) return false; return true; } and uninstall clean public function uninstall() { // Uninstall Tabs $tab = new Tab((int)Tab::getIdFromClassName('CurlParsing')); $tab->delete(); if (!parent::uninstall()) return false; return true; } it calls correctly the controller from the menu entry /modules/curlparsing/controllers/admin/CurlParsingController.php <?php class CurlParsingController extends ModuleAdminController { public function display() { parent::display(); /* {l s='Hello World' mod='curlparsing'}; */ /* $contents=$this->get_web_page('http://www.google.com'); */ /* $this->get_web_page('http://www.google.com'); */ $this->context->smarty->get_web_page('http://www.google.com'); } public function __construct() { parent::__construct(); } public function initContent() { parent::initContent(); /* $this->setTemplate(_PS_THEME_DIR_.'mypage.tpl'); */ /* $this->setTemplate(_PS_ROOT_DIR_.'/modules/curlparsing/curlparsing.tpl'); */ /* $this->context->smarty->createTemplate(_PS_ROOT_DIR_.'/modules/curlparsing/curlparsing.tpl', parent); */ } public function get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "spider", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_SSL_VERIFYPEER => false // Disabled SSL Cert checks ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } /* $contents=$this->get_web_page('http://www.google.com'); */ } but i'm stuck there, you can notice above my various commented attempts. I don't know how and where to call the function get_web_page in order at least to visualize the remote page as an admin page or to visualize the source of the page, is the same for me. After solving this I will continue implementing auth before calling the page and DB update (but i leave those for future help only if I got stuck again). Please keep in mind that i'm a newbie on php and PS so i could need some basic information. I try to search this info on PS manual and various forums, I learned a lot but not enough... Thank you all in advance. Link to comment Share on other sites More sharing options...
maxbrus Posted March 28, 2016 Share Posted March 28, 2016 So did you solve the problem? Do you have a working code? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now