Locale cakePHP-usersgroup near Cologne / Lokale cakePHP-usersgroup Nähe Köln

2009-07-21 Thread Andreas Hofmann

Hi,

we want to start a local usersgroup here in Cologne, so we are looking
for some interested people.
Please note, that the following text is therefore written in german:

--

Wir entwickeln nun knapp ein Jahr intensiv mit cakePHP und sind nun
auf der Suche nach Entwicklern hier in der Umgebung zum Erfahrungs-
und Wissensaustausch, Vorstellung eigener Projekte, Forschungen, etc
rund um cakePHP.

Wir betreiben die Social Comminity Platinnetz (www.platinnetz.de),
welche vollständig auf cakePHP gebaut wurde, inkl. aller background-
jobs, die mit einer umfangreichen eigenen cake-shell entwickelt
wurden.

Im Zuge der intensiven Entwicklung konnten wir bereits viel Interna
von cake kennenlernen, vieles Nützliche, aber auch einiges Unnütze und
auch nicht Verwendbare, sowie gänzlich fehlende Elelmente, was man
selber neuschrieb.
So haben wir z.B. eine funktionierende MySQL-Master/Slave-Anbindung
entwickelt mithilfe einer modifizierten Datasource, die AuthComponent
erweitert um den eigenen Passowort-Hash-Mechanismus, eine umfangreiche
Cachemechanik und anderes.

Dieses Wissen wollen wir nicht im stillen Kämmerchen für uns behalten
sondern kundtun, aber auch erfahren, was ihr so gemacht habt.

Wer Interesse hat, meldet sich bitte einfach bei uns und wir versuchen
mal sowas auf die Beine zu stellen.
Schraibt eine Mail an cake...@platinnetz.de

Wir freuen uns auf eure Rückmeldung!
Schöne Grüße aus Köln,

Andreas Hofmann, Olav Schettler
Platinnetz GmbH
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Master / Slave Support

2009-01-19 Thread Andreas Hofmann

Hi all,

we have discovered a way how to realize master/slave support with cake
(also with multiple slaves).
This old post is completely depricated:
http://groups.google.com/group/cake-php/browse_thread/thread/58ea010f930fab6c
Because Model::find() and Model::save() create the $db-handle lines
before it calles the callbacks 'beforeFind' and 'beforeSave'.

The way we realized is to overwrite the save() and updateAll()
methodes and to set the default db-config in the AppModel::__construct
().

Note: One thing remains: It's not possible to do a bindModel in the
'beforeSave' and 'afterSave' callbacks, because they get the wrong db-
config... If you find a way to do it, please let us know!

1. Define your Database-Configs in app/config/database.php. You should
have master and as much slaves you want to have:

class DATABASE_CONFIG {

  var $master = array(
driver' = 'mysql',
'persistent' = false,
'host' = 'localhost',
'login' = 'login',
'password' = 'password',
'database' = 'database',
'encoding' = 'utf8'
  );

  // Config for Slave #1
  var $slave1 = array(
driver' = 'mysql',
'persistent' = false,
'host' = 'slave1',
'login' = 'login',
'password' = 'password',
'database' = 'database',
'encoding' = 'utf8'
  );

  // Config for Slave #2
  var $slave2 = array(
driver' = 'mysql',
'persistent' = false,
'host' = 'slave2',
'login' = 'login',
'password' = 'password',
'database' = 'database',
'encoding' = 'utf8'
  );
...
}

2. Create/Alter app/models/app_model.php and create/alter the
constructor '__construct' of it like the following:

class AppModel extends Model {

  public function __construct($id = false, $table = null, $ds = null)
{

/**
 * USED FOR MASTER/SLAVE MECHANIC *
 **/
// If a datasource is set via params, use it and return
if((is_array($id)  isset($id['ds'])) || $ds) {
  parent::__construct($id, $table, $ds);

  return;
}

// Use a static variable, to only use one connection per page-call
(otherwise we would get a new handle every time a Model is created)
static $_useDbConfig;
if(!isset($_useDbConfig)) {
  // Get all available database-configs
  $sources_list = ConnectionManager::enumConnectionObjects();

  // Find the slaves we have
  $slaves = array();
  foreach($sources_list as $name = $values) {
// Slaves have to be named slave1, slave2, etc...
if(preg_match('/^slave[0-9]+$/i', $name) == 1) {
  $slaves[] = $name;
}
  }

  // Randomly use a slave
  $_useDbConfig = $slaves[rand(0, count($slaves) - 1)];
  $this-_usedSlave = $_useDbConfig;
}
$this-useDbConfig = $_useDbConfig;

parent::__construct($id, $table, $ds);
  }
...
}

