0

I want to run my activeIndex() function in GuestsController.php file under a subdirectory as the first default page when the user enters the url.

For this reason, I have written such a script in my .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/controllers/GuestsController.php/.*
RewriteRule ^/mvc/(.*) /controllers/GuestsController.php?method=$actionList?page=$1 [QSA,L]

And my GuestsController.php file is:

<?php

class GuestsController
{
    public function actionIndex()
    {       
        echo "start";
        sleep(1);       
        include(dirname(__FILE__) . '/../views/guests/index.php' );
    }

    public function actionList()
    {
        $guests = Guests::findAll();

        echo json_encode( $guests );
    }
}

I still could not manage to achieve my goal.

How I should modify .htaccess file to run actionIndex() function directly?

Thanks,

yusuf
  • 3,591
  • 8
  • 45
  • 86
  • 1
    Look at this, this may give you an idea. http://stackoverflow.com/questions/9019611/php-assigning-a-default-function-to-a-class – Panama Jack Oct 27 '15 at 20:59
  • 1
    Your `GuestsController.php` file simply contains a class definition - it doesn't contain any runable code (unless this is not shown)? Your `RewriteRule` substitution seems to be malformed (you have two `?`)? Where is your .htaccess file located? The `RewriteCond` and `RewriteRule` pattern appear to reference two very different URL paths so it's difficult to see how this would match? – MrWhite Oct 27 '15 at 21:39
  • so how can I modify my .htaccess? – yusuf Oct 27 '15 at 21:42
  • It's not just a matter of changing .htaccess (which is incorrect as w3d noted) but you aren't calling anything in your script as it appears. Check out the link I mentioned. – Panama Jack Oct 27 '15 at 21:57

0 Answers0