Re: [fw-general] Zend Framework + Doctrine Module Autoloader issue

2009-07-10 Thread dbroderick

Thanks to all for the input.

I want to continue down the road of a resource plugin for my Doctrine
configuration since it is what I think the resource plugin is meant to
provide.  I envision for my application that I will configure the DB Adapter
in the application configuration and within my Bootstrap I will load the
adapter dynamically based on that configuration.

So let me pose this question differently and I hope some Zend people will
comment.  

Is it currently possible from within a Resource Plugin to modify, update the
default module autoloader object configuration when it is instantiated the
application configuration?

If so, how?  If not, does this seem like a valid enhancement?

--David
-- 
View this message in context: 
http://www.nabble.com/Zend-Framework-%2B-Doctrine-Module-Autoloader-issue-tp24392765p24431101.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] Zend Framework + Doctrine Module Autoloader issue

2009-07-09 Thread swilhelm

I would really like to see an example of Doctrine integrated as a module as
well. 

- Steve W.


dbroderick wrote:
 
 I am using ZF 1.8.4 and Doctrine 1.1.2 with a module directory setup of
 
 
 +---application
 |   +---configs
 |   \---modules
 |   +---default
 |   |   +---controllers
 |   |   \---views
 |   |   \---scripts
 |   |   +---error
 |   |   \---index
 |   +---error
 |   |   +---controllers
 |   |   \---views
 |   |   \---scripts
 |   |   \---error
 |   \---user
 |   +---controllers
 |   +---models
 |   |   \---generated
 |   \---views
 |   \---scripts
 |   \---index
 +---library
 |   \---App
 |   \---Application
 |   \---Resource
 +---public
 |   +---images
 |   \---themes
 |   \---default
 |   \---css
 \---tests
 +---application
 \---library
 
 
 I have a resource file called Doctrine.php in my library folder which does
 the following:
 
 
 $zla = Zend_Loader_Autoloader::getInstance();
 $zla-unshiftAutoloader( array( 'Doctrine', 'autoload' ), 'Doctrine'
 )-setFallbackAutoloader( true );
 
 
 $manager = Doctrine_Manager::connection( $this-_getConnectionString() );
 $manager = Doctrine_Manager::getInstance();
 $manager-setAttribute( Doctrine::ATTR_MODEL_LOADING, 
 Doctrine::MODEL_LOADING_CONSERVATIVE );
 $manager-setAttribute( Doctrine::ATTR_PORTABILITY,
 Doctrine::PORTABILITY_NONE );
 $manager-setAttribute( Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true );
 $manager-setAttribute( Doctrine::ATTR_USE_DQL_CALLBACKS, true );
 $manager-setAttribute( Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true );
 
 
 My config xml file has this:
 
 
 --- snip ---
 
 
 pluginPaths
   
 App_Application_Resource![CDATA[App/Application/Resource]]/App_Application_Resource
   /pluginPaths  
   resources
   frontController
   
 defaultmodule![CDATA[default]]/defaultmodule
   params
   
 prefixDefaultModule![CDATA[true]]/prefixDefaultModule
   
 usedefaultcontrolleralways![CDATA[false]]/usedefaultcontrolleralways
   /params
   /frontController
   modules
   default![CDATA[default]]/default
   error![CDATA[error]]/error
   user![CDATA[user]]/user
   /modules
   !-- Doctrine application plugin --
   doctrine
   dbtype![CDATA[dbtype]]/dbtype
   dbhost![CDATA[localhost]]/dbhost
   dbname![CDATA[dbname]]/dbname
   dbuser![CDATA[dbuser]]/dbuser
   dbpass![CDATA[dbpass]]/dbpass
 /doctrine   
   !-- View application plugin --
   view![CDATA[view]]/view
   /resources
 
 
 --- snip ---
 
 
 The default Module Autoloader is loaded correctly during bootstrapping,
 making available the default resource types (form, model, dbtable), but I
 use Doctrine so dbtable is not used and I would like to insert, override
 or even replace the default resource type(s) with a folder in models that
 Doctrine uses which is 'generated'.
 
 
 My preference is that when my Resource Plugin which configures Doctrine as
 my DB layer, also can inject the needed resource type into the default
 module autoloader, in order to make the configuration available in all
 modules.
 
 
 I have tried for the past day to get this to work but all of the examples
 I find are to create a module autoloader in the module bootstrap file
 which means (as I understand it) that I have to do this for each module
 bootstrap.
 
 
 I am still new to Zend and struggling a bit with the changes in v1.8, so I
 may have just missed the example that shows how this is done.
 
 
 Of course my ultimate problem here is that when I try to load a model
 User.php in the models folder which extends generated\BaseUser.php, the
 BaseUser class is not found.
 
 Thanks,
 David
 

