Class 'Doctrine_Record' not found - php

This started over here when I was getting Class 'Classname_model' not found. I fixed this by explicitly calling that class.
However, it revealed another problem:
Fatal error: Class 'Doctrine_Record' not found in /../application/models/classname_model.php on line 7
Here is line 7:
class Classname_model extends Doctrine_Record {
Now, I'm incredibly new at Doctrine, CodeIgniter, and all things OOP/MVC.
Might there be a problem with my Doctrine install or configuration?

Bootstrapping Doctrine and your models...
spl_autoload_register(array('Doctrine', 'autoload')); //First set the doctrine autoloader
$manager = Doctrine_Manager::getInstance();
$manager->setCharset('UTF8');
$manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
$manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
Doctrine_Core::loadModels(__PATH_TO_YOUR_MODELS__);

Doctrine_Record is part of Doctrine 1.x. Doctrine 2.x is a complete rewrite and has no such class. So start by bringing down the latest Doctrine 1.x. And then you will need to take some time to understand autoloading and include path stuff. Find a simple tutorial and work you way through it.

Related

Attempted to load class "Doctrine_Core"

I'm trying to follow these steps:
http://docs.doctrine-project.org/projects/doctrine1/en/latest/en/manual/hierarchical-data.html
Please, correct me if I am wrong. Firstly, I've created this class in AppBundle/Model route:
namespace AppBundle\Model;
class Item extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 255);
}
public function setUp()
{
$this->actAs('NestedSet');
}
}
And then I use it in a controller like this:
$treeObject = Doctrine_Core::getTable('Category')->getTree();
I have two questions:
- Where do I have to define the Category table and how
- With this previous code I ran into this error: Attempted to load class "Doctrine_Core" from namespace "AppBundle\Controller\Admin
Any idea please? Thanks
Doctrine has it's bundle for Symfony, that allows to store all config data in YML. https://symfony.com/doc/current/bundles/StofDoctrineExtensionsBundle/index.html - it has "Tree extension" and it is exactly what you're looking for.
Classes Doctrine_Record and Doctrine_Core are part of Doctrine in 1.x version, Symfony2 is using Doctrine 2.x which is completely different than 1.x version. For example Doctrine 2.x does not use Active Record approach and this is what you are trying to use. In Doctrine 2 Model classes (Entities) don't extend any class
Check this piece of doc how to use Doctrine2 in Symfony2
Ok, I followed these steps:
Install this: http://symfony.com/doc/master/bundles/StofDoctrineExtensionsBundle/index.html
Don't forget to set up the configuration for the extensions, in this case for tree like this in config.yml:
stof_doctrine_extensions:
orm:
default:
tree: true

Cake PHP 2.4.1: how to store fixtures in a subdirectory

I have some code that I am migrating from Cake 1.3 to Cake 2.4.1, and I'm getting an internal error with one of my test cases. It's telling me that it cannot find the referenced fixture class. The fixture class I'm trying to reference is stored under a sub-directory: app/Test/Fixture/Ds1, which worked fine with the earlier version of Cake. Here's my test/fixture distilled down:
// app/Test/Case/Model/TestTest.php
<?php
class TestTest extends CakeTestCase {
public $fixtures = array('app.ds1.test'); // Trying to load this fixture.
public function testStuff()
{
$this->assertEqual(0, 0);
}
}
// app/Test/Fixture/Ds1/TestFixture.php
<?php
class TestFixture extends CakeTestFixture {
}
And the internal error I'm receiving is Referenced fixture class Ds1.test (Test\Fixture\Ds1.testFixture.php) not found. I've been googling around for a while, and will continue to do so, but I wanted to ask here just in case somebody knows off the top of their head how to reconcile this issue. Chances are I'm missing something really obvious, but I'm spinning my wheels on this one.
Inferring from the 2.x documentation, it looks like you can't have fixtures in sub-directories in 2.4.
From http://book.cakephp.org/2.0/en/development/testing.html
As of 2.5.0, you can load fixtures in subdirectories. Using multiple directories can make it >easier to organize your fixtures if you have a larger application. To load fixtures in >subdirectories, simply include the subdirectory name in the fixture name:
class ArticleTest extends CakeTestCase {
public $fixtures = array('app.blog/article', 'app.blog/comment');
}
In the above example, both fixtures would be loaded from App/Test/Fixture/blog/.
I wouldn't migrate to 2.4.1 just like that.
Since it is a very old code (1.3) I would migrate first to 2.1.
I faced the same problem. I submited a pull request, you can find it here :
https://github.com/cakephp/cakephp/pull/3005

