Im working on a script that i download online but when i install codeigniter it brings this.
Severity: Warning
Message: Declaration of MY_Lang::line($line = '') should be compatible with CI_Lang::line($line, $log_errors = true)
Filename: core/MY_Lang.php
Line Number: 41
And here's my Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Lang extends CI_Lang {
// --------------------------------------------------------------------
/**
* Load a language file
*
* #access public
* #param mixed the name of the language file to be loaded. Can be an array
* #param string the language (english, etc.)
* #param bool return loaded array of translations
* #param bool add suffix to $langfile
* #param string alternative path to look for language file
* #return mixed
*/
function load($langfile = '', $idiom = '', $return = FALSE, $add_suffix = TRUE, $log_errors = TRUE, $alt_path = '', $line ='')
{
parent::load($langfile, $idiom, $return, $add_suffix, $alt_path, $log_errors, $line);
}
function get_array()
{
return $this->language;
}
function line($line = '')
{
$value = ($line == '' OR ! isset($this->language[$line])) ? FALSE : $this->language[$line];
// Because killer robots like unicorns!
if ($value === FALSE)
{
log_message('debug', 'Could not find the language line "'.$line.'"');
}
return $value;
}
}
i don't know where is wrong, i already brake a little of fatal error warnings, but this one has my dry.
On the other hand, a second mistake that bounces me is this
Message: Call to undefined function config_db_item()
Filename: /home/casabla6/public_html/application/core/MY_Loader.php
and in the controller i have this.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Loader extends CI_Loader
{
function __construct()
{
parent::__construct();
$this->_ci_view_paths += array(FCPATH.'templates/'=>TRUE);
}
public function view($view, $vars = array(), $return = FALSE)
{
$admin_template = '';
if( config_db_item ('admin_template') !== FALSE)
$admin_template = config_db_item('admin_template');
if(strpos($view, 'admin/') === 0)
$view = $admin_template.'/'.$view;
if(isset($vars['subview']))
{
if(strpos($vars['subview'], 'admin/') === 0)
$vars['subview'] = $admin_template.'/'.$vars['subview'];
}
return parent::view($view, $vars, $return);
}
function common_view($view, $vars = array(), $return = FALSE)
{
$view = 'common/'.$view;
return parent::view($view, $vars, $return);
}
}
?>
can u give me a hand please?
Your class MY_Lang extends CI_Lang, which means the method MY_Lang::line() should have a definition that matches the method CI_Lang::line().
The original method in CI_Lang:
public function line($line, $log_errors = true)
Your extension in MY_Lang:
public function line($line = '')
You'll need to change your code to take the same arguments:
public function line($line, $log_errors = true)
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 1 year ago.
on this site I use magento and theme :
http://www.herbalheaven.co.uk
Everything works good but when you go on categories I got the same error for all of them :
http://www.herbalheaven.co.uk/herbal-ayurveda.html
Parse error: syntax error, unexpected '' (T_NS_SEPARATOR), expecting function (T_FUNCTION) or const (T_CONST) in /home/herbalheaven/public_html/app/code/MageBig/AjaxFilter/Plugin/Catalog/Product/ProductList/Toolbar.php on line 16
And here is the code :
<?php
/**
* Copyright © www.magebig.com - All rights reserved.
* See LICENSE.txt for license details.
*/
namespace MageBig\AjaxFilter\Plugin\Catalog\Product\ProductList;
use MageBig\AjaxFilter\Model\Layer\Filter\Rating;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Registry;
use Magento\Store\Model\ScopeInterface;
class Toolbar
{
private \Magento\Catalog\Model\Product\ProductList\Toolbar $toolbarModel;
private RequestInterface $request;
private Registry $coreRegistry;
private ScopeConfigInterface $scopeConfig;
public function __construct(
\Magento\Catalog\Model\Product\ProductList\Toolbar $toolbarModel,
ScopeConfigInterface $scopeConfig,
Registry $coreRegistry
)
{
$this->toolbarModel = $toolbarModel;
$this->scopeConfig = $scopeConfig;
$this->coreRegistry = $coreRegistry;
}
public function aroundSetCollection(
\Magento\Catalog\Block\Product\ProductList\Toolbar $subject,
\Closure $proceed,
$collection
) {
if (!$this->coreRegistry->registry('product_filter_collection')) {
$c1 = clone $collection;
$c1->setOrder('price', 'desc')->getFirstItem();
$this->coreRegistry->register('product_filter_collection', $c1);
}
$order = $subject->getCurrentOrder();
$result = $proceed($collection);
$ratingCode = Rating::RATING_CODE;
if ($ratingCode && ($order == $ratingCode)) {
$direction = $subject->getCurrentDirection();
$searchEngine = $this->scopeConfig->getValue('catalog/search/engine', ScopeInterface::SCOPE_STORE);
if ($searchEngine == 'mysql') {
$collection->setOrder('rating_summary', $direction);
} else {
$collection->setOrder('rating', $direction);
}
}
return $result;
}
/**
* #param $subject
* #param $dir
* #return string
*/
public function afterGetCurrentDirection($subject, $dir)
{
$defaultDir = $subject->getCurrentOrder() == 'rating' ? 'desc' : $dir;
$subject->setDefaultDirection($defaultDir);
if (!$this->toolbarModel->getDirection()) {
$dir = $defaultDir;
}
return $dir;
}
}
Please use below code
<?php
/**
* Copyright © www.magebig.com - All rights reserved.
* See LICENSE.txt for license details.
*/
namespace MageBig\AjaxFilter\Plugin\Catalog\Product\ProductList;
use MageBig\AjaxFilter\Model\Layer\Filter\Rating;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Registry;
use Magento\Store\Model\ScopeInterface;
use Magento\Catalog\Model\Product\ProductList\Toolbar as defaultToolbar;
class Toolbar
{
private defaultToolbar $toolbarModel;
private RequestInterface $request;
private Registry $coreRegistry;
private ScopeConfigInterface $scopeConfig;
public function __construct(
defaultToolbar $toolbarModel,
ScopeConfigInterface $scopeConfig,
Registry $coreRegistry
)
{
$this->toolbarModel = $toolbarModel;
$this->scopeConfig = $scopeConfig;
$this->coreRegistry = $coreRegistry;
}
public function aroundSetCollection(
defaultToolbar $subject,
\Closure $proceed,
$collection
) {
if (!$this->coreRegistry->registry('product_filter_collection')) {
$c1 = clone $collection;
$c1->setOrder('price', 'desc')->getFirstItem();
$this->coreRegistry->register('product_filter_collection', $c1);
}
$order = $subject->getCurrentOrder();
$result = $proceed($collection);
$ratingCode = Rating::RATING_CODE;
if ($ratingCode && ($order == $ratingCode)) {
$direction = $subject->getCurrentDirection();
$searchEngine = $this->scopeConfig->getValue('catalog/search/engine', ScopeInterface::SCOPE_STORE);
if ($searchEngine == 'mysql') {
$collection->setOrder('rating_summary', $direction);
} else {
$collection->setOrder('rating', $direction);
}
}
return $result;
}
/**
* #param $subject
* #param $dir
* #return string
*/
public function afterGetCurrentDirection($subject, $dir)
{
$defaultDir = $subject->getCurrentOrder() == 'rating' ? 'desc' : $dir;
$subject->setDefaultDirection($defaultDir);
if (!$this->toolbarModel->getDirection()) {
$dir = $defaultDir;
}
return $dir;
}
}
If this code work, I have explain how its work
Error: In your code you have added extra \ slashed in line on 16.
Step 1: First I have include default Toolbar Class with the alias of defaultToolbar.
use Magento\Catalog\Model\Product\ProductList\Toolbar as defaultToolbar;
Step 2: I have replace all manual path with the alias name.
Thanks
I have opencart 3 installed on my dev box and have suddenly started getting the following error:
Fatal error: Class Twig_Loader_Filesystem contains 2 abstract methods
and must therefore be declared abstract or implement the remaining
methods (Twig_LoaderInterface::isFresh,
Twig_ExistsLoaderInterface::exists) in
/mnt/c/wsl/server/opencart/system/library/template/Twig/Loader/Filesystem.php
on line 17
I have been working on a custom template and all was going fine until I changed something in the controller of the footer. Changing it back did not resolve the issue. I have also manually cleared the cache in the OC folder and the twig folder. I also did not have the cache setting set to off so I manually made this change in the db as I get the same error trying to get into the admin.
I am at a loss. I would love any help I could get.
Call Stack
{main}( )
start( )
require_once( '/mnt/c/wsl/server/opencart/system/framework.php' )
Router->dispatch( )
Router->execute( )
Action->execute( )
ControllerStartupRouter->index( )
Action->execute( )
ControllerCommonHome->index( )
Loader->controller( )
Action->execute( )
ControllerCommonColumnLeft->index( )
Loader->view( )
Template->render( )
Template\Twig->render( )
spl_autoload_call ( )
Twig_Autoloader::autoload( )
require( '/mnt/c/wsl/server/opencart/system/library/template/Twig/Loader/Filesystem.php'
)
Location
.../index.php:0
.../index.php:19
.../startup.php:104
.../framework.php:165
.../router.php:56
.../router.php:67
.../action.php:79
.../router.php:25
.../action.php:79
.../home.php:12
.../loader.php:48
.../action.php:79
.../column_left.php:72
.../loader.php:125
.../template.php:51
.../twig.php:20
.../twig.php:20
.../Autoloader.php:51
class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderInterface
{
/** Identifier of the main namespace. */
const MAIN_NAMESPACE = '__main__';
protected $paths = array();
protected $cache = array();
protected $errorCache = array();
/**
* Constructor.
*
* #param string|array $paths A path or an array of paths where to look for templates
*/
public function __construct($paths = array())
{
if ($paths) {
$this->setPaths($paths);
}
}
/**
* Returns the paths to the templates.
*
* #param string $namespace A path namespace
*
* #return array The array of paths where to look for templates
*/
public function getPaths($namespace = self::MAIN_NAMESPACE)
{
return isset($this->paths[$namespace]) ? $this->paths[$namespace] : array();
}
/**
* Returns the path namespaces.
*
* The main namespace is always defined.
*
* #return array The array of defined namespaces
*/
public function getNamespaces()
{
return array_keys($this->paths);
}
/**
* Sets the paths where templates are stored.
*
* #param string|array $paths A path or an array of paths where to look for templates
* #param string $namespace A path namespace
*/
public function setPaths($paths, $namespace = self::MAIN_NAMESPACE)
{
if (!is_array($paths)) {
$paths = array($paths);
}
$this->paths[$namespace] = array();
foreach ($paths as $path) {
$this->addPath($path, $namespace);
}
}
/**
* Adds a path where templates are stored.
*
* #param string $path A path where to look for templates
* #param string $namespace A path name
*
* #throws Twig_Error_Loader
*/
public function addPath($path, $namespace = self::MAIN_NAMESPACE)
{
// invalidate the cache
$this->cache = $this->errorCache = array();
if (!is_dir($path)) {
throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path));
}
$this->paths[$namespace][] = rtrim($path, '/\\');
}
/**
* Prepends a path where templates are stored.
*
* #param string $path A path where to look for templates
* #param string $namespace A path name
*
* #throws Twig_Error_Loader
*/
public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
{
// invalidate the cache
$this->cache = $this->errorCache = array();
if (!is_dir($path)) {
throw new Twig_Error_Loader(sprintf('The "%s" directory does not exist.', $path));
}
$path = rtrim($path, '/\\');
if (!isset($this->paths[$namespace])) {
$this->paths[$namespace][] = $path;
} else {
array_unshift($this->paths[$namespace], $path);
}
}
/**
* {#inheritdoc}
*/
public function getSource($name)
{
return file_get_contents($this->findTemplate($name));
}
/**
* {#inheritdoc}
*/
public function getCacheKey($name)
{
return $this->findTemplate($name);
}
/**
* {#inheritdoc}
*/
public function exists($name)
{
$name = $this->normalizeName($name);
if (isset($this->cache[$name])) {
return true;
}
try {
return false !== $this->findTemplate($name, false);
} catch (Twig_Error_Loader $exception) {
return false;
}
}
/**
* {#inheritdoc}
*/
public function isFresh($name, $time)
{
return filemtime($this->findTemplate($name)) <= $time;
}
protected function findTemplate($name)
{
$throw = func_num_args() > 1 ? func_get_arg(1) : true;
$name = $this->normalizeName($name);
if (isset($this->cache[$name])) {
return $this->cache[$name];
}
if (isset($this->errorCache[$name])) {
if (!$throw) {
return false;
}
throw new Twig_Error_Loader($this->errorCache[$name]);
}
$this->validateName($name);
list($namespace, $shortname) = $this->parseName($name);
if (!isset($this->paths[$namespace])) {
$this->errorCache[$name] = sprintf('There are no registered paths for namespace "%s".', $namespace);
if (!$throw) {
return false;
}
throw new Twig_Error_Loader($this->errorCache[$name]);
}
foreach ($this->paths[$namespace] as $path) {
if (is_file($path.'/'.$shortname)) {
if (false !== $realpath = realpath($path.'/'.$shortname)) {
return $this->cache[$name] = $realpath;
}
return $this->cache[$name] = $path.'/'.$shortname;
}
}
$this->errorCache[$name] = sprintf('Unable to find template "%s" (looked into: %s).', $name, implode(', ', $this->paths[$namespace]));
if (!$throw) {
return false;
}
throw new Twig_Error_Loader($this->errorCache[$name]);
}
protected function parseName($name, $default = self::MAIN_NAMESPACE)
{
if (isset($name[0]) && '#' == $name[0]) {
if (false === $pos = strpos($name, '/')) {
throw new Twig_Error_Loader(sprintf('Malformed namespaced template name "%s" (expecting "#namespace/template_name").', $name));
}
$namespace = substr($name, 1, $pos - 1);
$shortname = substr($name, $pos + 1);
return array($namespace, $shortname);
}
return array($default, $name);
}
protected function normalizeName($name)
{
return preg_replace('#/{2,}#', '/', str_replace('\\', '/', (string) $name));
}
protected function validateName($name)
{
if (false !== strpos($name, "\0")) {
throw new Twig_Error_Loader('A template name cannot contain NUL bytes.');
}
$name = ltrim($name, '/');
$parts = explode('/', $name);
$level = 0;
foreach ($parts as $part) {
if ('..' === $part) {
--$level;
} elseif ('.' !== $part) {
++$level;
}
if ($level < 0) {
throw new Twig_Error_Loader(sprintf('Looks like you try to load a template outside configured directories (%s).', $name));
}
}
}
}
Here am getting an error like Fatal error: Cannot declare class ABC, because the name is already in use in while listing all controller names and functions in project.In order to get i got an library from surroundings and placed it.library looks like this
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
/***
* File: (Codeigniterapp)/libraries/Controllerlist.php
*
* A simple library to list al your controllers with their methods.
* This library will return an array with controllers and methods
*
* The library will scan the "controller" directory and (in case of) one (1) subdirectory level deep
* for controllers
*
* Usage in one of your controllers:
*
* $this->load->library('controllerlist');
* print_r($this->controllerlist->getControllers());
*
* #author Peter Prins
*/
class ControllerList {
/**
* Codeigniter reference
*/
private $CI;
/**
* Array that will hold the controller names and methods
*/
private $aControllers;
// Construct
function __construct() {
// Get Codeigniter instance
$this->CI = get_instance();
// Get all controllers
$this->setControllers();
}
/**
* Return all controllers and their methods
* #return array
*/
public function getControllers() {
return $this->aControllers;
}
/**
* Set the array holding the controller name and methods
*/
public function setControllerMethods($p_sControllerName, $p_aControllerMethods) {
$this->aControllers[$p_sControllerName] = $p_aControllerMethods;
}
/**
* Search and set controller and methods.
*/
private function setControllers() {
// Loop through the controller directory
foreach(glob(APPPATH . 'controllers/*') as $controller) {
// if the value in the loop is a directory loop through that directory
if(is_dir($controller)) {
// Get name of directory
$dirname = basename($controller, 'EXT');
// Loop through the subdirectory
foreach(glob(APPPATH . 'controllers/'.$dirname.'/*') as $subdircontroller) {
// Get the name of the subdir
$subdircontrollername = basename($subdircontroller, EXT);
// Load the controller file in memory if it's not load already
if(!class_exists($subdircontrollername)) {
$this->CI->load->file($subdircontroller);
}
// Add the controllername to the array with its methods
$aMethods = get_class_methods($subdircontrollername);
$aUserMethods = array();
foreach($aMethods as $method) {
if($method != '__construct' && $method != 'get_instance' && $method != $subdircontrollername) {
$aUserMethods[] = $method;
}
}
$this->setControllerMethods($subdircontrollername, $aUserMethods);
}
}
else if(pathinfo($controller, PATHINFO_EXTENSION) == "php"){
// value is no directory get controller name
$controllername = basename($controller, 'EXT');
// Load the class in memory (if it's not loaded already)
if(!class_exists($controllername)) {
var_dump($controller);
$this->CI->load->file($controller);
}
// Add controller and methods to the array
$aMethods = get_class_methods($controllername);
//var_dump($aMethods);
$aUserMethods = array();
if(is_array($aMethods)){
foreach($aMethods as $method) {
if($method != '__construct' && $method != 'get_instance' && $method != $controllername) {
$aUserMethods[] = $method;
}
}
}
$this->setControllerMethods($controllername, $aUserMethods);
}
}
}
}
// EOF
Here am getting error in the line $this->CI->load->file($controller);.when i call this library in my controller am getting error what i mentioned in title.Is it a problem of php version,Here it is telling that controller class name is already called so it cannot be call again.
I'm calling a class by a string variable passed on a function argument.
ApiTester.php
use MyApp\Sites\Site;
abstract class ApiTester extends TestCase() {
/**
* Make a new record in the DB
*
* #param $type
* #param array $fields
* #throws BadMethodCallException
*/
protected function make($type, array $fields = [])
{
while($this->times--)
{
$stub = array_merge($this->getStub(), $fields);
$type::create($stub);
}
}
SitesTester.php
class SitesTester extends ApiTester() {
/** #test */
public function it_fetches_a_single_site()
{
// arrange
$this->make('Site');
// act
$site = $this->getJson('api/v1/sites/1')->data;
// assertion
$this->assertResponseOk();
$this->assertObjectHasAttributes($site, 'name', 'address');
}
Site.php // Eloquent Model
namespace MyApp\Sites;
class Site extends \Eloquent {
}
But if I call the class that the string variable $type contains, for example; string variable $type contains 'Site', it says class 'Site' not found.
I tried to manually type Site::create($stub) and finally accepts it.
I also tried
call_user_func($type::create(), $stub);
and
$model = new $type;
$model->create($stub);
but unfortunately it says class 'Site' not found.
Any ideas?
You're almost there:
class X {
static function foo($arg) {
return 'hi ' . $arg;
}
};
$cls = 'X';
print call_user_func("$cls::foo", 'there');
If your php is very old (<5.3 I believe), you have to use an array instead:
print call_user_func(array($cls, "foo"), 'there');
You may want to replace that static class call with the following :
while( $this->times-- )
{
$stub = array_merge( $this->getStub(), $fields );
call_user_func( "$type::create", $stub );
}
Runnable code here : http://runnable.com/VIqy4CDePeY-AeMV/output
I'm using PHPTAL in my project I'm able to successfully implement it almost all the cases except when I want to use its i18n services. I constantly get errors "Call to a member function on a non-object"
I've tried searching the net forums etc. but not found any solution, will really appreciate if somebody can help me out.
Its heartily disappointing that no one answered my question so here I'm finally with the solution and answering my own question.
By default there is no translator set by PHPTAL in order to translate your text from one language to another. So you've to do it on your own. There are some steps give below to do this . . .
Step 1. Create a new php file( e.g. MyTranslator.php ) and generate a new class for example PHPTAL_MyTranslator and store it inside the PHPTAL folder. This class will implement the interface PHPTAL_TranslationService. There are five functions in this interface but the function of our concern is only translate. So just add a declaration for rest of the functions and write code for the translate function. The class I've written and used in my case is :
class PHPTAL_MyTranslator implements PHPTAL_TranslationService {
/**
* current execution context
*/
protected $_context = null;
/**
* #param string (name of the language)
* #return string (language you've just set)
*
* This method sets translation language.
* Name of the language is a dir name where you keep your translation files
*/
public function setLanguage() {
}
public function __construct( $context ) {
$this->_context = $context;
}
/**
* #param string (translation file name)
* #return void
*
* You can separate translations in several files, and use only when needed.
* Use this method to specify witch translation file you want to
* use for current controller.
*/
public function useDomain( $domain ) {
}
/**
* Set an interpolation var.
* Replace all ${key}s with values in translated strings.
*/
public function setVar( $key, $value ) {
}
/**
* Translate a text and interpolate variables.
*/
public function translate( $key, $htmlescape=true ) {
$value = $key;
if( empty( $value ) ) {
return $key;
}
while( preg_match( '/\${(.*?)\}/sm', $value, $m ) ) {
list( $src, $var ) = $m;
if( !array_key_exists( $var, $this->_context ) ) {
$err = sprintf( 'Interpolation error, var "%s" not set', $var );
throw new Exception( $err );
}
$value = str_replace( $src, $this->_context->$var, $value );
}
return gettext( $value );
}
/**
* Not implemented yet, default encoding is used
*/
public function setEncoding( $encoding ) {
}
}
Step 2. Now open the PHPTAL.php file and modify the constructor of PHPTAL class. Add a line to this function as shown below . . . . .
Before
public function __construct($path=false)
{
$this->_path = $path;
$this->_globalContext = new StdClass();
$this->_context = new PHPTAL_Context();
$this->_context->setGlobal($this->_globalContext);
if (function_exists('sys_get_temp_dir')) {
............
After
public function __construct($path=false)
{
$this->_path = $path;
$this->_globalContext = new StdClass();
$this->_context = new PHPTAL_Context();
$this->_context->setGlobal($this->_globalContext);
//Set translator here
$this->setTranslator( new PHPTAL_MyTranslator( $this->_context ) );
if (function_exists('sys_get_temp_dir')) {
.............
These two simple steps will make your i18n:attributes as well as i18n:translate attributes to work properly.
Cheers...