Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to render template when using route with token #2

Open
Sokhavuth opened this issue Jun 19, 2021 · 4 comments
Open

Unable to render template when using route with token #2

Sokhavuth opened this issue Jun 19, 2021 · 4 comments

Comments

@Sokhavuth
Copy link

Sokhavuth commented Jun 19, 2021

I love f3 framework. It is similar to Express.js for Node.js. I have tried to build a blog engine with f3 framework as I use to do with Python and Node.js. Everything works fine. However, I am unable to render any template when using route with token (route with parameter in other frameworks). Here the link to the repository: https://github.com/Sokhavuth/tvp, and the link to the working blog on Heroku is here https://khmerweb-tvp.herokuapp.com/ . You could login with email "[email protected]" and password "password"; the link for login is https://khmerweb-tvp.herokuapp.com/login. On the admin page, click on the second icon on top, and try to click on edit icon of the post at the bottom, you will see the problem (do not click on delete icon, it will delete post).

@xfra35
Copy link
Member

xfra35 commented Jun 19, 2021

Hi @Sokhavuth. tokens don't look like an issue here.

When you write: edit($f3, $f3->get('PARAMS.id')), that looks perfectly fine.

It looks like the issue is in https://github.com/Sokhavuth/tvp/blob/master/controllers/admin/posts/edit.php:

$sql = "SELECT * FROM posts WHERE id=?";
$post = $f3->get('DB')->exec($sql, $id);

The 2nd line gets you an array of rows matching $id.

So you'd better write something like:

$sql = "SELECT * FROM posts WHERE id=?";
$posts = $f3->get('DB')->exec($sql, $id);
if (!$posts) {
  // no posts matching, do something, for example throw a 404:
  $f3->error(404);
} else {
  // everthing's ok, fetch first post and continue
  $post = $posts[0];
}

@Sokhavuth
Copy link
Author

Sokhavuth commented Jun 21, 2021

I have tried not to insert any data into the template in question. But nothing happens. The problem is static files such as css, js, and images are not loaded. I'm trying to build a blog exactly like I did with Express.js here: http://khmerweb-tv.herokuapp.com/ . In Express.js everything works really good.

@n0nag0n
Copy link
Member

n0nag0n commented Jun 21, 2021

out of curiosity, just to rule out heroku, when you load your app with php -S localhost:8000 when you are in your repo folder, and if you go to a page with a token on it, does it work for you there? You could load up a quick db with a docker image so you have a local database as well so you can really test out your project locally instead of in heroku. I'm just trying to rule out that something in heroku isn't causing it.

@Sokhavuth
Copy link
Author

Sokhavuth commented Jun 21, 2021

The route with token works really smooth. The problem is only the rendering of template with that route.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants