2

我在 yii 框架中工作。我陷入了必须从核心 php 文件调用 yii 框架中的控制器内部函数的地步。实际上我要创建 html 快照。

我的文件夹结构是

seoPravin--
--protected
  --modules
    --kp
      --Dnycontentcategoriescontroller.php
      --DnycontentvisitstatController.php
--themes
--start.php (This is my customized file)
--index.php

1) start.php 文件的代码:--

<!DOCTYPE HTML>
     <html>
     <head>
        <?php 
        if (!empty($_REQUEST['_escaped_fragment_']))    
        { 
            $yii=dirname(__FILE__).'/yii_1.8/framework/yii.php';
            require_once($yii);
            $escapeFragment=$_REQUEST['_escaped_fragment_'];
            $arr=explode('/',$escapeFragment);
            include 'protected/components/Controller.php';
            include 'protected/modules/'.$arr[0].'/controllers/'.$arr[1].'Controller.php';

            echo DnycontentcategoriesController::actiongetDnyContent();  //gettting error at this point

            ?>
            </head>
            <body>
                <?php 
                    //echo "<br> ".$obj->actiongetDnyContent();
        }
                ?>
            </body>
    </html>             

2) yii 端控制器功能:此功能正常工作,但当我调用using escaped_fragment它时会出错

public static function actiongetDnyContent()
    {

        if (!empty($_REQUEST['_escaped_fragment_']))//code inside if statement not working
        {
            $escapedFragment=$_REQUEST['_escaped_fragment_'];
            $arr=explode('/',$escapedFragment);
            $contentTitleId=end($arr);
            $model = new Dnycontentvisitstat();  //Error got at this line
        }
        else  //Below code is working properly  
        {
            $dependency = new CDbCacheDependency('SELECT MAX(createDateTime) FROM dnycontent');
            $content = new Dnycontent();
            $content->contentTitleId = $_GET['contentTitleId'];
            $content = $content->cache(2592000,$dependency)->getContent();
            $userId=105;
            $ipAddress=Yii::app()->request->userHostAddress;
            echo "{\"contents\":[".CJSON::encode($content)."]} ";
            $model = new Dnycontentvisitstat();
            $model->save($_GET['contentTitleId'], $userId, $ipAddress);
        }   
    }

错误:

致命错误:第 289 行的 C:\wamp\www\seoPravin\protected\modules\KnowledgePortal\controllers\DnycontentcategoriesController.php 中找不到类“Dnycontentvisitstat”

代码适用于普通网址,但不适用于 _esaped_fragment

4

1 回答 1

-1

这是一个非常糟糕的做法,但您可以执行 HTTP 自我请求,如下所示:

include("http://{$_SERVER['HTTP_HOST']}/path/?r=controller/action&_param={$_GET['param']}");

检查http://www.php.net/manual/en/function.include.php以了解如何启用 HTTP 包含。

于 2013-12-27T12:31:07.797 回答