I added Twig template engine to CodeIgniter 2 using this library:
https://github.com/dilantha/codeigniter-twig
Everything works except dum() function. Using dump troughs this error:
Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'Unknown "dump" function. Did you mean "var_dump", "debug_zval_dump", "xdebug_var_dump", "mysqli_dump_debug_info", "xdebug_dump_superglobals", "xdebug_dump_aggr_profiling_data"?
This is my Twig Template:
{{ dump() }}
And this is my controller:
public function index()
{
$data = ['title' => 'Title' ];
$this->twig->display('dump.twig', $data);
}
CodeIgniter Version: 2.2.0
Twig Version: 1.35.4
This option is not enabled by default in version 1.and codeigniter-twig code missed this.
I added this code to Twig.php library and the problem solved:
if ($debug) {
$this->_twig->addExtension(new Twig_Extension_Debug());
}
I will report this to the author.
Related
This has got to be simple, but I can't see what's wrong. I'm using the simple filter example at https://twig.symfony.com/doc/1.x/advanced.html#filters with Twig 1.34 in Timber, a WordPress plugin.
I added
// an anonymous function
$filter = new Twig_SimpleFilter('rot13', function ($string) {
return str_rot13($string);
});
and
$twig = new Twig_Environment($loader);
$twig->addFilter($filter);
to my theme's functions.php file.
But using {{ 'Twig'|rot13 }} in my view.twig file gives a fatal error
PHP Fatal error: Uncaught exception 'Twig_Error_Syntax'
with message 'Unknown "rot13" filter' in view.twig
and a notice
Undefined variable: loader in functions.php
Using a filter like {{ 'Twig'|lower }} works OK.
Do I need to add the functions to functions.php in a different way?
According to documentation here (title: Adding to Twig)
it should be done like this (in functions.php):
add_filter('timber/twig', function($twig) {
$twig->addExtension(new Twig_Extension_StringLoader());
// add Your filters here
$twig->addFilter(
new Twig_SimpleFilter(
'rot13',
function($string) {
return str_rot13($string);
}
)
);
// or simply:
// $twig->addFilter(new Twig_SimpleFilter('rot13', 'str_rot13'));
$twig->addFilter(
new Twig_SimpleFilter(
'hello',
function($name) {
return 'Hello, '.$name;
}
)
);
return $twig;
});
I use last version of Twig in Codeigniter project, I have an error I don't understand. I load my functions using Twig but I get this error :
Message: An exception has been thrown during the compilation of a
template ("Function () does not exist") in "base.twig".
To load my functions I use :
foreach(get_defined_functions() as $functions)
{
foreach($functions as $function)
{
$this->_twig->addFunction( new \Twig_Function($function) );
}
}
Then in template I try :
{{ base_url('test') }}
I made a var_dump of $twig->getFunctions(), and base_url() is listed.
I just migrated to the last version of Twig, and got this error.
Did I miss something ?
Ok I found the way in Twig 2.2.4 :
foreach(get_defined_functions() as $functions)
{
foreach($functions as $function)
{
$this->_twig->addFunction( new \Twig_SimpleFunction($function, $function) );
}
}
It works.
I am trying to add a codeigniter function $this->session->flashdata() at twig library. But I am getting below error:
Type: Error
Message: Call to a member function flashdata() on null
My code at twig library is:
$this->twig->addFunction(new Twig_SimpleFunction('flash_data', function($data){return $this->session->flashdata($data);}));
and at my twig file I am calling like this: {{ flash_data('login_error') }}
$this->twig->addFunction(new Twig_SimpleFunction('flash_data', function($data){
$obj =& get_instance();
return $obj->session->flashdata($data);
}));
I'm getting the following error in magento administration
Fatal error: Class 'Zend_Log' not found in /home/website/public_html/app/code/community/Uni/Fileuploader/Block/Adminhtml/Fileuploader/Edit/Tab/Products.php on line 241
This is a community extension, which has been working fine on my website. The error makes no sense to me, because the line 241 contains just a closing "}" character.
class Uni_Fileuploader_Block_Adminhtml_Fileuploader_Edit_Tab_Products extends Mage_Adminhtml_Block_Widget_Grid {
...
...
...
public function getRowUrl() {
return '#';
}
public function getGridUrl() {
return $this->getUrl('*/*/productgrid', array('_current' => true));
}
protected function getFileuploaderData() {
return Mage::registry('fileuploader_data');
}
protected function _getSelectedProducts() {
$products = $this->getRequest()->getPost('selected_products');
if (is_null($products)) {
$products = explode(',', $this->getFileuploaderData()->getProductIds());
return (sizeof($products) > 0 ? $products : 0);
}
return $products;
}
} // line 241, where error occurs
I can post the rest of the code, if you need it.
I noticed that if I upgrade to PHP 5.4 version the error disappears, but since 5.4 version causes other errors on my website, I have to continue using 5.3.
Any ideas on how to solve this?
The problem could be the name of one of the methods in your custom class.
Take for example the method name is getData() ,
Try searching for generic method names in your script, such as getData, which might be reserved by some of Magento’s core classes. I figure that these methods have predefined functionality, which your module is missing support for, and Zend then tries to write an exception to Zend log.
Reference link: netismine
I got the same error when rewriting a payment method.
public function authorize($payment, $amount)
Solved rewriting exactly the same main method:
public function authorize(Varien_Object $payment, $amount)
Magento 1.9.1.0/PHP 5.5
I am trying to implement the CI Asset manager found here. After I placed the files in the correct locations and then tried to call the assets in my main view I get the following error
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$assets
Filename: index/index.php
Line Number: 18
What am I forgetting to do that is causing this error?
Line 16-18 are
$this->load->library("Assets");
echo $this->assets->load("ie10mobile.css", "Content");
You have to load library and use it in controller file, not the view.
Sample controller function:
function index()
{
$this->load->library("assets");
$this->data['css'] = array(
$this->assets->load("ie10mobile.css", "Content"),
$this->assets->load("style.css", "Content"),
$this->assets->load("custom.css", "Content")
);
$this->load->view('index_view', $this->data);
}
Sample view file: index_view.php
foreach ($css as file) {
echo $file;
}