Dynamic Controller

2008-06-07 Thread stillboy

I would like to be able to have a single controller that handles other
controllers . Basically I want to be able to 'install' a controller
without modifying any files, so the 'installed' controller and views
would live as text in the database and be called on either via the
handlercontroller/installedcontroller/function/values or directly.

Anyone have any idea how I might go about doing this?

Thank you in advance!

~stillboy

--~--~-~--~~~---~--~~
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: Dynamic Controller

2008-06-07 Thread stillboy

Ok, I think using routes I may be able to accomplish this. Can anyone
tell me what will happen with this route:

Router::connect('/*', array('controller' = 'plugins', 'action' =
'subdispatch'));

From what I understand, then everything will match to that - or should
that line -the /* definitely not happen?

~stillboy

On Jun 7, 7:43 am, stillboy [EMAIL PROTECTED] wrote:
 I would like to be able to have a single controller that handles other
 controllers . Basically I want to be able to 'install' a controller
 without modifying any files, so the 'installed' controller and views
 would live as text in the database and be called on either via the
 handlercontroller/installedcontroller/function/values or directly.

 Anyone have any idea how I might go about doing this?

 Thank you in advance!

 ~stillboy

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Dynamic Controller Actions, or Extended Controller Classes

2007-11-27 Thread Wil Alambre

Hi, I'm looking for some advice on a CakePHP (version 1.1.7)
application our company is developing. The main application is a
general framework (not to be confused with the CakePHP framework
itself) with common JS, CSS, Helpers, Elements, Models, etc. That
application is expanded with Plugins acting as mini-apps that use the
common application/framework elements, but add specific functionality.
The entire application (with Plugins) will be pushed out to for local
installations, but we will be continuing to expand and update it
(providing files and SQL that those local installations can download
and replace).

We fully expect each installation to customize the application to fit
their needs, and we've coded it to as easily accommodate this as
possible. It's multilingual, with text coming from a datatable.
Specific datatables (used by the Plugins) can have fields added and/or
removed. A Component and Helper set is dynamically generating HTML
forms based on datatable information (type of field, options in
pulldowns, etc). Validation rules for each model come from a
datatable. Etc. We've tried as much as possible to allow the local IT
admins to customize the application and/or plugins as they need
through SQL.

However, we *are* expecting them to need to add or change code. We
expect at least some of them will need to add or change Actions within
the Plugins' Controllers. We'd like to give them the option to do so,
but still allow us to provide a general update (provide a download of
the original, standard application and plugins) that will *not*
overwrite their changes. The catch is that they should *not* have to
open or change ANY file or code we provide them.

Our *preferred* solution, which doesn't seem possible in PHP, is a
folder structure like this:

controller/
...foo_controller.php
...foo_standard/
..add.php
..edit.php
..delete.php
..index.php
...foo_custom/
..add.php
..copy.php

And a Controller something like this:

?php
class FooController extends AppController {

// parse through foo_custom folder IF IT EXISTS and include all
files dynamically
// parse through foo_standard folder and include all files
dynamically UNLESS that file name was loaded from foo_custom

}
?

And with each file within foo_custom and foo_standard looking like
this:

?php
function index( $var1, $var2 ) {

// do some Action here

}
?

The idea being we would provide the nearly empty Controller and all
the Actions (functions) in the foo_standard folder, and the local IT
admins can *add* functions/actions or *replace* by populating the
optional foo_custom folder. We can then, at some future date, push
any updates we want, replacing the standard functionality and leaving
their custom functionality intact (short of major revisions, of
course).

It's my understanding that the above is not possible; PHP cannot
dynamically include/require Functions into a Class like I described
above. If I am *mistaken*, and there *is* a PHP way to do the above
(or similar), please let me know!

We've come up with an alternate solution, however. The file structure
looks like this:

controller/
...foo_controller.php
...extensions/
..foo_controller_extension.php

With the foo_controller.php looking normal and the
foo_controller_extension.php file looking like this:

?php
class FooControllerExtension extends FooController {

function add() {
// do something...
}

function copy() {
// do something...
}
?

It required some additions to the base CakePHP files, but the result
is that for any Plugin, CakePHP looks for an optional Controller
Extension and loads it after loading the called Controller. Any new
functions in the Extension gets inherited by the parent Controller,
and and functions provided in the Extension *override* the parent's
function (so the Extension's add function would be run instead of
the Controller's add function).

We've tested Method #2, and it works fine, but we would prefer Method
#1, or some variation of it. And which ever method we decide on would
be used for other CakePHP files (Components, Helpers, Models, etc) to
allow for customization there.

Can anyone provide any advice on this topic, or suggestions? We want
to throw this out there looking for better ways before we commit to
something :)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups Cake 
PHP 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
-~--~~~~--~~--~--~---