Help to access view

Hi, i'm started in phalcon and a i need help to create a view.

For start the project a used "phalcon project teste".

Create a controller a used "phalcon controller takeshi"

In controller a created one action:

public function indexAction(){

}

And a create a view in: app/views/takeshi/index.phtml:

<h1>simple test</h1>

But access to url "http://localhost/p1/takeshi", dont work.

Access url "http://localhost/p1/" its work a index page from project.

what am i doing wrong?

Doc used: https://docs.phalconphp.com/en/3.3/tutorial-base

Phalcon version: 3.3.2

Model != Controller

phalcon model takeshi creates a model, not a controller.

In model a created one action:

public function indexAction(){

}

You have to create actions on controllers, not models.

edited Apr '18

Sorry.

I create a controller using "phalcon controller takeshi" and create action in controller. I wrote wrong, my bad.

Thanks for your answer.



37.0k

Hi,

be sure to put the right path in $url->setBaseUri()


// Setup a base URI
$di->set(
    'url',
    function () {
        $url = new UrlProvider();
        $url->setBaseUri('/p1/');
        return $url;
    }
);

Hi.

My baseUri is set, this way:

in config.php:

'baseUri' => preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"]),

In services.php:

$di->setShared('url', function () {
    $config = $this->getConfig();

    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);

    return $url;
});

I think it's right



37.0k

Hi,

So you are getting further than just

Doc used: https://docs.phalconphp.com/en/3.3/tutorial-base

I have replied in that context ;-)

Did you create your new p1 app with the phalcon devTools ?



37.0k

also:

But access to url "http://localhost/p1/takeshi", dont work.

That's not really helpfull, try to be more explicit. eg, did you get any error message in webserver log ?

edited Apr '18

Hi.

I'm used phalcon for Windows 10 for dll. The project and controller were created by the console, using this comands:

phalcon create-project p1

phalcon controller takeshi

View has create manually.

The error is 404 - Not Found.

My controller (app/controllers/TakeshiController.php):

<?php

class TakeshiController extends \Phalcon\Mvc\Controller
{

    public function indexAction()
    {

    }

}

My view (app/views/takeshi/index.phtml):

<h1>simple test</h1>

My config(app/config/config.php):

'baseUri' => preg_replace('/public([\/\\\\])index.php$/', '', $_SERVER["PHP_SELF"]),

My rout(app/config/services.php):

$di->setShared('url', function () {
    $config = $this->getConfig();

    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);

    return $url;
});

If access http://localhost/p1 is show:

Imgur

If access http://localhost/p1/takeshi is show:

Imgur



37.0k

Hi,

first be sure that you have the .htacess files in /p1/ and /p1/public/ directories then, try in config.php:

$baseUri = '/p1';



37.0k
edited May '18

I'm used phalcon for Windows 10 for dll.

did you get any error message in webserver log

I'm not used with Windows 10, but I'm pretty sure that you can access elsewhere on these webserver error logs. It is really helpfull while coding in php.