0

I have a default controller named SiteController with some actions in it like:

-index
-aboutcompany

When I open my site in browser like: localhost/lucky

The index action is working properly.

On index.php (view) i made a link: echo CHtml::link('About Company', array('site/aboutcompany));

When I click on the link an error appears:

The requested url not found on this server.

None of the actions (sitecontroller) are working except index

Please suggest me the solution.

This is the controller code:

<?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');
    }

This is the config code

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',
),
);
tereško
  • 58,060
  • 25
  • 98
  • 150
Lalitesh Upadhyaya
  • 311
  • 1
  • 4
  • 14
  • do you ve any htaccess?? I mean using any? – Nabin Kunwar Jan 20 '14 at 06:47
  • Yes, this is the content of my .htaccess `Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.php ` – Lalitesh Upadhyaya Jan 20 '14 at 06:52
  • htaccess is gud.and hiding index.php?? show ur config main.php and SiteController also if u can. :) – Nabin Kunwar Jan 20 '14 at 06:54
  • `?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'); }` – Lalitesh Upadhyaya Jan 20 '14 at 06:56
  • config file also and please update codes in ur question not in comment. – Nabin Kunwar Jan 20 '14 at 06:57
  • what is the url your getting while clicking the link? – Kumar V Jan 20 '14 at 07:04
  • I updated the question with controller code and main.php code – Lalitesh Upadhyaya Jan 20 '14 at 07:04
  • [link]http://localhost/lucky/site/aboutcompany – Lalitesh Upadhyaya Jan 20 '14 at 07:05
  • i think you should call `site/aboutCompany` not `aboutcompany` – Kumar V Jan 20 '14 at 07:15
  • your htcaccess file not replace index.php type your url with defining index.php in it – Agha Umair Ahmed Jan 20 '14 at 07:18
  • I think something is wrong with your .htaccess or mod-rewrite. Normally if it is an issue just with Yii finding the action you would get an error like this `The system is unable to find the requested action "aboutcompany".` Not a URL not found error. Can you confirm your htaccess and mod-rewrite are working? – Pitchinnate Jan 20 '14 at 15:39
  • Thanks Pitchinnate: I remove the `#` from the httpd.conf and restart the server and now every thing is working fine. – Lalitesh Upadhyaya Jan 21 '14 at 06:05

0 Answers0