1

I am creating a more robust find and replace plugin which shows what is being replaced and where. I need to query for all entries(or content records?) where content is like '%findme%'.

Should I query for entries or should I query for content records for this find and replace?

I saw that there is an EntryRecord, so I can give it CDBCriteria object to find but there is no ContentRecord so how do I get the content with the string in it?

This is all I have so far.

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->limit = $model->limit;
$relaventContent = ContentService::model()->findAll($criteria);
1

It's up to you what you prefer to use. Usually people use the ElementCriteriaModel. You could achieve your goal with the record itself too but it requires more code.

The ElementCriteriaModel provides more ready-to-use options and returns populated entries, Records provide only records, so no populated entries with all relations and such

I'm not sure what that $model->limit is supposed to do, maybe this is a setting in your globals, but you would normally search for entries that contains something (you can find the rules here) with this code

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->search = 'yourKeyWord';
$relaventContent = $criteria->find();

If you just want to have all entries you would do

$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->limit = null;
$relaventContent = $criteria->find();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.