How can I use composer to install dompdf, and load this into a controller class in opencart 3.
I have tried to use composer require dompdf... however this doesn't work, I'm not sure what directory this needs to be run in
In your composer.json file, add the Dompdf package:
{
"require": {
"dompdf/dompdf": "dev-master"
}
}
And then run: composer update
To use DOMPDF in an opencart controller, all you have to do is:
<?php
class ControllerExampleEmail extends Controller {
public function index() {
$dompdf = new DOMPDF();
}
}
It's auto-loaded by OpenCart itself.
Only really posting this as an answer to get the formatting, but I was just looking at exactly the same thing (adding DOMPDF to OpenCart 3) and (having already done the composer bit) have gotten this far (which will spit out a PDF):
<?xml version="1.0" encoding="utf-8"?>
<modification>
<name>DOMPDF Test</name>
<code>dompdftest</code>
<version>3.0.3x</version>
<author>TH</author>
<link></link>
<file path="system/library/response.php">
<operation error="abort">
<comment>Use the class</comment>
<search><![CDATA[class Response {]]></search>
<add position="before"><![CDATA[
use Dompdf\Dompdf;
]]></add>
</operation>
<operation error="abort">
<comment>Output to PDF instead of HTML</comment>
<search><![CDATA[private $output;]]></search>
<add position="after"><![CDATA[
// TH
public function writePDF($input,$filename) {
$dompdf = new Dompdf();
$dompdf->loadHtml($input);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream($filename);
}
// /TH
]]></add>
</operation>
</file>
</modification>
Have only tested this insofar as it spits out a PDF, it could well be wrong/not the best way to do it.
Related
Something is not right. CodeIgniter... the output is not in xml format. Just found out an hour ago that i can see the sitemap php page businessclaud.co.ke/sitemap but its not in xml format... take a look and please help
I have this controller named Sitemap.php
<?php
class Sitemap extends Controller {
public function __construct(){
require APPROOT.'/views/inc/load_models.php';
}
public function index(){
$this->view('sitemap/index');
}
}
Also created the view index.php and uploaded to the site shown below
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<!-- created with Free Online Sitemap Generator www.xml-sitemaps.com -->
<url>
<loc>https://businessclaud.co.ke/</loc>
<lastmod>2021-06-19T02:02:46+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>1.00</priority>
</url>
<url>
<loc>https://businessclaud.co.ke/admin/users/login</loc>
<lastmod>2021-06-19T02:02:46+00:00</lastmod>
<changefreq>daily</changefreq>
<priority>0.80</priority>
</url>
enter link description here
Something is not right. Just found out an hour ago that i can see the php xml page businessclaud.co.ke/sitemap but its not in xml format... take a look and please help
I found out that since the sitemap view is in php format that is index.php what you need to do is tell the browser to treat it as xml. This is done by defining the header header("Content-type: text/xml");.
If you are facing a problem like this, go to your controller and add this line header("Content-type: text/xml");.
<?php
class Sitemap extends Controller {
public function __construct(){
// require APPROOT.'/views/inc/load_models.php';
}
public function index(){
header("Content-type: text/xml");
$this->view('sitemap/index');
}
}
And just like that, the site is ready to submit a sitemap.
I am in new Magento 2 and have created a custom module, its working fine with the url(http:///modulename/index/test) but need to call it on home page. I mean when home page loaded, module would be called automatically. How it possible?
Below is the steps which I followed during module creation -
Step 1: Created the Namespace and module folder
Step 2: Created etc/module.xml file
<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ignvia_HelloWorld" setup_version="1.0.0">
</module>
Step 3: Created etc/registration.php file
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Ignvia_HelloWorld',
DIR
);
Step 4: Created etc/frontend/routes.xml file
<?xml version="1.0" ?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
<route frontName="helloworld" id="helloworld">
<module name="Igniva_HelloWorld"/>
</route>
</router>
Step 5: Created Controller/Index/Test.php
<?php
namespace Igniva\HelloWorld\Controller\Index;
class Test extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\View\Result\PageFactory $pageFactory)
{
$this->_pageFactory = $pageFactory;
return parent::__construct($context);
}
public function execute()
{
echo "Hello World";
exit;
}
}
Thanks.
To load your custom module in homepage, your code should be called in cms_index_index layout(not in core file).you have to define in custom file.
my over all goal is to grab the articles content after they have saved it and send it though my API. It's stated that onContentAfterSave is fired after they save to the database, my database is getting updated, but nothing coming though api.
Im using Joomla! 3.2.3 Stable
Owtest is my api call, it currently has hard coded data in it.
I feel im either extending the wrong class or missing an import. code below.
<?php
// no direct access
defined('_JEXEC') or die;
jimport('joomla.plugin.plugin');
class plgContentHelloworld extends JPlugin
{
public function onContentAfterSave( $context, &$article, $isNew )
{
owTest();
}
}
?>
Xml Code:
<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" group="content" method="upgrade">
<name>plg_content_helloworld</name>
<author>Keith</author>
<creationDate>March 18th, 2014</creationDate>
<copyright></copyright>
<license>GNU General Public License</license>
<authorEmail></authorEmail>
<version>1.0</version>
<files>
<filename plugin="helloworld">helloworld.php</filename>
<filename>index.html</filename>
</files>
</extension>
file names are helloworld.php and helloworld.xml respectfully.
what solved my problem was passing article by value and not reference
problem is self made module not working- I make my self made module in Joomla 3.0. I made a mod_products folder here we created a file called mod_products.php.
mod_products.php - code
defined('_JEXEC') or die;
require_once __DIR__ . '/helper.php';
$value = modProductsHelper::getproducts( $params );
require JModuleHelper::getLayoutPath('mod_products', $params->get('layout', 'default'));
and after it I made second file helper.php code -
class modProductsHelper{
public static function getProducts( $params ){
return 'Products';
}
}
and third one is default.php
<?php
defined('_JEXEC') or die;
if($value!='') { ?>
<ul style="margin-left: 0px;" class="clients-list slides-list slide-wrapper">
<li class="slide">
<div class="product-image"><img src="images/product3.png" width="181" height="177"></div>
</li>
</ul>
<?php } ?>
Then we install through administrator panel and gave a position to the mod_products module and display in index.php file like so:
<div class="grid_12 product_home">
<jdoc:include type="modules" name="position-3" />
</div>
But it's not being displayed on the site. Does anyone have any idea why?
Edit:mod_products.xml
<?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.0" client="site" method="upgrade">
<name>mod_products</name>
<author>Joomla! Project</author>
<creationDate>July 2004</creationDate>
<copyright>Copyright (C) 2005 - 2013 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin#joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>MOD_PRODUCTS_XML_DESCRIPTION</description>
<files>
<filename module="mod_products">mod_products.php</filename>
<folder>tmpl</folder>
<filename>helper.php</filename>
<filename>mod_products.xml</filename>
</files>
<config>
</config>
</extension>
Right, I've created a small example for you. I think it might have been due to you calling the wrong module layout, not entirely sure.
Here is a link to download the module. Uninstall the current module you're using via the Joomla backend and install this:
http://www.mediafire.com/download/ucp3prv219430zl/mod_products.zip
Also, don't forget to assign the module to a menu item. That might have been the problem before
Enjoy
For me it seems your problem is module name.In some places you have used mod_product and in other places mod_products Please make sure you use only one.I will suggest you to change
require JModuleHelper::getLayoutPath('mod_products', $params->get('layout', 'default'));
to
require JModuleHelper::getLayoutPath('mod_product', $params->get('layout', 'default'));
Also check that you have published the module and also test it for all pages.
As stated in the subject, I am trying to add a date field with its date picker in the System > Configuration area for a custom module (thus using etc/system.xml).
I tried to get inspiration from the thread below :
Magento - Add a button to system.xml with method attached to it
but no success.
I'm sure this is a question of creating the right block or method to create a custom html field but I cannot read thru the Magento Matrix :)
I am stuck at the step where I need to code the class (Datefield.php):
<?php
class Namespace_Module_Block_Datefield extends Mage_Adminhtml_Block_System_Config_Form_Field {
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
// ----> Am I wrong in calling ..._Abstract? Should I call Varien_Data_Form_Element_Date? I've tried but no success either...
$this->setElement($element);
$html = // ------------------> what to put here? Call a block or some other method?
->setFormat('d-m-Y')
->setLabel($this->__('Choose date'))
->toHtml();
return $html;
}
}
?>
Do you have a trick on how to do that ?
Thanks a lot.
Hervé
EDIT 02/19/2014: added validation
I found what I think is a more elegant way of doing this. Actually, satrun77 methods is ok but we must place a file in Varien/Data/Form/Element/ which can be overwritten if someone else working on the project unluckily uses the same file/class name. Moreover, this method places the file in the module directories which is, I think, better than distributing files all over the directory tree.
In system.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
....
<fields>
...
<run translate="label">
<label>Date</label>
<frontend_type>text</frontend_type> <!-- Use text instead of "myDateSelection" -->
<frontend_model>module/adminhtml_system_config_date</frontend_model> <!-- Call a module specific renderer model -->
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<validate>required-entry</validate> <!-- Optional -->
<show_in_store>1</show_in_store>
</run>
</fields>
...
</config>
Create a new file :
app/code/[local, community]/Namespace/Module/Block/Adminhtml/System/Config/Date
with the content below:
class Namespace_Module_Block_Adminhtml_System_Config_Date extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$date = new Varien_Data_Form_Element_Date;
$format = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
$data = array(
'name' => $element->getName(),
'html_id' => $element->getId(),
'image' => $this->getSkinUrl('images/grid-cal.gif'),
);
$date->setData($data);
$date->setValue($element->getValue(), $format);
$date->setFormat(Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT));
$date->setClass($element->getFieldConfig()->validate->asArray());
$date->setForm($element->getForm());
return $date->getElementHtml();
}
}
Create class file in app/code/local/Varien/Data/Form/Element/. Make sure the file name is prefixed with something that identify your module (this is just to differentiate your custom code from Magneto core files)
class Varien_Data_Form_Element_MyDateSelection extends Varien_Data_Form_Element_Date
{
public function getElementHtml()
{
// define image url
$this->setImage(Mage::getDesign()->getSkinUrl('images/grid-cal.gif'));
// define date format
$this->setFormat('yyyy-MM-dd');
return parent::getElementHtml();
}
}
Inside your module system.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
....
<fields>
...
<run translate="label">
<label>Run now</label>
<frontend_type>myDateSelection</frontend_type>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</run>
</fields>
...
</config>
Placing custom code inside lib/ folder or app/Mage/Core/ folder is not the best way to create custom code for Magento. These folders are for core code and not custom code.
This approach creates the least amount of code and does not change any of the core files. So, there isn't any harm from having extra file inside the lib/ folder. But you need to remember that you have extra file for your module in the lib/.
Hope this helps