-- 
View this message in context: 
http://www.nabble.com/Zend-Framework-%2B-Doctrine-Module-Autoloader-issue-tp24392765p24414344.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Re: [fw-general] Zend Framework + Doctrine Module Autoloader issue

2009-07-09 Thread Matthew Ratzloff
At my company I ended up creating a Doctrine integration class with a couple
of special methods:
class My_Doctrine
{
/**
 * Recursively (and lazily) load all models from a directory or
 * array of directories.
 *
 * @param string|array $directory Models directory or directories
 */
public static function loadModels($directory);

/**
 * Returns a table object, used for retrieving sets of records.
 *
 * @param  string $className Class name
 * @param  Doctrine_Connection $connection (Optional) Database
connection (default: null)
 * @return Doctrine_Table
 */
public static function getTable($className, $connection = null);
}

-Matt

On Thu, Jul 9, 2009 at 10:15 AM, swilhelm st...@studio831.com wrote:


 I would really like to see an example of Doctrine integrated as a module as
 well.

 - Steve W.


 dbroderick wrote:
 
  I am using ZF 1.8.4 and Doctrine 1.1.2 with a module directory setup of
 
 
  +---application
  |   +---configs
  |   \---modules
  |   +---default
  |   |   +---controllers
  |   |   \---views
  |   |   \---scripts
  |   |   +---error
  |   |   \---index
  |   +---error
  |   |   +---controllers
  |   |   \---views
  |   |   \---scripts
  |   |   \---error
  |   \---user
  |   +---controllers
  |   +---models
  |   |   \---generated
  |   \---views
  |   \---scripts
  |   \---index
  +---library
  |   \---App
  |   \---Application
  |   \---Resource
  +---public
  |   +---images
  |   \---themes
  |   \---default
  |   \---css
  \---tests
  +---application
  \---library
 
 
  I have a resource file called Doctrine.php in my library folder which
 does
  the following:
 
 
  $zla = Zend_Loader_Autoloader::getInstance();
  $zla-unshiftAutoloader( array( 'Doctrine', 'autoload' ), 'Doctrine'
  )-setFallbackAutoloader( true );
 
 
  $manager = Doctrine_Manager::connection( $this-_getConnectionString() );
  $manager = Doctrine_Manager::getInstance();
  $manager-setAttribute( Doctrine::ATTR_MODEL_LOADING,
  Doctrine::MODEL_LOADING_CONSERVATIVE );
  $manager-setAttribute( Doctrine::ATTR_PORTABILITY,
  Doctrine::PORTABILITY_NONE );
  $manager-setAttribute( Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true );
  $manager-setAttribute( Doctrine::ATTR_USE_DQL_CALLBACKS, true );
  $manager-setAttribute( Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true );
 
 
  My config xml file has this:
 
 
  --- snip ---
 
 
  pluginPaths
 
 
 App_Application_Resource![CDATA[App/Application/Resource]]/App_Application_Resource
/pluginPaths
resources
frontController
 
 defaultmodule![CDATA[default]]/defaultmodule
params
 
 prefixDefaultModule![CDATA[true]]/prefixDefaultModule
 
 
 usedefaultcontrolleralways![CDATA[false]]/usedefaultcontrolleralways
/params
/frontController
modules
default![CDATA[default]]/default
error![CDATA[error]]/error
user![CDATA[user]]/user
/modules
!-- Doctrine application plugin --
doctrine
dbtype![CDATA[dbtype]]/dbtype
dbhost![CDATA[localhost]]/dbhost
dbname![CDATA[dbname]]/dbname
dbuser![CDATA[dbuser]]/dbuser
dbpass![CDATA[dbpass]]/dbpass
  /doctrine
!-- View application plugin --
view![CDATA[view]]/view
/resources
 
 
  --- snip ---
 
 
  The default Module Autoloader is loaded correctly during bootstrapping,
  making available the default resource types (form, model, dbtable), but I
  use Doctrine so dbtable is not used and I would like to insert, override
  or even replace the default resource type(s) with a folder in models that
  Doctrine uses which is 'generated'.
 
 
  My preference is that when my Resource Plugin which configures Doctrine
 as
  my DB layer, also can inject the needed resource type into the default
  module autoloader, in order to make the configuration available in all
  modules.
 
 
  I have tried for the past day to get this to work but all of the examples
  I find are to create a module autoloader in the module bootstrap file
  which means (as I understand it) that I have to do this for each module
  bootstrap.
 
 
  I am still new to Zend and struggling a bit with the changes in v1.8, so
 I
  may have just missed the example that shows how this is done.
 
 
  Of course my ultimate problem here is that when I try to load a model
  User.php in the models folder which extends generated\BaseUser.php, the
  BaseUser class is not found.
 
  Thanks,
 

Re: [fw-general] Zend Framework + Doctrine Module Autoloader issue

2009-07-09 Thread Jon Lebensold
Another way is simply to create an entry in your  bootstrap:

