【发布时间】:2016-05-11 22:16:34
【问题描述】:
我有一个使用简单方法的控制器:
<?php
class SiteController extends CController
{
/**
* Declares class-based actions.
*/
public function actionIndex()
{
echo 'Zostala wywołana akcja Index';
}
public function actionPokaz()
{
echo 'Zostala wywołana akcja Pokaz';
}
}
现在当我去: http://localhost/yii/test/site 它应该运行一个 actionIndex 方法,但是我得到“找不到对象”信息。这是为什么呢?
更重要的是,我正在按照我正在阅读的书(今天才开始)做所有事情,书上说它应该有效,但它没有。我的项目文件夹当然是 yii/test,位于 XAMPP htdocs。
错误如下:
Nie znaleziono obiektu! (Object not found!)
Nie znaleziono żądanego URL-a na tym serwerze. Odnośnik na referującej stronie wydaje się być nieprawidłowy lub nieaktualny. Poinformuj autora tej strony o problemie. (Desired URL was not found on this server ...)
Jeśli myślisz, że jest to błąd tego serwera, skontaktuj się z administratorem.
Error 404
localhost
Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.6.15
这是波兰语。但是我把翻译放在括号里。
我的 main.php:
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
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(
// uncomment the following to enable the Gii tool
/*
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'Enter Your Password Here',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
),
*/
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
// uncomment the following to enable URLs in path-format
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'site/policz/<liczba1:\d+>/<liczba2:\d+>'=>'site/policz/',
),
),
// database settings are configured in database.php
'db'=>require(dirname(__FILE__).'/database.php'),
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>YII_DEBUG ? null : 'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*
array(
'class'=>'CWebLogRoute',
),
*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'webmaster@example.com',
),
);
【问题讨论】:
-
@MindRoller,你能粘贴整个错误,而不仅仅是“找不到对象”吗?会有帮助的。
-
我更新了问题。当我转到 localhost/yii/test 时,它会给我“Zostala wywolana akcja Index”但是如果我转到 localhost/yii/test/index 或 localhost/yii/test/site/index?r=site/index - 我会收到错误消息。如果我使用此链接:localhost/yii/test/index.php?r=site/index 或 localhost/yii/test/index.php?r=site 我会得到 actionIndex()。但是我怎样才能得到actionPokaz?在这本愚蠢的书中,他们说只是去localhost/yii/test/site/pokaz,但它不起作用。上面显示 404 错误。
-
要获得 actionPokaz 你需要使用 localhost/yii/test/index.php?r=site/pokaz 我想我明白了你的问题。很快就会给我答案。请确认 Pokaz 有效
标签: php web yii controller