Sunday, October 31, 2010

New to MVC

Hi,

i'm a Python developer, and have worked on small PHP projects. A few
months ago i've started looking at the MVC model, and have used
CakePHP for some simple database applications (AddressBook and a
stupid "crawler").

Now i'm working to an application that uses both Facebook, Youtube and
Bit.ly APIs. I've read your documentation about the "vendors"
directory, but am still confused, so i'm asking for help in this
mailing list. I'll really appreciate any type of help. Thanks. Now let
me explain:

In my old application I have the bit.ly library that has 2 main
functions: just_shorten_url and shorten_url. The first function
creates a short URL and saves it in the db (with an indipendent mysql
connection) and the first one just creates and print a short url,
given the long one. In that application i simply include_once the
library file and then use that functions.

With cakephp, if i'm right, using just_shorten_url is not so
difficult: just create a view with the form where you can insert the
long one and a controller where, with my library, the short url gets
created. Now, what about printing the created url to the user's
screen? I know I can create a new view where the controller will POST
data to display, but maybe there is a cleaner way to do this (direct
output from the controller?). Can you help me?

Using shorten_url (the function that also writes to the db) is more
difficult: yes, of course i can use it as just_shorten_url and work on
the database "manually" (the library creates a connection and executes
queries), but, as i'm using such a powerful framework, why not to use
it also here? I think the best way to do that is completely remove
database connections and queries from my library and put everything in
the controller. The controller gets the long url, with shorten_url
creates a short one then puts it into the DB.

Well, at this point there is the last problem. At this point i will
have 2 controllers: one, that creates and output a short url and
another one, that creates a short url, output it and adds it to the
DB. So i have almost the same code 2 times in my app. How can i make
controllers interacting between them? I mean: a controller that
creates and output the short url that, if needed saves it on the db.

Thanks so much.

Giorgio

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: