Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 维基风格的链接。如果目标页面没有';不存在_Php_Symfony1_Symfony 1.4_Propel - Fatal编程技术网

Php 维基风格的链接。如果目标页面没有';不存在

Php 维基风格的链接。如果目标页面没有';不存在,php,symfony1,symfony-1.4,propel,Php,Symfony1,Symfony 1.4,Propel,我有一个模型页面。WikiPage->我从数据库中获取的文本。我创建了方法“wikify”,并按class::wikify($page->getText())在页面上生成文本。 在文本中,我有构造[link name],我用以下内容生成链接: $text = preg_replace('@\[(.*) (.*)\]@', '<a href="\\1" class="<?php Wiki::httpresponse($\\1) ?>">

我有一个模型页面。WikiPage->我从数据库中获取的文本。我创建了方法“wikify”,并按class::wikify($page->getText())在页面上生成文本。 在文本中,我有构造[link name],我用以下内容生成链接:

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

  • 当我在本地主机页面上测试HttpESPONE时,它找不到它们;当我在网页上测试HttpESPONE时,一切正常

    (选中链接,如
    http://localhost:8080/category/page
    ,类别是第一个模块,页面是第二个模块,主页是模块:类别,操作:索引,类别/页面是模块的路径:页面,操作:显示)

  • 生成的链接的类仍然保留
    方法HttpResponse未执行

  • 可以做些什么? 也许有更好的方法来完成这项任务?

    找到了解决方案

    $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;
       }
    
    $reg\u inURL=“@\[(\w*)\/(\w*)(.*)\]\]@”;
    preg_match_all($reg_inURL,$text,$matches);
    $count=0;
    $links=count($matches[0]);
    foreach($matches[0]为$pattern)
    {
    $cat=$matches[1][$count];
    $pag=$matches[2][$count];
    $q=WikiPageQuery::create()
    ->leftJoin('WikiPage.WikiCategory')
    ->其中('WikiCategory.category_address=?',$cat)
    ->filterByAddress($pag)
    ->芬顿();
    如果(!$q)
    {
    $link_class='red';
    $url=$cat.'/add';
    }
    其他的
    {
    $link_class='blue';
    $url=$cat.'/'.$pag;
    }
    $title=$matches[3][$count];
    $text=str_replace($pattern,,$text);
    $count=$count+1;
    }
    
    $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;
       }