新手,请教一个import的问题

十分不好意思,对php了解不深刻,总是有些很肤浅的问题。

我现在在文件夹/protected/models/ActiveRecord/下有一个UserInfo.php文件。如下:

class user_log_info extends CActiveRecord

{

    public static function model($className=CLASS)

    {

        return parent::model($className);

    }

}

在SiteController.php文件中这样写:

Yii::import('application.models.ActiveRecord.UserInfo');

class SiteController extends CController

{

    //private $smarty;

    public function actionIndex()

    {

        $info=new user_log_info;

        $info->user_name='quxianping';

        $info->last_url='xxxxx';

        $info->last_log_time='2008-10-10 23:59:59';

        $info->save();

    }

}

为什么会返回这样的错误呢?十分感谢!

YiiBase::include(user_log_info.php) [<a href='function.YiiBase-include'>function.YiiBase-include</a>]: failed to open stream: No such file or directory

如果你要用Yii::import()来引入一个类的定义,那么类名必须和文件名一样。

Quote

如果你要用Yii::import()来引入一个类的定义,那么类名必须和文件名一样。

恩,十分感谢!那假如需要文件名与类名不同的话,应该用什么方式取代Yii::import()呢?我看到prado中是用using(),不知道yii中是什么哦?文档里我也没找到。麻烦之处请见谅…

加上true参数强制include:

Yii::import('path.to.filename', true)

Quote

加上true参数强制include:

Yii::import('path.to.filename', true)

恩,十分感谢,搞定了!

我还想问一个问题,不知道这个问题是不是很弱,而且我也不懂是不是关于Yii的问题,可是我研究了一个小时也不太明白。

我现在的设计是这样的,前端用smarty,后端用Yii。

现在我不太明白在html文件中<a herf="…">xxx</a>,这一般应该使用怎样的格式?不是太明白Yii的格式是怎样的,这个该使用Yii的格式呢?还是smarty的格式呢?

下面是php中的简单代码:

$smarty = Yii::app()->smarty;

$smarty->assign("user_name",'quxianping');

$smarty->display("index.html");

在index.html链接向其它php页面时我就不知道该怎样做了。

比如要链接到/protected/controllers/UserInfo.php,我应该如何写<a>标签呢?

html文件是smarty模板?如果这样你恐怕用不成yii的函数, 而只能用smarty的格式了。

Quote

html文件是smarty模板?如果这样你恐怕用不成yii的函数, 而只能用smarty的格式了。

恩,好的,感谢qiang的指点^_^

Quote

html文件是smarty模板?如果这样你恐怕用不成yii的函数, 而只能用smarty的格式了。

To qiang:

想分享一下经验,我是新手也不了解说的对不对俄。我下午试验了一下,在smarty模版文件(目前只试了一下<a>标签)中使用Yii的方式也是可以使用的。比如我在/protected/controllers文件夹下有一个文件NewsController.php,代码如下:

    11 class NewsController extends CController

    12 {

    13    public function actionIndex()

    14    {

    15        $smarty = Yii::app()->smarty;

    17        $smarty->display("page1.html");

    18    }

    19 }

然后我在smaty调用的模板文件index.html文件中这样写:   

15      <a href="index.php?r=news/index">news</a>

然后运行时,点击news也是完全可以链接过来的。

我不太了解smarty使用的格式是什么,不过我看到Yii的格式在smarty模板文件中同样也可以使用,还是挺开心的。多谢qiang!

你这个是普通的HTML代码了,应该是没问题的。我以为你是问能否用PHP表达式呢。

Quote

你这个是普通的HTML代码了,应该是没问题的。我以为你是问能否用PHP表达式呢。

哦,我这儿初学,问题都比较傻,呵呵…