I'm writing a PyroCMS module which involves image upload and thumbnail generation. I'm aware codeigniter has a built in image manipulation class that's capable of making thumbnails, but I'm a big for of phpThumb'ss adaptive resize function. For this reason I'd like to try and get phpThumb working.
I've placed the phpThumb files in ./addons/shared_addons/modules/mymodule/libraries
and I'm trying to load using the following:
$this->load->library('phpThumb/ThumbLib.inc.php');
I'm including the extension because an .inc.php file is not a .php file right? Either way if I keep the extension or not I get this error:
Class 'ThumbLib.inc.php' not found in .../htdocs/system/cms/libraries/MX/Loader.php on line 160
Anyone know what I'm doing wrong?
Thanks, Ed.
The loader naming conventions are probably stricter, so you may need to rename your file to something like 'Thumblib.php' and then declare your class as so class Thumblib {. You may also need to check the library doesn't conflict with anything as is suitable to use in CI.
Also, I think as long as you are loading the library from a controller in the same module folder tree as the library, the load line should be something like:
$this->load->library('Thumblib');
Or if not:
$this->load->library('othermodule/Thumblib');
Good luck.
This is a CodeIgniter question, not a PyroCMS question.
Simple solution:
include 'whatever/the/hell/you.like.php';
Remember guys it's just PHP. You don't need a special method for everything!
Related
I am trying to use ImageMagick inside a controller for CakePHP 3, in order to resize and convert images. However on attempting, the system has been generating an error
Error: Class 'App\Controller\Imagick' not found
I know this looks like it is caused by Imagick not being present, however this is occurring inside the load test for Imagick - it appears to be entirely on CakePHP 3's settings.
if (extension_loaded('imagick'))
{
$AlteredImage = new Imagick($image);
}
What do I need to change with CakePHP in order to get this to work? Alternatively, could this be related to php.ini settings?
With reference to ndm's comment,
\Imagick... php.net/manual/en/language.namespaces.fallback.php
Cakephp work with namespaces so you need to use \Imagick... to reference all Imagick functions as a fallback to global function/constant.
Check out https://www.php.net/manual/en/language.namespaces.fallback.php for more info.
Im tryng to use CakePdf https://github.com/ceeram/CakePdf but I need to be able to use it within the plugin I have created. Im not sure App:uses to call to use the plugin since im not familiar to his folder structure or what hes importing. I'm using Croogo CMS if that might be of any importance.
This is what I know and have done:
I have read their Read Me tutorial and have followed the intructions to the dot, but again, it does not explain usage within another plugin.
Their Bootsrap.php file is as so:
App::build(array('Pdf' => array('%s' . 'Pdf' . DS)), App::REGISTER);
App::build(array('Pdf/Engine' => array('%s' . 'Pdf/Engine' . DS)), App::REGISTER);
App::uses('PdfView', 'CakePdf.View');
To my understanding this is telling Cakephp to treat the files found within these folders as usable classes within the application. When I try App:Uses('CakePdf',('CakePdf.Controller') this does not load the correct class files. I've tested and found that the class is not evein available at my plugin level besided successful plugin bootstraping.
I had to use App::uses('CakePdf', 'CakePdf.Pdf');
I am using Code Igniter, The HMVC library, and Smarty with this library.
Smarty is working fine by default, however if I try to use smarty's inheritance feature ( {extends file="master.tpl"}) then we run into an issue.
The extends feature does not look in the module views folder for the extended file (in the above's case master.tpl), instead it only looks in the application/views/ folder and throws an error if it cannot find it.
I could add APPPATH."modules/smartytest/views" to the $config['template_directory'] array in the smarty config file. but that throws an error for each item in the array it checks first for the file. filemtime(): stat failed for application/views/master.tpl
and that has the added issue of, if I have three modules all the the array and the modules all have a master.tpl then no matter what module I call the extend from it will load the first one found.
So, is there a way to get smarty's extend function to behave nicely with the HMVC modules?
Ah, found a working solution,
in My_Parser.php edit the block at line 30 so it reads:
// Modular Separation / Modular Extensions has been detected
if (method_exists( $this->CI->router, 'fetch_module' ))
{
$this->_module = $this->CI->router->fetch_module();
//add the current module view folder as a template directory
if ($this->_module !== '')
$this->CI->smarty->addTemplateDir(APPPATH."modules/".$this->_module.'/views');
}
The one drawback of this method is that smarty will look in your application/views folder before the module views folder. if someone knows a solution to that then it would be fantastic.
The problem is that CI is not checking error_reporting() returns 0, because Smarty is using the # control operator:
So add the line at the top of the function "_exception_handler":
if (error_reporting() == 0) return;
To the "Common.php" file in the "_exception_handler" function (line 469), or create your own function with the same name before calling "CodeIgniter.php" in the index.php file.
Best!
I need to add custom context classesDirectory in applicationDirectory section to the .zfproject.xml.
I have created a context class, that extends Zend_Tool_Project_Context_Filesystem_Directory but the issue is that all contexts loading necessary to parse .zfproject.xml are hardcoded in Zend_Tool_Project_Provider_Abstract class as:
$contextRegistry->addContextsFromDirectory(
dirname(dirname(__FILE__)) . '/Context/Zf/', 'Zend_Tool_Project_Context_Zf_'
);
$contextRegistry->addContextsFromDirectory(
dirname(dirname(__FILE__)) . '/Context/Filesystem/', 'Zend_Tool_Project_Context_Filesystem_'
);
So I don't see any way to load my context without patching zend sources (or adding custom files to Zend library directories).
Is it even possible?
I don't believe it is possible without changing the ZF source code. You could try creating an issue on http://framework.zend.com/issues along with a patch. Please make this generic though.
Alternatively, what are you trying to do that requires a custom context? Maybe there's another way to solve it?
We have used Zend_Log, which is configured in application.ini differently for different circumstances. We initialize it/get it in the bootstrap and store it in the registry:
$r = $this->getPluginResource('log');
$logger = $r->getLog();
But we've subclassed Zend_Log (say, Our_Log) to add customized features, and want to get it the same way. So then we have to make a new Resource Plugin. That seems quite easy - just copy Application/Resource/Log.php, rename the file to Ourlog.php, rename the class to class Zend_Application_Resource_Ourlog. For now, let's not worry about "Our_Log", the class -- just use the new Resource Plugin to get a Zend_Log, to reduce the variables.
So then, our new code in the bootstrap is:
$r = $this->getPluginResource('ourlog');
$logger = $r->getLog();
but of course this doesn't work, error applying method to non-object "r". According to the documentation,
"As long as you register the prefix path for this resource plugin, you
can then use it in your application."
but how do you register a prefix path? That would have been helpful. But that shouldn't matter, I used the same prefix path as the default, and I know the file is being read because I "require" it.
Anyway, any guidance on what simple step I'm missing would be greatly appreciated.
Thanks for the pointers -- so close, so close (I think). I thought I was getting it...
Okay, so I renamed the class Xyz_Resource_Xyzlog, I put it in library/Xyz/Resource/Xyzlog.php
Then, because I don't love ini files, in the bootstrap I put:
$loader=$this->getPluginLoader();
$loader->addPrefixPath('Xyz_Resource','Xyz/Resource/');
$r = $this->getPluginResource('xyzlog');
if (!is_object($r)) die ('Not an object!!');
Sudden Death. So, okay, do the ini:
pluginPaths.Xyz_Resource='Xyz/Resource/'
The same. No help. I believed that the basepaths of the plugin paths would include the PHP "include" paths. Am I mistaken in that? Any other ideas? I'll happily write up what finally works for me to help some other poor soul in this circumstance. Something to do with Name Spaces, maybe?
Plugin classes are resolved using the plugin loader, which works slightly differently to the autoloader; so just requiring the class in doesn't help you here. Instead, add this to your application.ini:
pluginPaths.Application_Resource = "Application/Resource"
you should then be able to use the class as normal. Since your path above will be checked before the default Zend one, you can also name your class 'Log' and still extend the Logger resource to override the standard functionality.