[CakePHP] : Why don't we take a chat to solve it ?

First of all, it’s for you who take a lot of time with CakePHP Framework as your main framework to create a web based application. Readers, commonly i’ve a problem about extending a class in file app/config/database.php. I have a single element and want to access a database directly from my element (without any help of controller, component, helper, or model). I used to put some “ordinary” database connection script in my element. However, when i change my database configuration, i’ve to change 2 files simultaneously. So that, i want to extend the DATABASE_CONFIG in app/config/database.php file. How can I do that ? Check this chat out ….

macsuntzu: hello …
macsuntzu: i am sunu from indonesia ..
macsuntzu: i am 22, male, from indonesia
macsuntzu: i am having a problem with extending DATABASE_CONFIG class
macsuntzu: in CakePHP

macsuntzu: i am recently searching it by Google, return noting
macsuntzu: return nothing
macsuntzu: i am trying to use var $default in my element
macsuntzu: without making model and controller ..
macsuntzu may somebody help me ?
kalileo: macsuntzu: i do not understand what you are trying to do
kalileo: please explain
macsuntzu: emm…
macsuntzu: okay ..
macsuntzu: we know that we should put our database configuration in app/config/database.php right ?
macsuntzu: i create a single element to render up some data in my database..
macsuntzu: i didn’t use any model or controller for that element ..
macsuntzu: so i put database connection variable in my element
macsuntzu: such as $host = ‘localhost’ ;or $db_user = ‘sunu'; etc
macsuntzu: however .., i want to take it from class DATABASE_CONFIG in app/config/database.php
kalileo: element?
macsuntzu: may i extends that class in my element ?
macsuntzu: yup
kalileo: you mean elements as used in layouts and view?
macsuntzu: a piece of view file ..
macsuntzu: yup
macsuntzu: yes that’s right sir ..
kalileo: you want to access th adatabase directly from your elemnt?
macsuntzu: yes,
macsuntzu: can i do it ?
macsuntzu: or i just simply put some connection variable…… like i’ve just explained before ?
kalileo: macsuntzu: is there any reason why you do not want to use a usual model / controller to access your data?
kalileo: macsuntzu: if you can’t set your data to be used bu the element in your controller/action, you could still use requestAction() in your element to pull in any data
macsuntzu: emm ..
macsuntzu: okay kalileo ..
macsuntzu: i’ll read more manual or API file again by now
macsuntzu: thanks for your suggestion :)
SupaPhreak: macsuntzu http://bakery.cakephp.org/articles/view/creating-reusable-elements-with-requestaction
macsuntzu: thanks SupaPhreak..
cornernote: hi
kalileo: thanks, SupaPhreak ! However macsuntzu you might not even need requestAction if you can set your data in your controller. A controller can use different models …
macsuntzu: yes ..
cornernote: i used requestaction once to do currency conversions.. thought it would be a good way to do it…
cornernote: note to self, dont use 100 requestactions on 1 page :)
macsuntzu: i am reading the article
macsuntzu: heheh..
macsuntzu: yeap ..
cornernote: i built a controller+helper.. much better solution
cornernote: *component+helper
cornernote: thats 1 thing i dont like, if you want the same logic in controller+view, you need a component and a helper
cornernote: with very similar code
macsuntzu: before it ..
cornernote: and because the helper doesnt connect to the db, you need to pass a bunch of data to it
macsuntzu: usually i use component also
macsuntzu: and i add var $components in the controller
macsuntzu: using helper is a nice way too , i think
macsuntzu: thanks cornernote
cornernote: didnt really know i was helping .. but no problems.. :)
cornernote: i was more just making discussion
cornernote: having a whinge, etc

EOF. I hope you can understand what i’ve just talked about. If you turn to be bored with your problems in CakePHP, just feel free to take a chat with some bakers at :

irc.freenode.net (channel : #cakephp)

Gracias !

Be Sociable, Share!
Categories: CakePHP, Iseng

Leave a Reply