Sunday, October 31, 2010

Re: New to MVC

Thankyou Cricket for your kind reply! I'll try to give more details about the part of my application i'm trying to rewrite with cakephp.

1 - In a form, an user inserts a youtube link and click on submit
2 - My application handles the input and
2.1 - Gets, from youtube api, details of that video and stores them in a db (get_video_details() + a connection to the DB to store data)
2.2 - Creates a short url and saves it into the db (shorten_url() + a connection to the db to store data)
3 - Outputs a confirmation page with the video embedded in it

As you can see, this is very simple. I just need to understand where i have to put those "workers", those functions.

With Cake, one usually wouldn't echo back a simple string unless it
was an AJAX request, in which case you'd use an AJAX layout, which
simply echoes your value (no html, head, body, etc.) and, possibly, an
AJAX view. But that's not a hard and fast rule (I cheat sometimes and
simply echo).

Yeah right i was saying echo to make things simplier for you, of course i'm using an HTML output in the view.
 

However (and this really depends on what you're trying to do), I think
it'd be simplest to create a component that created the URL. What's
your use case? I mean, would it make sense to provide the URL to be
shortened within some other controller's form? If that were the case,
you could load the component in that controller, pass off the
submitted URL to it, and receive back the shortened version, which
you'd then save with your other data. Unless the only point is to
submit a single URL, and it's not part of some other model's data. If
that's the case, maybe a controller is the correct way forward. But
you wouldn't need 2 controllers. Just create actions for each ...
action you want to provide.

Do you confirm that a component is a library in the Vendors directory? And, sorry, i was using the wrong words in the first post. I didn't want to create a controller to substitute my 2 functions (shorten_url and just_shorten_url), but 2 actions. Right now, the shorten_url function calls just_shorten_url, gets the shortened url and puts them in the db. I have a basic function, that makes api calls and returns a shorten url and another function that uses this basic functions and does more things on its output. Can i have something like this with actions?
 

Googling "cakephp bit.ly" shows there are a few existing components
and at least one helper out there. Perhaps you should take a look at
how those were created for ideas (or just use one of them).

That's really interesting, i'll have a look.
 
Thankyou again!

Giorgio
 



--
--
AnotherNetFellow
Email: anothernetfellow@gmail.com

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: