Php 如何访问控制器中的操作
我有一个名为Php 如何访问控制器中的操作,php,yii,scope,yii-routing,Php,Yii,Scope,Yii Routing,我有一个名为SiteController的默认控制器,其中包含一些操作,如: -index -aboutcompany 当我在浏览器中打开我的站点时,比如:localhost/lucky 索引操作工作正常 在index.php(view)上我做了一个链接:echochtml::link('About Company',array('site/aboutcompany)) 当我单击链接时,出现一个错误: The requested url not found on this server. 除
SiteController
的默认控制器,其中包含一些操作,如:
-index
-aboutcompany
当我在浏览器中打开我的站点时,比如:localhost/lucky
索引
操作工作正常
在index.php(view)上我做了一个链接:echochtml::link('About Company',array('site/aboutcompany))代码>
当我单击链接时,出现一个错误:
The requested url not found on this server.
除索引外,所有操作(sitecontroller)均无效
请给我建议解决办法
这是控制器代码:
<?php
class SiteController extends Controller
{
public $layout='/layouts/main';
public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
'page'=>array(
'class'=>'CViewAction',
),
);
}
public function actionIndex()
{
$this->render('index');
}
public function actionAboutCompany(){
$this->render('aboutcompany');
}
您有任何htaccess吗??我是说在#上使用任何?是的,这是我的.htaccessOptions+FollowSymLinks IndexIgnore*/*RewriteEngine的内容。如果存在目录或文件,请直接使用它RewriteCond%{REQUEST_FILENAME}-f RewriteCond%{REQUEST_FILENAME}-d#否则将其转发到index.php RewriteRule。index.php
htaccess是gud.and hidden index.php??如果可以,也显示ur config main.php和SiteController.:)<代码>?php类SiteController扩展控制器{public$layout='/layouts/main';公共函数actions(){return array('captcha'=>array('class'=>'CCaptchaAction','backColor'=>0xffff,),'page'=>array('class'=>'CViewAction',);}公共函数actionIndex(){$this->render('index');}公共函数actionAboutCompany(){$this->render('aboutcompany');}
config文件,请更新问题中的代码,不要发表评论。
return array(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Web Application',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'test',
'ipFilters'=>array('127.0.0.1','::1'),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'<controller:\w+>'=>'<controller>/list',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'<controller:\w+>/<id:\d+>/<title>'=>'<controller>/view',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
),
),
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=testyii',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
array(
'class'=>'CWebLogRoute',
),
),
),
),
'params'=>array(
'adminEmail'=>'webmaster@example.com',
),
);