I'm a prestashop developper and i want to add my custom function using parameters in a smarty variable.
There's my PHP function
function maFonctionSMarty($params)
{
$array['1'] = $params['monParametre'];
$array['2'] = $params['monParametre1'];
return $array;
}
and in m'y template i try to do this
{$a|maFonctionSMarty:"toto":"tata"}
and i have an error.
Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/Users/guillaume/Sites/prestashop_156/modules/wb_newsletter/admin_panel.tpl" on line 94 "{$a|maFonctionSMarty:"toto":"tata"}" unknown modifier "maFonctionSMarty"' in /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php:667 Stack trace: #0 /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_compile_private_modifier.php(132): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown modifie...', 94) #1 /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php(475): Smarty_Internal_Compile_Private_Modifier->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), Array, NULL, NULL) #2 /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php(259): Smarty_Internal_TemplateCompilerBase->callTagCompil in /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php on line 667
[PrestaShop] Fatal error in module smarty_internal_templatecompilerbase:
Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/Users/guillaume/Sites/prestashop_156/modules/wb_newsletter/admin_panel.tpl" on line 94 "{$a|maFonctionSMarty:"toto":"tata"}" unknown modifier "maFonctionSMarty"' in /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php:667 Stack trace: #0 /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_compile_private_modifier.php(132): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown modifie...', 94) #1 /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php(475): Smarty_Internal_Compile_Private_Modifier->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), Array, NULL, NULL) #2 /Users/guillaume/Sites/prestashop_156/tools/smarty/sysplugins/smarty_internal_templatecompilerbase.php(259): Smarty_Internal_TemplateCompilerBase->callTagCompil
thanks
You have to put that function as a plugin in a separate file named modifier.maFonctionSMarty.php in tools/smarty/plugins. Also, the name of the function has to be different:
function smarty_modifier_maFonctionSMarty($params)
Related
This question already has answers here:
How to get WooCommerce product object in a custom shortcode to avoid errors
(1 answer)
Reference - What does this error mean in PHP?
(38 answers)
Closed 4 months ago.
I use this function via a snippets plugin to add some functionality to my woocommerce Wordpress site:
add_shortcode( 'show_ship_class', 'wpse_295878_shipping_banner' );
function wpse_295878_shipping_banner() {
$product = wc_get_product();
if ($product->get_shipping_class()){
$shipping_class = $product->get_shipping_class();
switch ( $shipping_class ) {
case 'dsk2':
return '<div class="shipdelay"><p>This item typically ships in 2-5 business days</p></div>';
break;
case 'dsk':
return '<div class="shipdelay"><p>This item typically ships in 1-3 business days</p></div>';
break;
}
}
else {
return;
}
}
I am getting these errors in my error log while another plugin is running:
PHP Fatal error: Uncaught Error: Call to a member function get_shipping_class() on bool in /home/m01hurl/public_html/wp-content/plugins/insert-php/includes/class.execute.snippet.php(635) : eval()'d code:5
Stack trace:
#0 /home/m01hurl/public_html/wp-includes/shortcodes.php(356): wpse_295878_shipping_banner('', '', 'show_ship_class')
#1 [internal function]: do_shortcode_tag(Array)
#2 /home/m01hurl/public_html/wp-includes/shortcodes.php(228): preg_replace_callback('/\\[(\\[?)(show_s...', 'do_shortcode_ta...', '<!-- wp:woobuil...')
#3 /home/m01hurl/public_html/wp-content/plugins/media-cleaner/classes/core.php(264): do_shortcode('<!-- wp:woobuil...')
#4 /home/m01hurl/public_html/wp-content/plugins/media-cleaner/classes/parsers/common.php(103): Meow_WPMC_Core->get_urls_from_html('<!-- wp:woobuil...')
#5 /home/m01hurl/public_html/wp-includes/class-wp-hook.php(307): MeowApps_WPMC_Parser_Common->scan_post('<!-- wp:woobuil...', '36805')
#6 /home/m01hurl/public_html/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters('', Array)
in /home/m01hurl/public_html/wp-content/plugins/insert-php/includes/class.execute.snippet.php(635) : eval()'d code on line 5
I assume it is because I whack-a-moled this function together and did something wrong that other code has issue with while accessing the site via the rest-api.
My question to you real programmers is is this something I did wrong in my function?
Im new to custom wordpress widget creation and im trying to create one. I created my widget at wp-content> plugins> custom-widgets> my-custom-widget.php.
This is my code
if(!class_exists("MyCustomWidget")){
class MyCustomWidget extends WP_Widget{
public function __constructor(){
parent::WP_Widget(false,"My custom Widget");
}
public function form($instance){
?>
<p>
<label>Tilte:</label>
<input type="text"/>
</p>
<?php
}
}
function register_my_widget(){
register_widget("MyCustomWidget");
}
add_action("widgets_init", "register_my_widget");
}
When im trying to activate it i get the wordpress fail page and specially the following. What is wrong?
Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0
passed in F:\Downloads\Worpress\Wordpress Local\apache2\htdocs\store\wordpress\wp-includes\class-wp-
widget-factory.php on line 61 and at least 2 expected in F:\Downloads\Worpress\Wordpress
Local\apache2\htdocs\store\wordpress\wp-includes\class-wp-widget.php:162 Stack trace: #0
F:\Downloads\Worpress\Wordpress Local\apache2\htdocs\store\wordpress\wp-includes\class-wp-widget-
factory.php(61): WP_Widget->__construct() #1 F:\Downloads\Worpress\Wordpress
Local\apache2\htdocs\store\wordpress\wp-includes\widgets.php(115): WP_Widget_Factory->register() #2
F:\Downloads\Worpress\Wordpress Local\apache2\htdocs\store\wordpress\wp-content\plugins\custom-widget\wp-
custom-widget.php(34): register_widget() #3 F:\Downloads\Worpress\Wordpress
Local\apache2\htdocs\store\wordpress\wp-includes\class-wp-hook.php(287): register_my_widget() #4
F:\Downloads\Worpress\Wordpress Local\apache2\htdocs\store\wordpress\wp-includes\class-wp-hook.php(311):
WP in F:\Downloads\Worpress\Wordpress Local\apache2\htdocs\store\wordpress\wp-includes\class-wp-
widget.php on line 162
See this answer from wordpress.stackexchange.com for a full correct widget example.
There is a couple of issues with the code in this question:
It's function __construct() and not function __constructor().
As detailed in rich's answer the parent call should be to parent::__construct(..). For example: parent::__construct('', 'Widget name');
In your constructor, you need to pass 2 arguments... so something like this:
public function __constructor(){
parent::__construct('my_custom_widget',v__('My Custom Widget', 'my_text_domain'));
}
WordPress documentation here:
https://developer.wordpress.org/reference/classes/wp_widget/__construct/
I am trying to update customer attribute in Shopware but am getting an error:
$builder = $this->container->get('models')->createQueryBuilder()
->update(\Shopware\Models\Customer\Customer::class, 'customer')
->set('customer.active',0)
->where('customer.email= :email')
->setParameter('email ' ,'xyz#test.com');
$builder->getQuery()->execute();
Fatal error: Uncaught Doctrine\ORM\Query\QueryException: Invalid
parameter: token email is not defined in the query. in
/var/www/html/shopware/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php:134
Stack trace: #0
/var/www/html/shopware/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(362):
Doctrine\ORM\Query\QueryException::unknownParameter('email ') #1
/var/www/html/shopware/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(319):
Doctrine\ORM\Query->processParameterMappings(Array) #2
/var/www/html/shopware/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(962):
Doctrine\ORM\Query->_doExecute() #3
/var/www/html/shopware/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(917):
Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(NULL, NULL) #4
/var/www/html/shopware/custom/plugins/CustomPlugin/Controllers/Frontend/CustomPlugin.php(17):
Doctrine\ORM\AbstractQuery->execute() #5
/var/www/html/shopware/engine/Library/Enlight/Controller/Action.php(193):
Shopware_Controllers_Frontend_CustomPlugin->indexAction() # in
/var/www/html/shopware/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php
on line 134
How can I fix this?
Try to use a where statement like this;
->where('customer.email = ?1')->setParameter(1 ,'xyz#test.com');
I get this error. I created a button to update the table. When I click the button, I get an error. How to fix it?
Fatal error: Uncaught ArgumentCountError: Too few arguments to function personel::update_form(), 0 passed in C:\xampp\htdocs\warehouse\panel\system\core\CodeIgniter.php on line 360 and exactly 1 expected in C:\xampp\htdocs\warehouse\panel\application\controllers\personel.php:57 Stack trace: #0 C:\xampp\htdocs\warehouse\panel\system\core\CodeIgniter.php(360): personel->update_form() #1 C:\xampp\htdocs\warehouse\panel\index.php(202): require_once('C:\xampp\htdocs...') #2 {main} thrown in C:\xampp\htdocs\warehouse\panel\application\controllers\personel.php on line 57
Fİle Name: personel.php Controller
MY CODES
public function update_form($id){
$where = array( "id" => $id);
$personel = $this->Personel_model->get($where);
$viewData["personel"] = $personel;
$this->load->view("personel_edit");
}
MY BUTTON CODES
Update
You must pass an ID with the button to function in the controller like this.
Update
I'm trying to get my Page Entities using the Doctrine QueryBuilder. I have succesfully implemented the ORM and it generated my database without any trouble. Now that I want to grab the Entities from the database, it seems to return a QueryException
Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'SELECT page FROM Website\Model\Body\Page page WHERE page.isActive = 1' in path\to\orm\Doctrine\ORM\Query\QueryException.php:39
Stack trace:
#0 path\to\orm\Doctrine\ORM\Query\Parser.php(429): Doctrine\ORM\Query\QueryException::dqlError('SELECT page FRO...')
#1 path\to\orm\Doctrine\ORM\Query\Parser.php(854): Doctrine\ORM\Query\Parser->semanticalError('Class 'Website\...', Array)
#2 path\to\orm\Doctrine\ORM\Query\Parser.php(1529): Doctrine\ORM\Query\Parser->AbstractSchemaName()
#3 path\to\orm\Doctrine\ORM\Query\Parser.php(1426): Doctrine\ORM\Query\Parser->RangeVariableDeclaration()
#4 path\to\orm\Doctrine\ORM\Query\Parser.php(1168): Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration()
#5 path\to\orm\Doctrine\ORM\Query\Parser.php(757): Doctrine\ORM\Query\Parser->FromClause()
#6 path\to\ in path\to\orm\Doctrine\ORM\Query\QueryException.php on line 49
This piece of code causes the trouble
public function getActivePages()
{
$qb = \WebTools\Doctrine\Doctrine::instance()->getQueryBuilder();
$qb->select('page')
->from('Website\Model\Body\Page', 'page')
->where($qb->expr()->eq("page.isActive", true));
$query = $qb->getQuery();
$result = $query->getResult();
\Doctrine\Common\Util\Debug::dump($result);
die();
return $result;
}
Any help is appreciated, thanks
Try
$qb->select('page')
->from('Page', 'page')
or
$qb->select('page')
->from('\Website\Model\Body\Page', 'page')
and make sure your class is mapped by dotrine.