CodeIgniter Third party class not loading - php

I am trying to implement Dashboard widget class (found here: http://harpanet.com/programming/php/codeigniter/dashboard/index#installation) but it is giving me error Unable to load the requested class
I have tried to add this class in autoload as well as menually to my controller $this->load->library('dash') but this also giving the same error.
I have checked dash.php and found below method private function __example__() but can't understand what the developer is saying in comment.
class Dash
{
private function __example__()
{
/*
* This function is purely to show an example of a dashboard method to place
* within your own controller.
*/
// load third_party hArpanet dashboard library
$this->load->add_package_path(APPPATH.'third_party/hArpanet/hDash/');
$dash =& $this->load->library('dash');
$this->load->remove_package_path(APPPATH.'third_party/hArpanet/hDash/');
// configure dashboard widgets - format: type, src, title, cols, alt (for images)
$dash->widgets = array(
array('type'=>'oop', 'src'=>'test_dash', 'title'=>'Test OOP Widget', 'cols'=>3),
// if 'title' is set to FALSE, the title block is omitted entirely
// note: this is an 'html' widget but is being fed content from a local method
array('type'=>'html', 'src'=>self::test_method(), 'title'=>false, 'cols'=>3),
array('type'=>'file', 'src'=>'saf_inv.htm', 'title'=>'Safety Investigation'),
// multi-content widget - set widget title in outer array (also note use of CI anchor to create a link)
array('title'=>anchor('tz', 'TARGET ZERO'),
// sub-content follows same array format as single content widget
// 'img' content can also have an 'alt' text
array('type'=>'img', 'src'=>'saf_tzout.gif', 'alt'=>'Action Completed'),
array('type'=>'file', 'src'=>'saf_tz.htm'),
array('type'=>'file', 'src'=>'ave_close.htm', 'title'=>'Average Time to Close')
),
array('type'=>'file', 'src'=>'saf_meet.htm', 'title'=>'Safety Meeting'),
array('type'=>'file', 'src'=>'saf_acc.htm', 'title'=>'Accident Investigation'),
array('type'=>'file', 'src'=>'saf_hazmat.htm', 'title'=>anchor('hazmat', 'HAZMAT')),
array('type'=>'file', 'src'=>'saf_cont.htm', 'title'=>'Loss of Containment'),
array('type'=>'file', 'src'=>'saf_worksinfo.htm', 'title'=>'Works Information'),
// an action widget - 'clear' will generate a blank widget with a style of clear:both
array('type'=>'clear'),
// multi-content widget - width can be set using the 'cols' param in outer array
array('title'=>'RAG Report', 'cols' => 2,
array('type'=>'file', 'src'=>'saf_rag.htm'),
array('type'=>'img', 'src'=>'ProcSaf.gif')),
array('type'=>'file', 'src'=>'saf_chrom.htm', 'title'=>'Chrome checks'),
);
// populate the view variable
$widgets = $dash->build('safety');
// render the dashboard
$this->load->view('layout_default', $widgets);
}
...................
} // end of Dash class
Installation path is root/application/third_party/hArpanet/hDash/libraries/dash.php
How can I load this class to my system and use widgets?

You have to create a library that initialize the third party class:
for Eg:
--in library create a file named mydash.php --
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MyDash
{
public function __construct()
{
require_once APPPATH.'third_party/hArpanet/hDash/libraries/dash.php';
}
}
load the library using:
$this->load->library('mydash');
then you are able to use the Dash class. Also able to load library in autoload.
Thank you...

Sorry to hear you were having problems, (I've only just noticed this SO entry). Thanks to ReNiSh for his workaround, much appreciated.
You do not however need to use the library approach to implement the 'require_once' of hDash. I have now written a walkthrough for getting hDash installed and running, which you can find here: http://harpanet.com/programming/php/codeigniter/dashboard/walkthrough
Also, note that as of yesterday, 3rd Feb 2014, hDash has been updated to version 1.2.

I am using PDF Parser from http://pdfparser.org/
I create files application/libraries/pdf.php
class Pdf
{
public function __construct()
{
require_once APPPATH."/third_party/pdfparser.php";
}
}
Then I create file application\third_party\pdfparser.php
if (!defined('pdfparser')) {
define('pdfparser', dirname(__FILE__) . '/');
require(pdfparser . 'pdfparser/autoload.php');
}
Last, I include PDF Parser Library in Directory => application\third_party\pdfparser

Related

TYPO3: Add LINK tags to CSS Files in the HEAD tag from within a Typo 3 extension

I have a custom extension in Typo3.
Does anyone know how to add in a template ?
Ive had some success with adding in
call_user_func(
function($extKey)
{
//other init code goes here
$GLOBALS['TBE_STYLES']['skins'][$extKey] = array();
$GLOBALS['TBE_STYLES']['skins'][$extKey]['name'] = $extKey;
$GLOBALS['TBE_STYLES']['skins'][$extKey]['stylesheetDirectories'] = array(
'structure' => 'EXT:'. $extKey. '/Resources/Public/css/',
);
},
$_EXTKEY
);
Ive looked at typo3 docs but cant get it to work when adding to ext_tables.php
It is a Front End Plug in and I want the reference to be contained within the Extension for ease of installation and management.
Anyone had success with this ?
put following in this file your_extension/Configuration/TypoScript/setup.ts
page = PAGE
page {
# CSS files to be included
includeCSS {
yourCss = EXT:your_extension/Resources/Public/Css/yourCss.css
}
}
and then call it in your ext_tables.php
/***************
* Include TypoScript
*/
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile(
$_EXTKEY, 'Configuration/TypoScript', 'Your Package'
);
you'll find this voice in your template in the backend so that you can include it ...

Drupal 8 - Adding/Creating Menu Item with HTML in it

I'm creating a website using Drupal 8. I want to create a menu item link that I could add HTML/Javascript code in it (I'm trying to display a widget that expands on click in the menu rather than displaying it in its own block next to the menu). The only way I could see to add a menu item is to link to a page.
You could work with a derivative. This lets you customize pretty much everything about it and control what is to be made. An example below:
Note: I am assuming you have a general knowledge of custom modules. If not follow this link
Create the following file in your custom module:
# my_module.links.menu.yml
my_module.custom_links:
deriver: \Drupal\my_module\Plugin\Derivative\CustomLinkDerivative
And now for the derivative class (Located under my_module/src/Plugin/Derivative)
<?php
namespace Drupal\my_module\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CustomLinkDerivative extends DeriverBase implements ContainerDeriverInterface {
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static();
}
/**
* {#inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$links['custom_menulink'] = [
'title' => t('Custom menulink'),
'menu_name' => 'main',
'route_name' => 'entity.node.canonical',
'parent' => footer,
'route_parameters' => [
'node' => 1,
]
] + $base_plugin_definition;
return $links;
}
}
Note: Derivatives get triggered during rebuild of cache!
This just creates a link in the footer that directs to node 1. You can add all sort of stuff and logic to your liking. Hope this helps you :)

joomla 3.x tags in custom component fails

Running Joomla 3.3.0-dev
I'm following the info posted here about adding tag support to a third-party component.
I've added the content type to the #__content_types table and modified my table file like this:
class MycomponentTableElement extends JTable
{
public $tagsHelper = null; // failed when protected and public
public function __construct(&$_db)
{
parent::__construct('#__mycomponent', 'id', $_db);
// Add Joomla tags
JObserverMapper::addObserverClassToClass('JTableObserverTags', 'MycomponentTableElement', array('typeAlias' => 'com_mycomponent.element'));
//$this->_observers = new JObserverUpdater($this); JObserverMapper::attachAllObservers($this); // failed with or without this line
}
I added the tag field in the edit template, and it worked fine-- but when I save an object I get the following error:
Save failed with the following error: Unknown column 'tagsHelper' in 'field list'
What am I missing? There's no other steps (besides front-end steps!) that are mentioned. It seems like I need to modify the model but that info is not applicable.
Thanks
"This Page Needs Copy Editing" and it's really true!
I also follow initial steps as described in page
Register a 'Content type' for the extension view(s)
Add 'Observer methods' to the extension table class(es)
Add 'Tag fields' to the extension edit forms
But to make field tag works on custom extensions I need to explicit set form field value in view file of backend:
$tagsHelper = new JHelperTags;
$this->form= $this->get('Form');
$this->form->setValue('tags', null, $tagsHelper->getTagIds( $this->item->id, 'com_custom.viewname') );
in this way on edit page all seems to work correctly.. surely exist better and more clean method, but until doc page will not be updated, this can help someone!
1- Add tag field to your xml form file or edit template file
2- Modify #__content_types table file:
function __construct(&$db)
{
parent::__construct('#__ir_products', 'id', $db);
JTableObserverTags::createObserver($this, array('typeAlias' => 'com_itemreview.product'));
}
3- Modify model file getItem function:
public function getItem($pk = null)
{
$item = parent::getItem($pk);
if (!empty($item->id))
{
$item->tags = new JHelperTags;
$item->tags->getTagIds($item->id, 'com_yourcomponent.yourmodel');
}
return $item;
}

How can I add a custom tag in MediaWiki templates for my extension to process?

I want to add 3 custom tags which a MediaWiki admin will add to her templates(for example to the Userlogin.php template for the login page), and these extensions need to be processed by the extension I am building. The tags will be of the form <mytag_forXaction>, <mytag_forYaction>. When the extensions parses through this, they will be replaced with valid HTML tags to display boxes or images or whatever the desired purpose may be.
So far, I have tried doing this:
if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is a MediaWiki extension, it is not a valid entry point' );
}
$wgExtensionCredits['parserhook'][] = array(
'path' => __FILE__,
'name' => 'Test Parser Function',
'description' => 'A simple example parser function extension',
'version' => 0.1,
'author' => 'Me',
'url' => 'https://www.mediawiki.org/wiki/Manual:Parser_functions',
);
$wgHooks['ParserFirstCallInit'][] = 'buttonParserSetup';
function buttonParserSetup( ) {
global $wgParser;
//apploginbtn will be the tag to be replaced
$wgParser->setHook( 'apploginbtn', 'RenderAppLoginButton' );
return true; // Return true so that MediaWiki continues to load extensions.
}
// Render the output of the parser function.
function RenderAppLoginButton( $input, $argv ) {
$output = "SUCCESSFULLY REPLACED.";
return $output;
}
So now when I add the tag <apploginbtn />, or <apploginbtn></apploginbtn>, or {{apploginbtn}}, or {{#apploginbtn}} to the Userlogin.php file at the desired position, the tag doesn't get replaced.
Any help in achieving the desired outcome will be a lot helpful as am stuck with this since 2-3 days and the documentation isn't helpful at all.
Also, am using MediaWiki 1.9.3 as that's the lowest version I need to start supporting.
Use the UserLoginForm hook. It calls your extension function with the UserLogin template (at SVN) which is used to create the login form. It is an instance of QuickTemplate, and you will be able to edit / stuff it up from your extension code.
Do not try to build a parser extension (tag extension) if you don't target parsed wikitext.

What is a minimal, complete example of pagination in Kohana 3.2?

I found much information about pagination in Kohana 3.2 but most of it is scattered across forum comments and blog posts with no single complete source to refer to.
(note: I intended to self answer this question)
This is what worked for me:
Download the pagination module from https://github.com/kloopko/kohana-pagination (pagination was removed from Kohana 3.2, so this is an adapted module).
Install the module in modules/pagination.
Add the module in bootstrap.php:
Kohana::modules(array(
// ... other modules ...
'pagination' => MODPATH.'pagination'
));
Copy the configuration file from modules/pagination/config/pagination.php to application/config/pagination.php.
Add the following actions to your controller:
public function action_index() {
// Go to first page by default
$this->request->redirect('yourcontroller/page/?page=1');
}
public function action_page() {
$orm = orm::factory('your_orm');
$pagination = Pagination::factory(array(
'total_items' => $orm->count_all(),
'items_per_page' => 20,
)
);
// Pass controller and action names explicitly to $pagination object
$pagination->route_params(array('controller' => $this->request->controller(), 'action' => $this->request->action()));
// Get data
$data = $orm->offset($pagination->offset)->limit($pagination->items_per_page)->find_all()->as_array();
// Pass data and validation object to view
echo View::factory('yourview/page', array('data' => $data, 'pagination' => $pagination));
}
Create yourview/page as follows:
<?php
foreach($data as $item) {
// ...put code to list items here
}
// Show links
echo $pagination;
Modify application/config/pagination.php according to your needs. I had to change the 'view' parameter to 'pagination/floating' which displays ellipses (...) when the list of pages is too large, unlike the default 'pagination/basic' which lists all pages regardless of length.
Pagination wasn't originally working/supported in Kohana 3.2. Luckily, somebody has updated the module and you can get the code at https://github.com/kloopko/kohana-pagination

Categories