Loading external library into ExpressionEngine plugin - plugins

I'm trying to load an external library into an ExpressionEngine plugin but am getting:
Message: Undefined property: Detector::$EE
In the plugin itself I've got:
public function __construct()
{
$this->EE->load->library('detector');
$this->EE =& get_instance();
}
and my folders are set up like:
detector
-libraries
--Detector.php
-pi.detector.php
What am I doing wrong?
Having moved past the loading library error, I'm now getting an 'undefined variable' error with the following code:
public function detector()
{
return $ua->ua;
}
public function user_agent()
{
return $ua->ua;
}
That's if I have {exp:detector:user_agent} in my template. If I {exp:detector} I get no output.

you should change your code like this:
$this->EE =& get_instance();
$this->EE->load->add_package_path(PATH_THIRD.'/detector');
$this->EE->load->library('detector');
First initialize the $this->EE variable, then you can load the library. So in this case it would be
$this->EE->detector->user_agent();

Related

cakephp: How to load Flash component in the plugin?

I am using CakePHP 3 and add a plugin cakphp-Notifier.
I want to add flash component in that plugin.
how to add cakephp default component in plugin?
Code:
NotificationManager.php
use Cake\Controller\Component\FlashComponent;
class {
// ...
private $Flash;
public function __construct( )
{
$this->Flash = new FlashComponent();
}
// ...
public function send {
$smsAPI->sendSms($numbers, $message, $sender);
$this->Flash->success(__('SMS sent .'));
// ...
}
I got this error:
Required parameter $registry missing.
Invocation parameters types are not compatible with declared.
First you must import the component on the top of your plugin file:
use Cake\Controller\Component\FlashComponent;
Then import the component inside your Class
var $components = array('Flash');
Then use your Flash functions
$this->Flash->set(__('Error!'));
Hope it works!

Backend Module with AJAX in Typo3 6.2.6?

I am working on an extension which contains both FE extension and BE Module. See below for my BE module
class Tx_XXXXXXX_Controller_PitslayersliderController extends Tx_Extbase_MVC_Controller_ActionController {
public function listAction(){
}
public function getdataAction($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
//This is an AJAX Call Action and I am rendering all my contents through
//$this->view->assign();
//$this->view->render();
//Everything was working fine till 6.1 . But from 6.2 onwards this is not working.
}
}
ext_tables.php
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::registerAjaxHandler (
'xxxxxxxxxController::getdata',
'Tx_xxxxxxxxxx_Controller_xxxxxxxController->getdataAction'
);
Error from php_error_log
PHP Fatal error: Call to a member function assign() on a non-object in
Can any one help me with this issue ??

Undefined variable: mysqli - PHP OOP

How can I implement mysqli in an extended class?
I am uploading an image and storing it in a MySQL database, but I get this error:
Notice: Undefined variable: mysqli in ...ecc/ecc/ on line 33
Fatal error: Call to a member function query() on a non-object in ...ecc/ecc/ on line 33
Here is my test code:
<?php
interface ICheckImage {
public function checkImage();
public function sendImage();
}
abstract class ACheckImage implements ICheckImage {
public $image;
private $mysqli;
public function _construct(){
$this->image = $_POST['image'];
$this->mysqli = new mysqli('localhost','test','test','test');
}
}
class Check extends ACheckImage {
public function checkImage() {
if($this->image > 102400) {
echo "File troppo grande";
}
}
public function sendImage() {
//This is the line 33 give me the error
if ($mysqli->query("INSERT INTO images (image) VALUES ('$this->image')")) {
echo "Upload avvenuto &nbsp";
} else {
echo "Errore &nbsp" . $mysqli->error;
}
}
}
$form = new Check();
$form->checkImage();
$form->sendImage();
?>
There are some errors in your code.
The $mysqli member is private inside the abstract class. It will not be inherited by the Check class, so it does not exist there. Make it protected.
Access to the members of a class always needs $this-> in front, specifically $this->mysqli in this instance.
The constructor function must be named __construct with two underscores in front.
The image check looks wrong. $_POST['image'] does contain something that you expect to store in the database, but you also compare it with an integer value and seem to echo an error message if it is bigger. While the data handling will work, e.g. you can compare a string from POST data with an integer, it looks like you want something else.

action parameters routing not working in Zend framework routes.ini

I'm trying to set up a route in Zend Framework (version 1.11.11) in a routes.ini file, which would allow be to match the following url:
my.domain.com/shop/add/123
to the ShopController and addAction. However, for some reason the parameter (the number at the end) is not being recognized by my action. The PHP error I'm getting is
Warning: Missing argument 1 for ShopController::addAction(), called in...
I know I could set this up using PHP code in the bootstrap, but I want to understand how to do this type of setup in a .ini file and I'm having a hard time finding any resources that explain this. I should also point out that I'm using modules in my project. What I've come up with using various snippets found here and there online is the following:
application/config/routes.ini:
[routes]
routes.shop.route = "shop/add/:productid/*"
routes.shop.defaults.controller = shop
routes.shop.defaults.action = add
routes.shop.defaults.productid = 0
routes.shop.reqs.productid = \d+
Bootstrap.php:
...
protected function _initRoutes()
{
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'routes');
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addConfig( $config, 'routes' );
}
...
ShopController.php
<?php
class ShopController extends Egil_Controllers_BaseController
{
public function indexAction()
{
// action body
}
public function addAction($id)
{
echo "the id: ".$id;
}
}
Any suggestions as to why this is not working? I have a feeling I'm missing something fundamental about routing in Zend through .ini files.
Apparently I'm more rusty in Zend than I thought. A few minutes after posting I realized I'm trying to access the parameter the wrong way in my controller. It should not be a parameter to addAction, instead I should access it through the request object inside the function:
correct addAction in ShopController:
public function addAction()
{
$id = $this->_request->getParam('productid');
echo "the id: ".$id;
}
I also realized I can simplify my route setup quite a bit in this case:
[routes]
routes.shop.route = "shop/:action/:productid"
routes.shop.defaults.controller = shop
routes.shop.defaults.action = index

