I am trying to make use of this Helper class, which was written for earlier version of cake.. It seems that it makes use of the vendor() method to use a third party class, but now that method is deprecated. I am trying to use the following in the helper class to include the third party class called eq_pie.class.php:
App::import('Vendor', 'eq_pie' );
I placed the third party class in the app/vendor folder(which im not sure if its correct)
The helper class makes use of it like so
//vendor('class_eq_pie'); Now commented out..
$this->eq_pie = new eq_pie; //generates error
I get this error: Error: Class 'eq_pie' not found , which means that the third party class is not being included.
What am I missing here? Thanks in advance
Ok, Fellow cakePHP new users... make sure to follow your version's of cake conventions.. the problem was that my current version(2x) expects class names and their respective files to be camelCased rather than underscored..
Fromeq_pie, I changed the class name to EqPieClass, and file toEqPieClass.php. Reference doc here : Class Conventions if you run into trouble. Best of luck
Related
Im building a custom CMS and have setup an autoloader, and have adapted use of namespaces. For the most part things are loading properly, but in certain cases PHP reports that it cannot find the class, the class file has been included.
Once a file is included (using require), it should be instanced as well.
The parent controller is instanced, then the child controller attempts to instance a few of its own dependencies.
$this->auth = new \Modules\Auth\RT\Auth();
This will look for a file at /modules/auth/rt/auth.php, and it does and the class is instanced properly.
The namespace of Auth is:
namespace Modules\Auth\RT;
The auth class tried to load its own dependencies, a model in particular.
$this->auth_model = new Models\ModelAuth();
Here the file to be included is at /modules/auth/rt/models/modelauth.php
It is included successfully, but this is where PHP says I cannot find this class.
Fatal error: Class 'Modules\Auth\RT\ModelAuth' not found in /Users/richardtestani/Documents/ShopOpen-Master/shopopen/modules/auth/rt/auth.php on line 12
What would cause the class from not being instanced even though the file is included?
Thanks
Rich
try this:
$this->auth_model = new Modules\Auth\RT\Models\ModelAuth();
try this:
$this->auth_model = new \Modules\Auth\RT\Models\ModelAuth();
OR
$this->auth_model = new Models\ModelAuth();
when you are in this namespace \Modules\Auth\RT
There was a Missing \ , so the code trys to include the namespace twice;
FOR REAL ;)
I am trying to use a custom class in cakephp. Initially I had created a vendor class which works fine but I can't use other cakephp components.
To use built in components like $this->Text, I can create a custom component but the constructor requires a argument which is a json object returned from an API and I need to keep initializing in a loop
//The constructor for the class
function __construct($objValue) {
$this->messageId = $objValue['id'];
Is using a component suitable for this purpose?
you don't need to create a component here if you don't need it in the controller scope.
also you don't need to make it a vendor class (which is third party stuff).
cake offers you a way out: Libs in APP/Lib
You can use them anywhere anytime.
App::uses('MyClassName', 'Lib');
$MyClass = new MyClassName();
You might even want to create a package in Lib itself - e.g. "Lib/Utility":
App::uses('MyClassName', 'Utility');
without knowing any more about what exactly this custom class does, it is difficult to be any more specific here.
I created two plugins in the CakePHP, and both of them have the same named model, e.g, plugin1.mod and plugin2.mod.
In the two models, defined the same named method, e.g, mymethod.
Now, I have a controller in my main program. Then, use ClassRegistry::init to initialize plugin1 and can call plugin1.mod without problem.
Problem:
When I use ClassRegistry::init to initialize plugin2 and call the plugin2.mod, it is calling plugin1.mod! Can somebody tell me what wrong here is?
Thank you.
in 2.0 this is not possible (anymore).
class paths are cached (inside App class) and therefore can use a class name only once.
You need to use different class names.
I am trying to load a custom exception class that I created according to the instructions here:
http://codeigniter.com/user_guide/general/core_classes.html
MY_Exceptions.php is stored at application/core/
Somehow, when I try loading it, I keep getting this error:
Fatal error: Class 'MY_Exceptions' not found in C:\xampp\htdocs\xampp\facebook\application\models\campaign_model.php on line 29
Based on the instructions, it doesn't say I have to autoload the class or anything. What am I doing wrong?
MY_Exception.php is stored at application/core/
Name the class and file MY_Exceptions with an s
You do not need to autoload or manually load anything in the core directory, nor should you. They are required classes for CI to run that are automatically loaded.
For creating core classes, use this documentation instead: http://codeigniter.com/user_guide/general/core_classes.html
Keep in mind that when calling the class you will use the original class name. Let's say you have created MY_Input. Example:
$this->input->post(); // Do this
$this->my_input->post(); // Don't do this
To understand the why and how, see system/core/Common.php function load_class.
Looking at the docs now, I agree that this should probably be highlighted.
It's trying to find MY_ExceptionS.php, not MY_Exception.php.
I have an enCrypt and deCrypt class which I want to use in my whole Zend Framework project without having to declare it on every need, but just once. Where should this be done? Thank you for any help...
Zend Framework is quite flexible in implementing things.
You could create an instance in a bootstrap file and save it to the registry; whenever you need to call the class just get it from registry?
You could have every controller extend Zend_Controller_Action and put the two functions into this class (only ideal if you're calling the classes from the controller).
Or, what I did, was make my functions static, register my own library (in your application config.ini file, enter the line: autoloaderNamespaces[] = "MyPrefix_", then create a folder in the library folder called MyPrefix) and drop my class in there. When I need it I call $encryptedString = MyPrefix_Crypt::encrypt($string); and $string = MyPrefix_Crypt::decrypt($encryptedString);
Hope this helps :)