Friday, January 29, 2010

scraping / preg_match_all / ->beginner in cakephp

Hi all.
I'm totally newbie to CakePhp.

I have a problem with some preg_math_all function. Let me explain you.

This is what I want to do :

I'm doing a kind of personnal bookmark "software". Something very
easy.
But I can't achieve it. Too bad.

I want to manage my bookmarks by category.

This is how I'd explain : "A category hasMany bookmarks".

A bookmark is composed of a url, a "created" field, a title.

So here's my 1st problem. I do not encounter a bug or anything. I just
don't know how to "say" that in Cakephp language.

I want a field in which I can "paste" some urls, and it "recognizes
it" and add it to the database. It's a way of importing a lot of
bookmarks at a time.

In procedural PHP, I would have no pb to do that. But I try to take
resolutions for this new year : doing some CLEAR code that's why I
started with cake php.

So in procedural, I would have done something like this :

1. explode the $_POST field using "\r\n".
2. for each line in the array, explode it again with ";"
3. for each line, create a MySQL query using the correct cells, and
bulk import it into the database.
4. et voilà !

But here, what must I do ? I thought about creating a function import
() in my controller.
But then ? how to tell cakephp : bulk import it into the database ?


My 2nd problem : how can I "count" how many bookmarks there are in my
category ?
I tried this but it doesn't work. When I debug $nbBookmarks, it's not
giving me the right figure.

class CategoriesController extends AppController {

var $name = 'Categories';
var $hasMany = 'Bookmark';

function index() {
$this->set('Categories', $this->Category->find('all'));
}

function view($id = null) {
$this->Category->id = $id;
$this->set('Category', $this->Category->read());

$q = $this->Category->find('first',array( 'conditions' => array
('Category.id'=>$id) ));
$this->set('Bookmarks',$q);

$nbBookmarks = $this->Category->find('count', array('conditions' =>
array('Category.id' => $id)));
$this->set('nbBookmarks',$nbBookmarks);
}

Sorry for my bad english mates, I'm french.

Thanks again for your help people !

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: