we`re currently developing our own Feedmanager for ShopProducts based on Zend Framework.
In this feedmanager you can manage several feeds, to be created and sent to different locations.
Each feed has n-fields which are in the current version only in one level.
Now we want to change it to a multilevel version, we we have parentfields and childfields.
We dont want to reinvent the wheel, so we would like to use a developed class or helper.
I found the class of F. Pietka.
https://github.com/fpietka/Zend-Nested-Set
I tried to use this helper in our system, but had no success.
I wrote the following line, to use the class:
$oNested = new NestedSet_Model();
I got the following error message:
Fatal error: Call to undefined method NestedSet_Model::getDbTable() in
D:\xampp\htdocs\feedmanager_alpha\application\classes\NestedSet.class.php
on line 75
In the readme of Peitka`s NestedSet helper it says that the ZendLibrary needs to be in the include path.
I think I did this with the following lines:
define("ROOTPATH", realpath("../"));
define("LIBPATH", ROOTPATH . DIRECTORY_SEPARATOR . 'library' . DIRECTORY_SEPARATOR);
// Ensure library/ is on include_path
set_include_path(
implode(PATH_SEPARATOR,
array(
realpath(LIBPATH)
)
)
);
Did I set the include path correctly?
What could be the problem in my case?
Is a nested-set the best way to create the parent-child-model?
I would strongly advise you not to use this class, because it's clearly a WIP. However, if you want to circumvent this error, you can just delete the __construct() method and call the setDb() and setTableName() by hand.
Example:
$model = new NestedSet_Model();
$model->setDb(Zend_Db_Table::getDefaultAdapter());
$model->setTableName('table_name');
class NestedSet extends Zend_Db_Table
{
protected $_name = 't_nested_set_mkb_10';
public function set(){
$model = new NestedSet_Model();
$model->setDb(Zend_Db_Table::getDefaultAdapter());
$model->setTableName('t_nested_set_mkb_10');
}
}
It was long overdue, but I updated https://github.com/fpietka/Zend-Nested-Set (even with unit tests).
Feel free to create issues!
Related
I'm trying to use Universal Class Loader functionality from Phalcon into my project, however I can't get it working.
Here is how i've implemented into my app (using registerClasses).
index.php:
//...
$loader->registerClasses(
array(
"Commons" => "library/classes/CommonsClass.php"
)
);
$loader->register();
sampleController.php:
public function doAction()
{
$cc = new Commons();
}
And when I execute the controller, it throws me this exception:
Fatal error: Class 'Commons' not found in C:\the\path\to\phalcon_app\app\controllers\SomeController.php on line 63
The Phalcon Documentation just say that you need to register a class and call it in your funcion. There is something I've missed?
Ps.: The library folder is not registered anywhere (don't know if its needed), and it is in the same path as controllers, views, etc (/app/).
You should probably check your directory structure.
given:
mah_app/app/config/loader.php
mah_app/library/classes/Commons.php
I would expect this to work:
// loader.php
$loader->registerClasses(
array(
"Commons" => __DIR__ . "/../../library/classes/Commons.php"
)
)->register();
// works with $loader->registerDirs() for sure
Also, I would also suggest using namespaces and/or matching file name with class name.
Had the same problem. I commented out the namespace declaration inside the class and it worked. Version 2.0.3.
I want to try Yii, but I don't want use it as my main framework. In other words, I want to use my own framework while also using some of Yii's features. I figured that in order to be able to instantiate Yii's classes from my application, I'd just need to register Yii's autoloader from my application, probably in a way similar to this:
spl_autoload_register
(
function ($classname)
{
YiiBase::autoload($className);
}
);
Of course, I'm gonna need to require or include the YiiBase class, so before I call the previous function, I do this:
$yiiBase = $_SERVER['DOCUMENT_ROOT'].'/yii/framework/YiiBase.php';
require_once($yiiBase);
But I get a "Cannot redeclare class YiiBase" error. What am I missing?
1) Do not include YiiBase.php direcly, include yii.php. Because yii.php contains a class Yii which is used in all over framework code (even in YiiBase methods).
$yii = $_SERVER['DOCUMENT_ROOT'].'/yii/framework/yii.php';
require_once($yii);
( and YiiBase.php is included in yii.php by default)
2) register your autoload handler in this way.
(Yii has built-in functionality to add custom autoload handlers ).
$my_autoload = function($class) { ... };
// OR
// $my_autoload = array('MyClass', 'my_autoload')
YiiBase::registerAutoloader($my_autoload, true);
The second parameter true tells whether to append/prepend the new autoloader after/before the default Yii autoloader
if the YiiBase.php included, then Yii's default autoloader will also gets included. No need to call YiiBase::autoload() explicitly in you code. Ref: check the last line in YiiBase.php file
You can take a look at some approaches of people integrating Yii with wordpress, you may not need to do ->run() the application, unless you need the controllers/routing, it also depends on what parts of the framework you pretend to use.
To do it for Yii2, this article explains it under the heading "Using Yii in Third-Party Systems" in the middle of the page.
Here is the relevant part to include on startup of your external application:
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
$yiiConfig = require(__DIR__ . '/../config/yii/web.php');
new yii\web\Application($yiiConfig); // Do NOT call run() here
Obviously, __DIR__ . '/../ may need to be adjusted to fit your directory layout.
Short version
Where does the Client class look for the DispatchableInterface interface?
class Client implements Libraries\Stdlib\DispatchableInterface
I'm trying to add the ZF2 libraries to a CodeIgniter installation. The whole Zend folder sits in:
/Users/stef/Sites/site_name/application/libraries/
In my CI controller I have
public function run()
{
$CI =& get_instance();
$CI->load->library('Zend');
$CI->load->library('Zend/Http/Client');
$client = new Client($url);
//Do stuff
}
When I access the run() method I get a fatal error:
Fatal error: Interface 'Zend\Stdlib\DispatchableInterface' not found in /Users/stef/Sites/site_name/application/libraries/Zend/Http/Client.php on line 27
In libraries/Zend.php (a file I added, not part of the ZF) I have
function __construct($class = NULL)
{
// include path for Zend Framework
// alter it accordingly if you have put the 'Zend' folder elsewhere
ini_set('include_path',ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries/Zend/');
}
It doesn't seem to matter what I set the include_path to be, even when I put bogus values the fatal error stays the same. So it seems that the loading of the interface DispatchableInterface doesn't make use of the include_path.
How can I get Client.php to "find" the interface, which it tries to do so here:
class Client implements Libraries\Stdlib\DispatchableInterface
Least difficult solution is probably:
set_include_path(get_include_path() . PATH_SEPARATOR . '/Users/stef/Sites/site_name/application/libraries/');
require_once 'Zend/Loader/StandardAutoloader.php';
$loader = new Zend\Loader\StandardAutoloader(array('autoregister_zf' => true));
$loader->register();
Then skip the CI->load part. And just use new Zend\Http\Client. Also make sure that the dispatchable interface is in /Users/stef/Sites/site_name/application/libraries/Zend/Stdlib/DispatchableInterface.php
Update:
I noticed just now:
class Client implements Libraries\Stdlib\DispatchableInterface
What class is this? Is it Zend's class? I guess it's some class of yours. And you're adding wrongly namespaced interface. IMO it should be \Zend\Stdlib\DispatchableInterface
I'm using Codeigniter 2.1.0.
I'm including the Amazon Web Services SDK in a custom model using require_once APPPATH . "/libraries/aws_sdk/sdk.class.php";
This works well. However when CI decides it later needs to load it's db cache class, it calls (via CI_DB_driver::_cache_init):
if ( ! class_exists('CI_DB_Cache'))
{
if ( ! #include(BASEPATH.'database/DB_cache.php'))
{
return $this->cache_off();
}
}
This triggers the autoload of the AWS SDK (the exact method being CFLoader::autoloader).
I can get around this by telling class_exists not to autoload, as it seems that DB_cache.php is included anyway if class_exists returns false:
if ( ! class_exists('CI_DB_Cache', false))
{
if ( ! #include(BASEPATH.'database/DB_cache.php'))
{
return $this->cache_off();
}
}
This dirty fix works, but obviously only fixes the immediate problem. In general, what is the best way to ensure that CodeIgniter doesn't get confused with the autoload from other libraries?
Please note:
I've read bits and pieces about using spl_autoload_register. It seems that Codeigniter doesn't use this and I'm not sure how I should implement this safely. I would find a solid example of how and where I should implement this most useful (if, of course, this is the solution).
It appears that the AWS SDK already uses spl_autoload_register: spl_autoload_register(array('CFLoader', 'autoloader'));
As you probably know, you don't really want to be modifying the core methods in CI. So, to prevent CI from conflicting with your class, you want to do something very similar to the following:
Leave your folder structure as is, but create a new file outside your aws_sdk folder. Name it something like *Aws_loader* or something that makes sense to you. If you want to autoload the sdk, then in the CI autoloader file, add:
CI Autoload file (application/config/autoload.php):
$autoload['libraries'] = array('Aws_loader');
Your init file:
class CI_Aws_sdk{
// for use with PHP < version 5
/*public function CI_Aws_sdk(){
require dirname(__FILE__) . DIRECTORY_SEPARATOR . "aws_sdk" .DIRECTORY_SEPARATOR . 'sdk.class.php';
}*/
// for use with PHP >= 5
public function __construct(){
require dirname(__FILE__) . DIRECTORY_SEPARATOR . "aws_sdk" .DIRECTORY_SEPARATOR . 'sdk.class.php';
}
}
So your directory structure looks like this now:
application --
config --
...
libraries --
Aws_loader.php
aws_sdk --
sdk.class.php
If you aren't autoloading the sdk, then in your controller, you can do this:
$this->load->library('Aws_loader');
Either way, CI with load the class for you and effectively separate any methods within it and now you can operate within that class just like any other library or model that you've loaded previously, without interfering with CI's methods, similar to this:
$this->Aws_loader->do_something();
You can use the same method for any third party class library or even one that you wrote yourself. A very similar arrangement can be used for models, libraries, helpers and the like.
Hope this helps!
We are finding cases where we get the following 500 error:
File xyz.php does not exist or class "xyz" was not found in the file at () in SF_ROOT_DIR/lib/vendor/Zend/Loader.php line 107 ...
where xyz ==
Memcache (when trying to use symfony cc on the command line)
or
sfDoctrineAdminGenerator (when using an old-ish AdminGenerator-generated CMS page).
We use Propel, but Loader.php is trying to load classes used only for Doctrine.
Currently I am using a filthy hack where I request Loader.php to check if the file is either of these two cases, and if so simply return rather than trying to load it. Obviously, this is unacceptable longer term.
Has anybody encountered this, and how did you solve it?
Edited to add:
We have:
class ProjectConfiguration extends sfProjectConfiguration
{
public function setup()
{
// for compatibility / remove and enable only the plugins you want
$this->enableAllPluginsExcept(array('sfDoctrinePlugin'));
}
}
And we have a propel.ini file in our top level config directory. This has only started in the past four weeks or so, and we've had a stable build for over a year now. I'm pretty sure Doctrine is totally disabled.
The only thing I can think of is to make sure Doctrine is disabled in your project configuration...
Could this be a conflict between Symfony's autoloader and Zend's? Try adding the following to your ProjectConfiguration.class.php:
set_include_path(sfConfig::get('sf_lib_dir') . '/vendor' . PATH_SEPARATOR . get_include_path());
require_once sfConfig::get('sf_lib_dir').'/vendor/Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
I use Zend Lucene using the above and it works. If that doesn't help, perhaps something in these Zend and Symfony slides may help.
Clear Cache :) And make sure your index.php have the right include file.