OpenCart problems adding new admin pages - php

So, I followed:
How to create a custom admin page in opencart?
This tut to try and add a page to my OpenCart v1.5.6 shop.
<?
class ControllerCommonHelloworld extends Controller {
public function index(){
// VARS
$template="common/hello.tpl"; // .tpl location and file
$this->load->model('common/hello');
$this->template = ''.$template.'';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
}
?>
but upon opening the new page am fed with this:
load->model('common/hello'); $this->template = ''.$template.''; $this->children = array('common/header', 'common/footer' ); $this->response->setOutput($this->render()); } }?>
( ! ) Fatal error: Class 'Controllercommonhelloworld' not found in ------\store\system\engine\front.php on line 39
Call Stack
# Time Memory Function Location
1 0.0015 303736 {main}( ) ..\index.php:0
2 0.0634 2285056 Front->dispatch( ) ..\index.php:166
3 0.0663 2439760 Front->execute( ) ..\front.php:29`
now as far as I am aware this error is telling me I have no Class named "ControllerCommonHelloworld" even though I have a file called helloworld.php
I have both of these things, and have tried all types of case combinations, and moving the files around...
does anyone know of any other reason this error might be appearing? or can see anything else I might have missed?

Your server doesn't seem to be able to use php short tags. Change <? to <?php - Since PHP doesn't load that file as a PHP file, the class doesn't exist. Changing it to <?php will get it working

Related

How to remove an action in wordpress which is inside a plugin class?

I'm using awesome support plugin for creating a ticket system in my project.
The problem I have is that support plugin will add some fields into Users Admin page which I don't want them.
I searched inside plugin code and I've found the action that is used to put the fields in users page and I want to remove that action.
I tried removing its action by using this code:
remove_action('wpas_all_user_profile_fields', array( WPAS_User::get_instance() , 'profile_phone_fields'), 10)
and it is working and the fields doesn't show on users page but I'm getting a fatal error inside my debug.log which says:
PHP Fatal error: Uncaught Error: Class 'WPAS_User' not found in ...
the plugin class that is something like this
class WPAS_User {
public function __construct() {
add_action( 'wpas_all_user_profile_fields', array( $this, 'profile_phone_fields' ), 10, 1 );
}
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}
return self::$instance;
}
.
.
.
}
Do you include in your php the name of the file ?
<?php include('yourfile.php') ?>

Cannot load custom content type nodes with load_node_multiple or load_node

I have a custom content type called "program" that I am trying to load via a drupal module.
The .module file includes a class called Program that has a method called
getAllPrograms() using include_once(drupal_get_path('module', 'progs') . '/progs.php');
When i try and load nodes using either node_load() or node_load_multiple() i get one of two different errors randomly.
either:
Fatal error: Fatal error: Call to undefined function user_access() in /mypath/modules/filter/filter.module on line 1035
or
Error: Call to undefined function token_get_entity_mapping() in /mypath//sites/all/modules/contrib/token/token.tokens.inc, line 767
Note: 99% of times it is the first error, and occasionally i would recieve the token_get_entity error.
The strange thing is, while i have been trying different things to resolve the error I have been able to get both of these functions to work for a period but as soon as i clear the Drupal Cache i get the error again.
What I have tried
Disabling and enabling the user module via the database.
Checking the paths and status are correct for the main modules (system, user, block etc)
using db_select to get a list of node ids and then use node_load() (with a loop) and node_load_multiple() to load the nodes. This is one of the things that started working for a short time until i cleared the cache.
Tested to see if i can call user_access() from my .module file. This does not work and returns the same call to undefined function error.
Here is the code that I have (not progs an anonymized name)
progs.module
include_once(drupal_get_path('module', 'progs') . '/progs.php');
progs.php
if( !class_exists('progs') ):
class progs
{
//a bunch of properties
function __construct()
{
// load partial includes and objects
$this->load_partial_inclues();
//retrieve all programs that are open
$this->open_programs = Program::getAllOpenPrograms();
}
function load_partial_inclues()
{
//includes
include_once(drupal_get_path('module', 'progs') . '/core/objects/program.php');
}
}
function progs()
{
global $progs;
if( !isset($progs) )
{
$progs = new progs();
}
return $progs;
}
// initialize
progs();
endif;
Note: I load the $progs into the global space so i can call it elsewhere in my module.
program.php
if( !class_exists('Program') ):
class Program
{
//a bunch of properties
public static function getAllOpenPrograms()
{
// This is the line that causes all of the issues.
$result = node_load_multiple('',array('type' => 'program'));
dpm($result);
}
Thanks in advance!
Like Mike Vranckx mentioned, if you call progs() directly when you include it in progs.module, Drupal basically hasn't bootstrapped, i.e. hasn't started running fully yet. Suggest you put your progs() in progs_init() or similar so that Drupal will invoke it at the right time.
Here's a proposed way that follows your initial structure quite closely, and below you will see an alternative that better follows Drupal's conventions.
New progs.module
/**
* Implements hook_init().
*/
function progs_init(){
progs();
}
And modify your progs.php
// Why are you doing this check? Are you defining this class elsewhere in your project? If not you can safely ignore this
//if( !class_exists('progs') ):
// Convention is to name classes with Pascal case btw.
class progs
{
//a bunch of properties
function __construct()
{
// load partial includes and objects
$this->load_partial_inclues();
//retrieve all programs that are open
$this->open_programs = Program::getAllOpenPrograms();
}
function load_partial_inclues()
{
//includes
include_once(drupal_get_path('module', 'progs') . '/core/objects/program.php');
}
}
function progs()
{
global $progs;
if( !isset($progs) )
{
$progs = new progs();
}
return $progs;
}
A more Drupal way:
progs.module
/**
* Implements hook_init().
*/
function progs_init(){
global $progs;
// Consider using drupal_static to cache this
if( !isset($progs) )
{
module_load_include('inc', 'progs', 'progs');
$progs = new Progs();
}
}
progs.inc (convention is to use .inc)
class Progs
{
//a bunch of properties
function __construct()
{
// load partial includes and objects
$this->load_partial_inclues();
//retrieve all programs that are open
$this->open_programs = Program::getAllOpenPrograms();
}
function load_partial_inclues()
{
//includes
module_load_include('php', 'progs', 'core/objects/program');
}
}

Can't load modules from libraries in CodeIgniter HMVC

I'm having a problem loading modules inside my template library in CodeIgniter HMVC. The reason I want to load a module in the template library is that I wish to use modules for sideboxes and other content boxes in my template.
PS: I am also using the Smarty template parsing system for CodeIgniter, but I doubt it has anything to do with the errors, but if you have reasons to believe otherwise, please, let me know.
What I tried to do
I tried to load the module in two different ways, and both presented with the same errors.
The errors
A PHP Error was encountered
Severity: Notice
Message: Undefined Property CI::$template
File: MX/Loader.php
Line Number: 141
-
A PHP Error was encountered
Severity: Notice
Message: Undefined Property CI::$template
Filename: MX/Controller.php
Line number: 57
-
Fatal error: Call to a member function load_content() on a non-object in E:\Xampp\htdocs\firecms\application\modules\sidebar_login_box\controllers\sidebar_login_box.php on line 7
The undefined "load_content()" function will be explained further down (in Sidebar Controller).
The Error lines
MX/Loader
/*Line 140*/if (isset($this->_ci_classes[$class]) AND $_alias = $this->_ci_classes[$class])
/*Line 141*/ return CI::$APP->$_alias;
MX/Controller
/*Line 56*/public function __get($class) {
/*Line 57*/ return CI::$APP->$class;
How I tried to load the modules
This was my first attempt (loading the file and instancing its class):
class Template {
//[...]
public function load_sidebars()
{
$sidebars = $this->CI->cms_model->get_sidebars();
foreach ($sidebars as $sidebar)
{
if (trim($sidebar["content"]) == "")
{
//An example of sidebar module name is "sidebar:login_box"
//The function below changes the name to "sidebar_login_box" (the
//module's folder and controller name.
$module = str_replace(':', '_', $sidebar["module"]);
$file_path = APPPATH.'modules/'.$module.'/controllers/'.$module.'.php';
require_once $file_path;
$class = ucfirst($module);
$object = new $class();
$module_data = $object->index();
$this->_section_data["sidebars"][]["content"] = $module_data;
}
else
{
$this->_section_data["sidebars"][]["content"] = $sidebar["content"];
}
}
}
//[...]
}
And this was my second attempt (using the loader function):
public function load_sidebars()
{
$sidebars = $this->CI->cms_model->get_sidebars();
foreach ($sidebars as $sidebar)
{
if (trim($sidebar["content"]) == "")
{
$module = str_replace(':', '_', $sidebar["module"]);
$this->CI->load->module($module);
$module_data = $this->CI->$module->index();
$this->_section_data["sidebars"][]["content"] = $module_data;
}
else
{
$this->_section_data["sidebars"][]["content"] = $sidebar["content"];
}
}
}
The sidebar controller
This is how the sidebar controller looks like:
class Sidebar_login_box extends Fire_Controller {
public function index()
{
$view_data = array();
//The load_content function in the template library is used to parse template files
//and return them as a string.
return $this->template->load_content("login_box", $view_data);
}
}
The Fire Controller
The Fire_Controller is my core controller. My core classes' prefix is Fire_ instead of MY_.
This is how the fire controller looks like:
class Fire_Controller extends MX_Controller {
public function __construct()
{
parent::__construct();
//Load configurations from the database.
$this->config->load_db_configs();
//Set the timezone.
date_default_timezone_set(config_item("timezone"));
//Loads the form validation library.
$this->load->library("form_validation");
//Reset the Form Validation CI Object (to fix problems with HMVC CI).
$this->form_validation->CI =& $this;
//To reduce load time, the template library will not be loaded in ajax
//requests.
if ( ! $this->input->is_ajax_request())
{
$this->load->library("template");
}
//Force access via SSL connection (HTTPS) if necessary.
if ((int)config_item('force_https') === 1)
{
force_https();
}
}
Note: This is a very recent project of mine, which means that the framework and all third party extensions are in the most recent stable version as of January 06, 2015.
Thank you for your time,
Best regards.
Fixed.
The sidebars were loaded from the set_defaults() method, which was called by the constructor method in my template library. And since it wasn't fully loaded, the template object was not saved in CI's super object, thus being inaccessible and throwing the errors in the sidebar module.
I have moved the set_defaults() call to the render_page() function of my template library (which are called by the modules' controllers), and now it's working perfectly.
Too bad I added bounty a few hours before finding the solution, hehe.
You need to load the library before you can use it in the sidebar controller. It isn't being passed from the parent. Try this:
class Sidebar_login_box extends Fire_Controller {
public function index()
{
$view_data = array();
$this->load->library('template');
//The load_content function in the template library is used to parse template files
//and return them as a string.
return $this->template->load_content("login_box", $view_data);
}
}
Cheers!

MediaWiki upgrade (1.19.6 to 1.22.2) breaks - fetchContent() error

Just upgraded Mediawiki 1.19.6 to the most current, 1.22.2.
Used update.php, which worked just fine. The front page loads, as do SOME of the articles if you enter their exact URL. However, following any of the links produces:
Catchable fatal error: Argument 1 passed to
ContentHandler::getContentText() must implement interface Content,
boolean given, called in <wiki path>/includes/Article.php on line 389
and defined in <wiki path>/includes/content/ContentHandler.php on line
95.
I've looked up the call to getContentText() in Article.php, and it's in a function called fetchContent(), with a comment about it being crufty and a note that the ContentHandler method within is deprecated.
I can't figure out how to fix what's gone wrong, and web searches are only turning up bug reports that are marked fixed... any ideas? Thanks very much.
getContentText() is depreciated.
Use WikiPage::getContent()
https://doc.wikimedia.org/mediawiki-core/master/php/html/classArticle.html#affd3b52d2544cc334d7805ae9e5aba98
We had the same problem. Our ICT guy handled it by adapting the Article.php file placed in the includes directory of your mediawiki. Only 1 function was adapted (line 377 function function fetchContent()). I do not know the exact working principle but the MediaWiki returned to normal.
Also I believe you need to run the mediawiki update routine by visiting:
'HostAdress'/MediaWiki/mw-config/
Original function in Article.php:
function fetchContent() { #BC cruft!
ContentHandler::deprecated( __METHOD__, '1.21' );
if ( $this->mContentLoaded && $this->mContent ) {
return $this->mContent;
}
wfProfileIn( __METHOD__ );
$content = $this->fetchContentObject();
// #todo Get rid of mContent everywhere!
$this->mContent = ContentHandler::getContentText( $content );
ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
wfProfileOut( __METHOD__ );
return $this->mContent;
}
New function in Article.php:
function fetchContent() { #BC cruft!
ContentHandler::deprecated( __METHOD__, '1.21' );
if ( $this->mContentLoaded && $this->mContent ) {
return $this->mContent;
}
wfProfileIn( __METHOD__ );
$content = $this->fetchContentObject();
if ( !$content ) {
wfProfileOut( __METHOD__ );
return false;
}
// #todo Get rid of mContent everywhere!
$this->mContent = ContentHandler::getContentText( $content );
ContentHandler::runLegacyHooks( 'ArticleAfterFetchContent', array( &$this, &$this->mContent ) );
wfProfileOut( __METHOD__ );
return $this->mContent;
}

Silverstripe: I can't handle sub-URLs of a Form object. Subsites module

Bit of a long shot but can anyone shed any light on this?
I have recently installed the subsites module to run multiple sites from a single installation and am now getting the error: "I can't handle sub-URLs of a Form object." when I try to add descriptions/titles to image gallery objects. I have removed the subsites to verify that it is this which is causing the issue. I am using 2.4
I can upload images fine, however it is when trying to save a description from the popup that the issue arises.
I have tried with the default fields too and this still gives the same error.
My code:
<?php
class Gallery extends Page {
public static $db = array(
'SummaryText'=>'Text',
'GalleryText'=>'Text'
);
static $has_many = array(
'Photos' => 'GalleryPhoto'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$manager = new ImageDataObjectManager(
$this, // Controller
'Photos', // Source name
'GalleryPhoto', // Source class
'Image' // File name on DataObject
);
$manager->uploadFolder = $this->URLSegment;
$fields->addFieldToTab('Root.Content.Main', new TextField('SummaryText', 'Summary Text (Appears in the section preview)'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('GalleryText', 'Gallery Text (entering anything in here will overwrite any image Titles and Descriptions)'), 'Content');
$fields->addFieldsToTab("Root.Content.Gallery", array($manager));
$fields->removeFieldFromTab('Root.Content', 'StyledText');
$fields->removeFieldFromTab('Root.Content', 'Column2');
$fields->removeFieldFromTab('Root.Content', 'Content');
return $fields;
}
}
..
<?php
class GalleryPhoto extends Photo {
public static $db = array(
'HTMLDescription'=>'HTMLText'
);
static $has_one = array(
'Gallery' => 'Gallery'
);
public function getCMSFields(){
$fields = parent::getCMSFields();
$fields->removebyname('Description');
$fields->removebyname('Title');
$fields->replaceField('HTMLDescription', new SimpleTinyMCEField('HTMLDescription'));
return $fields;
}
}
Unfortunately "I can't handle sub-URLs of a Form object." is a pretty generic error message and from my experience rather tricky to debug.
To be honest, the Subsites module isn't that great in my opinion, it works, but its not that nice and not really compatible with other modules I guess.
I could imagine that the reason for your error is because silverstripe forgets the SubsiteID inside the popup and because of that SilverStripe can no longer find the current Page you are editing (because it adds a filter WHERE SubsiteID = x to every query of Pages you make)
one place to start debuging would be hooking into Subsite::currentSubsiteID() and see if it remembers the SubsiteID when you are in the popup
also, what is the exact url that gets called when you get the error message?
I just had the same error, searched for hours. It was a problem with /framework/control/Session.php

Categories