Php mysql 6th edition: how to integrate js ajax into the framework created in the book

@tomB am trying to integrate javascript into the framework to AJAXIFY the app created using the framework and I find it difficult doing it without code duplication and now, I also believe in DRY principle. How can I integrate it Into the framework.
I know this is not part of the book as the book is meant only for PHP and MySQL alone but I will appreciate it if you can give me some guide lines on how to integrate it into the existing code

You’ll need to change the router to make it so that each route also contains the name of the layout file to use. Then create a new layout which does json_encode on the data from the controller.

I wont mind if you can show me an example.
That will be appreciated

The best way to learn is through experimentation, try it yourself and see how you get on.

Am not with my laptop now but this is what I just draft out now(as in how is the route will be)

$routes = 'user/login' => [
    'GET' => [
        'controller' => $userController,
        'action' => 'loginForm',
        'layout' => 'login.html.php'

I will still write how the layout plan will be. But i dont know if that is how the route will be, that is why i wrote it to see if this is what you mean

Just implemented it now and it works but it looks magic to me. But I will really like to know why and how it works.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.