5

I have a simple project in my xampp/htdocs directory called phalcon and I have apache configured to point to that folder so that I can go to phalcon/ in my browser.

The problem occurs when I try to open an index controller view other than index(default).
For instance I have someAction in Index controller and in views/index I have some.phtml.
If I go to phalcon/index/some I don't get the text from some.phtml outputed to the page.
It's probably because it thinks as if I wan't to open IndexController->indexAction and pass some as a parameter.

Would be grateful on any help provided to resolve this.
P.S. the project skeleton was copied from https://github.com/phalcon/skeleton-single.

Index controller:

<?php

class IndexController extends ControllerBase
{

  public function indexAction($action = null)
  {

  }
  public function someAction () {
      exit('test');
  }

}

views/index/index.phtml :

<?php echo $this->getContent(); ?>

views/index/some.phtml:

Some Action

views/index.phtml

<!DOCTYPE html>
<html>
<head>
  <title>Phalcon PHP Framework</title>
</head>
<body>
  <?php echo $this->getContent(); ?>
</body>
</html>
doydoy44
  • 5,720
  • 4
  • 29
  • 45
Andriy Haydash
  • 357
  • 1
  • 14
  • 35
  • Is mod_rewrite enabled for your installation? – Nikolaos Dimopoulos Apr 12 '14 at 13:58
  • The view processing happens **after** the controller action is executed. Have you tried to remove that `exit` call? – cvsguimaraes Apr 14 '14 at 00:53
  • The controller's action doesn't get executed at all. Whatever I do in controller like with the exit() function doesn't get called. Hence the view doesn't get called as well. That's the problem. – Andriy Haydash Apr 14 '14 at 09:51
  • See if this isn't related http://stackoverflow.com/questions/24049941/friendly-urls-in-phalcon-framwork-is-not-working-in-ubuntu – cvsguimaraes Jun 05 '14 at 16:38
  • I have clonned git repository, copied your code, exluded `exit()` an visited `http://localhost/skeleton-single/index/some` and I found it working just fine. Having no idea.. This is probably somewhere along server configuration :\ – yergo Mar 11 '15 at 15:31

6 Answers6

0

I am not sure if I understand your question completely but I think your Action must match the folder/file in view with the same name for it to function.

Also, I see you have extends 'ControllerBase' there then do you have a file called 'ControllerBase' in the controllers file with:

class ControllerBase extends \Phalcon\Mvc\Controller 

Another thing you can check would be the index.php in your public folder. Most of the time these stuff happens because the DI is missing or with a wrong input.

Blkc
  • 560
  • 7
  • 29
0

I think, that you should check your .htaccess file for following rule:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

This will enable all other controller actions, not only index. To check that the problem is in this rule you can by access your controller method via url /index.php?_url=/index/some - if it will be loaded, change your .htaccess like in example below

PVGrad
  • 84
  • 4
0

Not sure if that's expected behaviour, but in some scenarios actions from IndexController should be requested in Capital case like Index/some/ when index/some/ would return not found response.

Nazariy
  • 6,028
  • 5
  • 37
  • 61
0

Try using custom routing.

This can be done as follows if you are using the skeleton project but the concept is the same for any other application.

create the file app/config/routes.php

/**@var $router \Phalcon\Mvc\Router*/
$router = $di->get('router');

$router->add(
    "/index/some",
    [
       "controller" => "index",
       "action"     => "some",
    ]
 );

In the index.php after loading services.php

require __DIR__ . '/../app/config/routes.php';
Radolan
  • 129
  • 1
  • 4
-2
please change your .htaccess settings to following one

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule  ^$ public/    [L]
RewriteRule  (.*) public/$1 [L]
</IfModule>
-2
class SomeController...

is what you're looking for.