Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Trouble at the first tutorial

Hello everyone. After having downloaded Phalcon and getting it to work, I thought I'd try some tutorials to get going with it.

I'm using Phalcon 1.0.1 - Windows x86 for PHP 5.4.0 (VC9).

The first tutorial being this one: http://docs.phalconphp.com/en/latest/reference/tutorial.html

Everything works fine until I hit the part where you have to load the register form. My URL http://localhost/PhalconTutorial/signup just goes back to the index page.

Here is a screenshot of my folder structure: http://i.stack.imgur.com/uW6Sy.jpg

I can't determine what I did wrong. Everything is copied from the tutorial page.

I'm not a beginner, but I'm not exactly a seasoned PHP developer either. I'd normally post this on StackOverflow, but this seems so simple and yet it goes wrong, I cannot help but think something is wrong with either the code or the .htaccess files. Any help would be appreciated.

check u view folder, u need create folder using same name of u controller

\-view
    +- index
    +- signup


82.7k

Compare the code with the one in this repository: https://github.com/phalcon/tutorial

Ah, I see the problem. There's a folder for each view and inside those the phtml files. I just put all the phtml files in the view folder, without making subfolders.

So, now I made subfolders, put the files in there and named them both index.phtml. Working now.



98

SOS, I have the same problem with both my and the source code I dowloaded. It says "Not Found: The requested URL /public/signup was not found on this server" when trying to go the form with the "Sign up here" link. Am I missing something in configurations? Using Wampserver with php 5.4.12 and apache 2.4.4

edited Oct '14

@Vahe, make sure mod_rewrite is enabled and check your .htaccess files. Then make sure your base URI point's to the project folder:

//Setup a base URI so that all generated URIs include the "projectName" folder
$di->set('url', function(){
    $url = new \Phalcon\Mvc\Url();
    $url->setBaseUri('/projectName/');
    return $url;
});

( if your using virtual hosts it should be $url->setBaseUri('/'); )

the URL's should be: localhost/projectName and localhost/projectName/signup



98
Accepted
answer

So, the porblem is solved!!! I had written the rewrite rules directly in the httpd.conf file as is recommended by apache.I don't know what I had done wrong with it but creating separate htaccess files as mentioned in the tutorial solved the problem....thanks again!!!

edited Oct '14

Hallo All, have Phalcon with Ubuntu 12.04. LTS, but at 1st Tutorial have a 1st Problem: if I write im Browser localhost/mari (my project name), I can see just a folder names, but no output of Controller or view. If I click on 'public' folder, I can see output of view. My .htaccees file looks like:

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

and index.php:

try {

    //Register an autoloader
    $loader = new \Phalcon\Loader();
    $loader->registerDirs(array(
            '../app/controllers/',
            '../app/models/'
    ))->register();

    //Create a DI
    $di = new Phalcon\DI\FactoryDefault();

    //Setup the view component
    $di->set('view', function(){
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../app/views/');
        return $view;
    });

    //Setup a base URI so that all generated URIs include the "tutorial" folder
    $di->set('url', function(){
        $url = new \Phalcon\Mvc\Url();
        $url->setBaseUri('/mari/');
        return $url;
    });

    //Handle the request
    $application = new \Phalcon\Mvc\Application($di);

    echo $application->handle()->getContent();

} catch(\Phalcon\Exception $e) {
    echo "PhalconException: ", $e->getMessage();
}

what is wrong here? please, help!

Firstly, the file .htaccees should have the name .htaccess. Secondly you need a second .htaccess file in your /public directory, as described here. Thirdly you should ensure you are using the Apache web server, mod_rewrite is enabled and the server checks for .htaccess files.

Additionally the index.php file should begin with a <?php, otherwise your code won't get executed and the .htaccess file should contain line breaks after each statement.

edited May '14

Thank you, Wenzel Pünter, with a second .htaccess file will I try, and index.php has already at begin "<? php". I know, taht a riht name file is * .htaccess, not a *.htaccees :-) - it's just a 'write-error' I write the answer if it works!

