We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Replace previous old website step by step with new phalcon-powered site?

The old site is a series of .php files, no framework, no templates and i'd like to replace the pages on this site one by one. Basically the structure is index.php, thing.php, thing2.php thing3.php etc.

Can i make a project so i publish both site together but i only override first index.php (home), and then thing, thing1 and so on. So i can make an incremental convert.

Thanks

Yes but you will need to have Phalcon driving behind the scenes so to speak. Traditionally one doesn't do this since it is more work than one would expect. Changing to an MVC framework should be done in one move.

However to answer your question:

You need to set a phalcon project. In your routes you need to add something like this:

$router->add('thing.php', ['controller' => 'onlyphp' , 'action' => 'index'])
$router->add('thing2.php', ['controller' => 'onlyphp' , 'action' => 'index'])

which will instruct phalcon to process thing.php with the thing controller. In that controller you can have code that will read thing.php and send it to the view.

Slowly you can move each of the php files to their respective controllers.and thus removing the old functionality.



574

I have another question: is it possible to just integrate the template(VOLT) on the old site since the templates are the biggest mess? And then i can continue with the controllers and models? Basically on thing.php: i do queries and php stuff and in the end something like:

print render_template('template.phtml', data)

Thanks

Hey @ddorian ,

As you can see here : https://forum.phalcon.io/discussion/599/using-volt-compiler-as-an-external-component (i'm still waiting for an answer), i'm also migrating an old web site to phalcon.

First step (maybe the only, because as you say the real mess is not the framework, but the template engine itself) is to integrate volt. I get lucky because on this website all pages call a function html_render(); that renders a the html What you can see in the link is the new html_render that i did for the site.

You may have additionnals infotmations at : https://docs.phalcon.io/en/latest/reference/volt.html (last section of the page is what i used to integrate it on my site)

@ddorian maybe https://docs.phalcon.io/en/latest/reference/views.html#simple-rendering

class PostsController extends \Phalcon\Mvc\Controller
{

    public function indexAction()
    {
        //Render 'views-dir/index.phtml'
        echo $this->view->render('index');

        //Render 'views-dir/posts/show.phtml'
        echo $this->view->render('posts/show');

        //Render 'views-dir/index.phtml' passing variables
        echo $this->view->render('index', array('posts' => Posts::find()));

        //Render 'views-dir/posts/show.phtml' passing variables
        echo $this->view->render('posts/show', array('posts' => Posts::find()));
    }

}

or https://docs.phalcon.io/en/latest/reference/views.html#id2

<?php

$view = new \Phalcon\Mvc\View\Simple();

//A trailing directory separator is required
$view->setViewsDir("../app/views/");

// Render a view and return its contents as a string
echo $view->render("templates/welcomeMail");

// Render a view passing parameters
echo $view->render("templates/welcomeMail", array(
    'email' => $email,
    'content' => $content
));