开发者

Symfony helpers and database

开发者 https://www.devze.com 2023-03-03 01:21 出处:网络
I use symfony 1.4.11 with doctrine. I have helper: function filterwords($text){ $filterWords=array (\'some\',\'filter\',\'words\');

I use symfony 1.4.11 with doctrine. I have helper:

function filterwords($text){

    $filterWords=array ('some','filter','words');
     $filterCount = sizeof($filterWords);
        for($i=0; $i<$filterCount; $i++){
        $text = preg_replace('/\b'.$filterWords[$i].'\b/ie',"str_repeat('*',strlen('$0'))",$text);
                                         }
        return $text;
                               }
    }

All works fine. But I want to make module, that administrator can add words to filter from backend. Is 开发者_如何转开发it possible to transfer data from the database to varaible $filterWords I have next schema:

Filter:
  actAs:
    Timestampable: ~
  connection: doctrine
  tableName: filter
  columns:
    word: {type: string(255), notnull: true}

I can make in helper something like this, and get word what I need :

 $record = Doctrine_Core::getTable('Filter')->getWordFilter();

 foreach ($record as $filter )

   {
 echo  $filter ->getWord();
    }

But I do not how to implement it im my function...

Sorry for my bad English.


Just pass $filterwords in as a variable:

function filterwords($text, $filterwords)
{
   //etc.


field = the column name that contains a value you're searching by.

$record = Doctrine_Core::getTable('Words')->findOneByField($value);
$filterWords = $record->getWord();


I do not now is it correct, but it is work.

 function filterwords($text){
  $record = Doctrine_Core::getTable('Filter')->getWordFilter();//

   foreach ($record as $filter )
   {
        $filterWords[] =  $filter->getWord();
    }
         $filterCount = sizeof($filterWords);
        for($i=0; $i<$filterCount; $i++){
        $text = preg_replace('/\b'.$filterWords[$i].'\b/ie',"str_repeat('*',strlen('$0'))",$text);
                                         }
        return $text;
                               }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号