Probable reasons why autoloading wont work in Zend Framework 1.10.2?

Iam writing an application using Zend Framework 1.10.2.
I created few model classes and a controller to process them.
When Iam executing my application and accessing the admin controller. Iam seeing this error.
Fatal error: Class 'Application_Model_DbTable_Users' not found in C:\xampp\htdocs\bidpopo\application\controllers\AdminController.php on line 16
The error clearly shows its an autoloading error.
Hence I wrote this code in the bootstrap file.
protected function initAutoload()
{
$modeLoader = new Zend_Application_Module_AutoLoader(array
('namespace'=>'','basePath'=>APPLICATION_PATH ));
//echo(APPLICATION_PATH);
return $modeLoader;
}
Still the error remains :( . Can anyone suggest me what Iam missing out here?
This is the location of the Model Users class.
C:\xampp\htdocs\bidpopo\application\models\DbTable\Users.php
This is its code.
class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract
{
//put your code here
protected $_name='users';
public function getUser($id)
{
$id = (int)$id;
$row = $this->fetchrow('id='.$id);
if(!$row)
{throw new Exception("Could not find row id - $id");}
return $row->toArray();
}
public function addUser($userDetailArray)
{
$this->insert($userDetailsArray);
}
public function updateUser($id,$userDetailArray)
{
$this->update($userDetailArray,'id='.(int)$id);
}
public function deleteUser($id)
{
$this->delete('id='. (int)$id);
}
}
This is the Admin Controller's code
class AdminController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$this->view->title= "All Users";
$this->view->headTitle($this->view->title);
$users = new Application_Model_DbTable_Users();
$this->view->users = $users->fetchAll();
}
public function addUserAction()
{
// action body
}
public function editUserAction()
{
// action body
}
public function deleteUserAction()
{
// action body
}
You application classes don't follow the proper naming convention for the namespace you've set. The Zend_Application_Module_AutoLoader is a little different than the normal autoloader in that it doesn't simply change the '_' in the class name with '/'. It looks at the second part of the class name and then checks a folder for the existence of the class based on that.
You need to change the line:
$modeLoader = new Zend_Application_Module_AutoLoader(array(
'namespace'=>'Application',
'basePath'=>APPLICATION_PATH
));
This means it will autoload all module classes prefixed with 'Application_'. When it the second part of the class is 'Model_' it will look in "{$basePath}/models" for the class. The '_' in the rest of the class name will be replaced with '/'. So the file path of the file will be "{$basePath}/models/DbTable/Users.php".
Read more here.