Loading a Zend 2 Authentication Adapter

I'm writing a custom authentication adapter in Zend Framework 2.
module/Application/src/Application/Auth/Adapter/Auth_Adapter.php -
namespace Application\Auth;
use Zend\Authentication\Adapter\AdapterInterface;
use Zend\Authentication\Result;
class Auth_Adapter implements AdapterInterface {
...
Not sure what I'm doing wrong, but no classes can seem to find my new adapter. I've tried moving it into an autoloaded path (the Application/Controller directory) with no luck either.
Im assuming your namespaces are invalid. Given the path "module/Application/src/Application/Auth/Adapter/Auth_Adapter.php"
Try:
namespace Application\Auth\Adapter;

Mapping Exception when trying out the Symfony2 example from the cookbook

I just started learning Symfony2 and I'm following the examples from "The Cookbook" from Symfony's website.
When trying the code from the chapter about loading users from database (Entity Provider) (Link to the chapter) I get the following error:
MappingException: Class Acme\UserBundle\Entity\User is not a valid entity or mapped super class.
... and can't find out wthat I am doing wrong. I do think I followed all the steps provided in the chapter.
Thanks for any help,
I finally found the problem when revising step by step the whole code.
I forgot to register UserBundle in AppKernel.php.
I have the same problem. I looked at symfony+Mapping error but that solution not works for me. Then I found, that Michi solution works https://stackoverflow.com/a/10935672/2910183
So, here is what I do at all:
register bundle in AppKernel.php:
new Acme\UserBundle\AcmeUserBundle(),
create this bundle (it is just a copy of FOS\UserBundle\FOSUserBundle) and save as src/Acme/UserBundle/AcmeUserBundle.php
<?php
namespace Acme\UserBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\DoctrineMongoDBMappingsPass;
use Doctrine\Bundle\CouchDBBundle\DependencyInjection\Compiler\DoctrineCouchDBMappingsPass;
class AcmeUserBundle extends Bundle {
}

Using PHP 5.3 namespaces (Doctrine2) with Zend Framework classes

i am having a situation where my doctrine model, Post, is in the namespace Application\Entities and i want to try to implement Zend_Acl_Resource_Interface. i get the error
Fatal error: Interface
'Application\Entities\Zend_Acl_Resource_Interface'
not found in
D:\Projects\Websites\php\ZendFram
ework\LearningZF\library\Application\Entities\Post.php
on line 8
namespace Application\Entities;
use DoctrineExtensions\NestedSet\Node;
/**
* #Entity #Table(name="posts")
*/
class Post implements Node, Zend_Acl_Resource_Interface {
update
if i try
class Post implements Node, \Zend_Acl_Resource_Interface {
Fatal error: Interface
'Zend_Acl_Resource_Interface' not
found in
D:\Projects\Websites\php\ZendFramework\LearningZF\library\Application\Entities\Post.php on
line 8
Are you using the ZF 2.0 branch or the stable one, e.g. 1.10? Is your autoloader setup to load classes with the ZF naming scheme?
You can use the Conversion tool the ZF devs used to convert ZF to using namespaces:
http://github.com/ralphschindler/PHPTools
http://blog.calevans.com/2010/03/27/zends-new-namespace-converter/
As far as I remember Zend Framework does not uses namespaces (until 2.x comes out anyway) so it's classes are in global namespace. Try class Post implements Node, \Zend_Acl_Resource_Interface {
i am going to put this as an answer, so i can mark this qn as answered if noone have any other answers, its actually a workaround i used. i am not too sure why it worked exactly, or rather why the Zend autoloader failed
i added the require_once to include Zend_Acl_Resource_Interface
namespace Application\Entities;
use DoctrineExtensions\NestedSet\Node;
require_once "Zend/Acl/Resource/Interface.php";
/**
* #Entity #Table(name="posts")
*/
class Post implements Node, \Zend_Acl_Resource_Interface {
i think a better fix will be to conversion tool in #Gordon's answer. but i cant fix all the errors i get with "unclean" conversion yet. paths are broken.

Categories