0

私はモデルWikiPageを持っています。WikiPage->データベースから取得したテキスト。メソッド「wikify」を作成し、class::wikify($Page->getText()) でページ上にテキストを生成しました。テキスト I have construction [リンク名] では、次のリンクを生成します。

$text = preg_replace('@\[(.*) (.*)\]@', '<a href="\\1" class="<?php Wiki::httpresponse($\\1) ?>">\\2</a>', $text);

アイデアは、関数 httpresponse で URL をチェックし、ページがない場合はクラスを変更することです。

http応答:

static public function httpresponse($url){
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_NOBODY, true);
    curl_setopt($ch, CURLOPT_FAILONERROR, true); 
    curl_exec ($ch); 
    $intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    curl_close ($ch); 
    if ($intReturnCode != 200 && $intReturnCode != 302 && $intReturnCode != 304) { return "red"; } else return "blue";
}

2 つの問題:

  1. localhost ページで httpresponce をテストすると、それらが見つかりません。Web ページでテストすると、すべて問題ありません。

    (次のようなチェックされたリンクhttp://localhost:8080/category/page、カテゴリは最初のモジュール、ページはisecond、ホームページはモジュール:カテゴリ、アクション:インデックス、カテゴリ/ページはモジュールのルート:ページ、アクション:表示)

  2. 生成されたリンクのクラスは、<?php Wiki::httpresponse($\\1) ?>メソッド httpresponce が実行されていないままです。

何ができるでしょうか?たぶん、このタスクを実行するためのより良い方法がありますか?

4

1 に答える 1

0

解決策を見つけました。

$reg_inURL = "@\[(\w*)\/(\w*) (.*)\]\]@";
   preg_match_all($reg_inURL, $text, $matches);
   $count = 0;
   $links = count($matches[0]);
   foreach ($matches[0] as $pattern)
   {
    $cat = $matches[1][$count];
    $pag = $matches[2][$count];

    $q = WikiPageQuery::create()
        ->leftJoin('WikiPage.WikiCategory')
        ->where('WikiCategory.category_address = ?', $cat)
        ->filterByAddress($pag)
        ->findOne();
    if (!$q)
    {
        $link_class = 'red';
        $url = $cat.'/add';
    }
    else 
    {
        $link_class = 'blue';
        $url = $cat.'/'.$pag;
    }

    $title = $matches[3][$count];
    $text = str_replace  ($pattern, '<a href='.$url.' class='.$link_class.'>'.$title.'</a>', $text);
    $count = $count+1;
   }
于 2013-02-25T05:24:01.417 に答える