protected function _initDoctrine()
{
$this-bootstrap(autoload);

$dbConfig = $this-options['db'];
defined('CONFIG_PATH') || define('CONFIG_PATH',
APPLICATION_PATH . '/configs');
defined('DATA_FIXTURES_PATH') || define('DATA_FIXTURES_PATH',
CONFIG_PATH . '/data/fixtures');
defined('SQL_PATH') || define('SQL_PATH',
CONFIG_PATH . '/data/sql');
defined('MIGRATIONS_PATH') || define('MIGRATIONS_PATH',
CONFIG_PATH . '/migrations');
defined('YAML_SCHEMA_PATH') || define('YAML_SCHEMA_PATH',
CONFIG_PATH . '/schema.yml');
defined('MODELS_PATH') || define('MODELS_PATH',
APPLICATION_PATH . '/models');
defined('DB_PATH') || define('DB_PATH' ,
'mysql://' . $dbConfig['username']. ':' . $dbConfig['password']. '@' .
$dbConfig['host']. '/' . $dbConfig['name']);

require_once 'Doctrine.php';

spl_autoload_register(array('Doctrine', 'autoload'));

$connection = Doctrine_Manager::connection(DB_PATH);
$connection-setCharset('UTF8');

Doctrine_Manager::getInstance()-setAttribute('model_loading',
'conservative');
Doctrine::loadModels(MODELS_PATH);
}


and then add Doctrine_ as a namespace:

$autoloader-registerNamespace(array('Doctrine_', 'App_'));

and include them in your include paths:

set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
APPLICATION_PATH . '/models',
APPLICATION_PATH . '/models/generated',
get_include_path(),
)));

this works for me... although its not a total separation, it works fine for
my purposes.


On Thu, Jul 9, 2009 at 1:32 PM, Matthew Ratzloff
m...@builtfromsource.comwrote:

 At my company I ended up creating a Doctrine integration class with a
 couple of special methods:
 class My_Doctrine
 {
 /**
  * Recursively (and lazily) load all models from a directory or
  * array of directories.
  *
  * @param string|array $directory Models directory or directories
  */
 public static function loadModels($directory);

 /**
  * Returns a table object, used for retrieving sets of records.
  *
  * @param  string $className Class name
  * @param  Doctrine_Connection $connection (Optional) Database
 connection (default: null)
  * @return Doctrine_Table
  */
 public static function getTable($className, $connection = null);
 }

 -Matt


 On Thu, Jul 9, 2009 at 10:15 AM, swilhelm st...@studio831.com wrote:


 I would really like to see an example of Doctrine integrated as a module
 as
 well.

 - Steve W.


 dbroderick wrote:
 
  I am using ZF 1.8.4 and Doctrine 1.1.2 with a module directory setup of
 
 
  +---application
  |   +---configs
  |   \---modules
  |   +---default
  |   |   +---controllers
  |   |   \---views
  |   |   \---scripts
  |   |   +---error
  |   |   \---index
  |   +---error
  |   |   +---controllers
  |   |   \---views
  |   |   \---scripts
  |   |   \---error
  |   \---user
  |   +---controllers
  |   +---models
  |   |   \---generated
  |   \---views
  |   \---scripts
  |   \---index
  +---library
  |   \---App
  |   \---Application
  |   \---Resource
  +---public
  |   +---images
  |   \---themes
  |   \---default
  |   \---css
  \---tests
  +---application
  \---library
 
 
  I have a resource file called Doctrine.php in my library folder which
 does
  the following:
 
 
  $zla = Zend_Loader_Autoloader::getInstance();
  $zla-unshiftAutoloader( array( 'Doctrine', 'autoload' ), 'Doctrine'
  )-setFallbackAutoloader( true );
 
 
  $manager = Doctrine_Manager::connection( $this-_getConnectionString()
 );
  $manager = Doctrine_Manager::getInstance();
  $manager-setAttribute( Doctrine::ATTR_MODEL_LOADING,
  Doctrine::MODEL_LOADING_CONSERVATIVE );
  $manager-setAttribute( Doctrine::ATTR_PORTABILITY,
  Doctrine::PORTABILITY_NONE );
  $manager-setAttribute( Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true );
  $manager-setAttribute( Doctrine::ATTR_USE_DQL_CALLBACKS, true );
  $manager-setAttribute( Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true );
 
 
  My config xml file has this:
 
 
  --- snip ---
 
 
  pluginPaths
 
 
 App_Application_Resource![CDATA[App/Application/Resource]]/App_Application_Resource
/pluginPaths
resources
frontController
 
 defaultmodule![CDATA[default]]/defaultmodule
params
 
 prefixDefaultModule![CDATA[true]]/prefixDefaultModule
 
 
 usedefaultcontrolleralways![CDATA[false]]/usedefaultcontrolleralways
/params
/frontController
modules