How to dynamically load controller based on field in database.

2008-11-13 Thread Nick

Basically I am using wildflower cms which is built on cakephp.
It routes are setup so that / goes to the pages controller.
I am building a product catalog and could simply have the urls be /
products/category/product-name
however I do not want to prepend the controller name in this scenario.
Right now I have it so that the product controller from the admin side
will insert rows into the pages table as products are created in the
products table.  Also I created a field in the pages table called
controller. By default it is blank however what I want to do is if
it isn't blank and for example has Products in it then I want to
load the Products controller from within the Pages controller so that
it can handle pulling the product images, pricing, etc...

I want the controller to be dynamically called.
Url structure example desired:

/shirts/mens/rockstar-shirt/-   goes to pages controller sees that
the controller field has Product and loads product through Product
Controller
/about-us/  -   goes to pages controller
and has blank controller field, page rendered as normal

Im new to cake but like it so far.  Also does anyone know of a good
cake cms, wildflower is slow running as localhost.

--~--~-~--~~~---~--~~
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: How to dynamically load controller based on field in database.

2008-11-13 Thread [EMAIL PROTECTED]

Hi Nick,
I think you may be going about this in an akward way.
You are making a product catalog but using the pages feature of
Wildflower for displaying products.
I suggest you put your products separate from normal pages. Let the
ProductsController handle the products.

You should try to see the controllers as the signposts, Airport
control-tower... they direct trafic and should try to keep to doing
two tings. Deciding what data should be accessed and which view to
display. For example, when you ask how to load the ProductsController
fron within the PagesController you should be looking for the solution
in the Model and the View domains instead. If you want to load product
data you need the Product Model, not the ProductsController.

Possibly:

if ( !empty($data['Page']['modelname']) ) {
App::import('Model', $data['Page']['modelname'] );

$model = new $data['Page']['modelname'];

//or maybe you have to make it a variable first, I forget.
//$model_name = $data['Page']['modelname'];
//$model = new $model_name;

$more_data = $model-getStuffForPageView();
}

(just example code I wrote here in the browser... no error checking,
may have mistakes... the usual disclaimers)


/Martin

On Nov 13, 6:53 am, Nick [EMAIL PROTECTED] wrote:
 Basically I am using wildflower cms which is built on cakephp.
 It routes are setup so that / goes to the pages controller.
 I am building a product catalog and could simply have the urls be /
 products/category/product-name
 however I do not want to prepend the controller name in this scenario.
 Right now I have it so that the product controller from the admin side
 will insert rows into the pages table as products are created in the
 products table.  Also I created a field in the pages table called
 controller. By default it is blank however what I want to do is if
 it isn't blank and for example has Products in it then I want to
 load the Products controller from within the Pages controller so that
 it can handle pulling the product images, pricing, etc...

 I want the controller to be dynamically called.
 Url structure example desired:

 /shirts/mens/rockstar-shirt/    -   goes to pages controller sees that
 the controller field has Product and loads product through Product
 Controller
 /about-us/                              -   goes to pages controller
 and has blank controller field, page rendered as normal

 Im new to cake but like it so far.  Also does anyone know of a good
 cake cms, wildflower is slow running as localhost.
--~--~-~--~~~---~--~~
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: How to dynamically load controller based on field in database.

2008-11-13 Thread Rafael Bandeira aka rafaelbandeira3



On 13 nov, 03:53, Nick [EMAIL PROTECTED] wrote:
 Basically I am using wildflower cms which is built on cakephp.
 It routes are setup so that / goes to the pages controller.
 I am building a product catalog and could simply have the urls be /
 products/category/product-name
 however I do not want to prepend the controller name in this scenario.
 Right now I have it so that the product controller from the admin side
 will insert rows into the pages table as products are created in the
 products table.  Also I created a field in the pages table called
 controller. By default it is blank however what I want to do is if
 it isn't blank and for example has Products in it then I want to
 load the Products controller from within the Pages controller so that
 it can handle pulling the product images, pricing, etc...

 I want the controller to be dynamically called.

That's a terrible idea, would cost you so much in performance,
maitainability and logic.
I think you should re-think your design principles, trying to keep it
a little more simple and tided to a rule.
Maybe moving some logic to the model side - Fat Model, Skinny
Controller - you could dynamically load a Model class,
wich would make much more sense and would be much lighter. You'd only
have to create a pattern for your models so that they
could be easily used by the same controller - like an interface.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---