edited Oct '14

Hallo Wenzel Pünter, I have add the second .htaccess file under /public/ directory, but I have the same problem :-(

The second .htaccess file looks like:

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

I have deleted a view, and my IndexController look like:

<?php
class IndexController extends \Phalcon\Mvc\Controller
{

    public function indexAction()
    {
        echo $this->url->getBaseUri(); //"mari";
    }   
}

The output is: /mary/ - NO 'localhost/mary/' - is it correct?

I guess, I have a Problem with apache or php configuration...

The output /mary is correct. getBaseUri() returns the path without a domain or server name.

Hello, I'm having issues with the first tutorial in phalcon. I am using apache server on windows at localhost. I installed it as a standalone and not part of a stack like XAMPP or WAMP. I had to do that to enable the mySQL connector for use with c++. I've enabled rewrite, I'm checked my .htaccess files and done pretty much whats been said in this forum. I've no idea why i cannot seem to load my signup page. I always get localhost/public/signup not found error. Below are my codes.

TESTAAR.htaccess

<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ public/ [L] RewriteRule ((?s).*) public/$1 [L] </IfModule>

TESTAAR/public/.htaccess

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

TESTAAR/public.index.php

<?php /** * Created by PhpStorm. * User: User * Date: 18/11/2015 * Time: 4:19 PM */

use Phalcon\Loader; use Phalcon\Mvc\View; use Phalcon\Mvc\Application; use Phalcon\DI\FactoryDefault; use Phalcon\Mvc\Url as UrlProvider; use Phalcon\Db\Adapter\Pdo\Mysql as DbAdaptor;

try { // Register an autoloader $loader = new Loader(); $loader->registerDirs(array( '../app/controllers/', '../app/models/' ))->register();

//Create a DI
$di = new FactoryDefault();

// Set up the view component
$di->set('view', function() {
    $view = new View();
    $view->setViewsDir('../app/views/');
    return $view;
});

//Setup a base URI so tha all generated URIs include the "tutorial folder
$di->set('url', function() {
    $url = new UrlProvider();
    $url->getBaseUri('/TESTAAR/');
    return $url;
});

// Handle the request
$application = new Application($di);

echo $application->handle()->getContent();

} catch (\Exception $e) { echo "PhalconException: ", $e->getMessage(); }

TESTAAR/app/controllers/IndexController.php

<?php /** * Created by PhpStorm. * User: User * Date: 19/11/2015 * Time: 10:44 AM */ use Phalcon\Mvc\Controller;

class IndexController extends Controller { public function indexAction() { } }

TESTAAR/app/views/index/index.phtml

<?php /** * Created by PhpStorm. * User: User * Date: 19/11/2015 * Time: 10:46 AM */ echo "<h1>Hello!</h1>";

echo $this->tag->linkTo("signup", "Sign Up Here!");

TESTAAR/app/controllers/SignupController.php

<?php /** * Created by PhpStorm. * User: User * Date: 19/11/2015 * Time: 10:48 AM */

use Phalcon\Mvc\Controller;

class SignupController extends Controller { public function indexAction() {

}

}

TESTAAR/app/views/signup/index.phtml

/** * Created by PhpStorm. * User: User * Date: 19/11/2015 * Time: 10:50 AM */ <h2>Sign up using this form</h2>

<?php echo $this->tag->form("signup/register"); ?>

<p> <label for="name">Name</label> <?php echo $this->tag->textField("name") ?> </p>

<p> <label for="email">Email</label> <?php echo $this->tag->textField("email") ?> </p>

<p> <?php echo $this->tag->submitButton("Register") ?> </p>

</form>

ITS VERY FRUSTRATING TO NOT BBE ABLE TO MAKE IT WORK FOR 5 DAYS!

edited Dec '16

I had a similar problem and was just wondering why the .htaccess configuration is not included in the first tutorial. Please include. Thanks