Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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 模块化Yii组件/动作_Php_Yii_Modularity - Fatal编程技术网

Php 模块化Yii组件/动作

Php 模块化Yii组件/动作,php,yii,modularity,Php,Yii,Modularity,我正在使用Yii框架,对于我们的站点,我们希望使其更加模块化。这对我们来说意味着,我们希望将一些组件的逻辑分离到它们自己的组件/应用程序文件夹中 目前我正在做的是用我自己的类扩展每个控制器类上的CController e、 g 在MyController中,我将通过actions()方法加载组件: 在Auth组件中,我有一个run()方法: 它将运行Auth组件中的操作方法。我还应该提到,我的Auth组件并没有扩展CWidget,而是扩展了CAction 在Auth中,我有我的方法:action

我正在使用Yii框架,对于我们的站点,我们希望使其更加模块化。这对我们来说意味着,我们希望将一些组件的逻辑分离到它们自己的组件/应用程序文件夹中

目前我正在做的是用我自己的类扩展每个控制器类上的CController

e、 g

在MyController中,我将通过actions()方法加载组件:

在Auth组件中,我有一个run()方法:

它将运行Auth组件中的操作方法。我还应该提到,我的Auth组件并没有扩展CWidget,而是扩展了CAction

在Auth中,我有我的方法:actionLogin()和actionLogout()来匹配MyController中的上述操作

当我尝试渲染我希望保留在模块化组件中的视图文件时,它不会识别组件文件夹中是否有视图文件,而是查看默认视图或主题文件夹

我已尝试从受保护的根目录“//application/components/auth/login”加载密码

注: 我尝试这样做的总体目标是,让我能够在URL结构不变的情况下创建网站的多个模块化部分/应用程序/组件,并根据我如何设置actions方法数组,加载该URL的特定组件。我可能在站点上有两种形式的身份验证,或者未来的组件可能是根据我在actions数组中的内容加载周计划和月计划组件


我已经调查了模块,但我发现URL不会保持一致。我欢迎任何关于这方面的建议。多谢各位

首先,在组件中创建一个函数,列出本地操作处理程序

public static function actions(){
    return array(
        // name action and point to the location where the action class is
        'GetActivity'       =>'application.components.Auth.login',
        'GetActivitytype'   =>'application.components.Auth.logout',
    );
}
并按如下方式加载您的视图:-

return $this->renderPartial('application.components.views.auth_login',
                             array('model'    => $userModel),
                             true
                           );
public function run() {
//  Get the action string from the URL
    $uri = (Yii::app()->getRequest()->getRequestUri());
    $method = 'action'.ucfirst(substr($uri,strrpos($uri,'/')+1));

//  Run the method from the URI
    $this->$method();
}
public static function actions(){
    return array(
        // name action and point to the location where the action class is
        'GetActivity'       =>'application.components.Auth.login',
        'GetActivitytype'   =>'application.components.Auth.logout',
    );
}
return $this->renderPartial('application.components.views.auth_login',
                             array('model'    => $userModel),
                             true
                           );