This method uses a local static variable to save the db-config
application-wide. It collects all configs from the database.php that
start with slave# and selects a random one for it. This is now the
default-config for the application that is used with every query
done via the Model-class UNTIL we do the next step:

3. We now overwrite the Model::save() and Model::find() methods to use
another database-config for write-queries!
Note: We discovered, that it's not enough to just overwrite Model::save
(), because Model::updateAll() doesn't use the callbacks, neither the
Model::save() method.

  function save($data = null, $validate = true, $fieldList = array())
{
// Remember the old config
$oldDb = $this-useDbConfig;
// Set the new config
$this-setDataSource('master');
// Call the original Model::save() method
$return = parent::save($data, $validate, $fieldList);
// Reset the config/datasource
$this-setDataSource($oldDb);

return $return;
  }

  function updateAll($fields, $conditions = true) {
$oldDb = $this-useDbConfig;
$this-setDataSource('master');
$return = parent::updateAll($fields, $conditions);
$this-setDataSource($oldDb);

return $return;
  }

Now you should have full master/slave support within your cake-
application.
The way it works:
When your application is called, the AppModel will be called the first
time and realizes, that the local $_useDbConfig variable is not set.
So it randomly selects one of your slave-configs and sets this to the
default used database-config (AppModel::useDbConfig). Every further
instance of AppModel will recognize that the local $_useDbConfig
variable already exists and will use the same config.
Now every query you do will use this slave-config, EXCEPT all save's
and updateAll's, because you've overwritten these methods to use your
master-config.

Hope this tutorial was helpful to you!

Greetings,

Andreas Hofmann!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com

Getting route-URL for internal controller/action-URL

2008-10-09 Thread Andreas Hofmann

Hi all,

i discovered the whole Router-class-definition, but I found no method,
that matches my needs :)
Is there any way to get the URL of a defined route for an internal
cake-controller/action-URL.

For example I have this route defined:

Router::connect('/gruppen', array('controller' = 'groups', 'action'
= 'index'));

Is there now a way to get this defined URL ('/gruppen') by calling a
function with the params controller/action, like this:

Router::theMagicMethodThatMustExist(
  array(
'controller' = 'groups'
'action' = 'index'
  )
); // Should now return '/gruppen'

With this I can undock the URLs from the templates/views! Currently
I'm doing stuff like this in a view:

$html-link('A Link', '/groups/index');

But this sucks, because when I define a route for '/groups/index', I
don't want to change the URL in 1000 view-files and replace '/groups/
index' with '/gruppen' :S Would be nice if there is a method I'm
looking for, to always get a defined route-URL, if there is one! :)

Is there such a method out there??

Thanks and greetings,

Andreas!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Getting route-URL for internal controller/action-URL

2008-10-09 Thread Andreas Hofmann

Ah, I remember the word for this thing I'm looking for: A Lookup :P

On 9 Okt., 10:23, Andreas Hofmann [EMAIL PROTECTED]
wrote:
 Hi all,

 i discovered the whole Router-class-definition, but I found no method,
 that matches my needs :)
 Is there any way to get the URL of a defined route for an internal
 cake-controller/action-URL.

 For example I have this route defined:

 Router::connect('/gruppen', array('controller' = 'groups', 'action'
 = 'index'));

 Is there now a way to get this defined URL ('/gruppen') by calling a
 function with the params controller/action, like this:

 Router::theMagicMethodThatMustExist(
   array(
     'controller' = 'groups'
     'action' = 'index'
   )
 ); // Should now return '/gruppen'

 With this I can undock the URLs from the templates/views! Currently
 I'm doing stuff like this in a view:

 $html-link('A Link', '/groups/index');

 But this sucks, because when I define a route for '/groups/index', I
 don't want to change the URL in 1000 view-files and replace '/groups/
 index' with '/gruppen' :S Would be nice if there is a method I'm
 looking for, to always get a defined route-URL, if there is one! :)

 Is there such a method out there??

 Thanks and greetings,

 Andreas!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Getting route-URL for internal controller/action-URL

