如何从核心php文件中调用yii框架控制器内的函数?

时间:2013-09-10 07:47:01

标签: php yii yii-components

我在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);
        }   
    }

错误:

  

致命错误:未找到“Dnycontentvisitstat”类   C:\瓦帕\ WWW \ seoPravin \保护\模块\ KnowledgePortal \控制器\ DnycontentcategoriesController.php   在第289行

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

1 个答案:

答案 0 :(得分:-1)

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

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

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