2008-10-09 Thread Andreas Hofmann

Ah yeah, works!! Cool, thx!

I tried Router::url() before, but with the URl as a string. with an
array of controller/action it works like expected!!

Thanks again!!

On 9 Okt., 10:53, David C. Zentgraf [EMAIL PROTECTED] wrote:
 I believe what you're looking for is $html-url() or, more direct,  
 Router::url().http://api.cakephp.org/class_router.html#a34cdc409ebe46302682fb8c242c...

 Also, you should lookup URLs with an array like
 array('controller' = 'groups', 'action' = 'something')
 instead of /groups/something. Seems more reliable for reverse lookups  
 in my experience.

 On 9 Oct 2008, at 17:23, Andreas Hofmann wrote:



  Hi all,

  i discovered the whole Router-class-definition, but I found no method,
  that matches my needs :)
  Is there any way to get the URL of a defined route for an internal
  cake-controller/action-URL.

  For example I have this route defined:

  Router::connect('/gruppen', array('controller' = 'groups', 'action'
  = 'index'));

  Is there now a way to get this defined URL ('/gruppen') by calling a
  function with the params controller/action, like this:

  Router::theMagicMethodThatMustExist(
   array(
     'controller' = 'groups'
     'action' = 'index'
   )
  ); // Should now return '/gruppen'

  With this I can undock the URLs from the templates/views! Currently
  I'm doing stuff like this in a view:

  $html-link('A Link', '/groups/index');

  But this sucks, because when I define a route for '/groups/index', I
  don't want to change the URL in 1000 view-files and replace '/groups/
  index' with '/gruppen' :S Would be nice if there is a method I'm
  looking for, to always get a defined route-URL, if there is one! :)

  Is there such a method out there??

  Thanks and greetings,

  Andreas!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Related Model returns empty array

2008-09-24 Thread Andreas Hofmann

Hi,

I'm not sure if this is a bug, or I'm just blind... I've developed
some apps in cakePHP already, but I can't find the reason for this
problem.

I have a Gallery and a User Model. When fetching a Gallery, the
User array is empty (It should contain the fields specified in the
belongsTo-Relation).
Here's the gallery model:

class Gallery extends AppModel
{
  public $name = 'Gallery';
  public $primaryKey = 'gallery_id';
  public $hasMany = array(
'Images' = array(
  'className' = 'GalleryImage',
  'foreignKey' = 'gallery_id'
)
  );
  public $belongsTo = array(
'User' = array(
  'className' = 'User',
  'foreignKey' = 'user_id',
  'fields' = array(
'User.user_id',
'User.first_name',
'User.last_name'
  )
)
  );
}

When doing a find():

$this-Gallery-find(
  array(
'Gallery.gallery_id' = $gallery_id
  ),
  array(
'Gallery.gallery_id',
'Gallery.title',
'Gallery.description',
'Gallery.created'
  ),
  array(),
  2
);

The afterFind()-Method in the User-Model contains an empty results-
Array:

array(1) { [0]=  array(1) { [User]=  array(0) { } } }

It seems, that cake build up the array, but had no fields to fetch.
I have the same belongsTo in another model and there it works (=
fetches the fields specified in the belongsTo-Relation). I've
commented out all afterFinds()'s I have in this Model and the other,
but it didn't help.

Does anyone have an idea what this could be? Is it a (known?) bug?

Thanks for your help and greetings,

Andy!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Loading a component with App::import() doesn't work

2008-07-25 Thread Andreas Hofmann

Hi all!

I'm using cake 1.2.0.7296 RC2 and was now rewriting my code.
When I try to import a component aith App::import, it seems not be
loaded/started up:

public function __construct()
{
  parent::__construct();
  App::import('component', 'Auth');
}

Results in:
Undefined property: GameController::$Auth

Even loading it directly in the action method or globally in the App-
Controller doesn't work.
Do you know this problem?

Greetings,

Andreas!

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
CakePHP group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---