ivandoric / Making-Websites-With-October-CMS

This is a repository for video tutorial series about making websites with October CMS. You can check out the series here: https://goo.gl/eW32CM
160 stars 52 forks source link

Single page with one type genre movies only. #20

Closed pierzo closed 5 years ago

pierzo commented 5 years ago

Hi, I've already asked you for a solution under a video on youtube. Your respond was:

You would create a page that would have this type of URL: "movies/genres/:slug" Now in PHP block of that file you would have something like this:

<?php function onStart(){ $this['movies'] = WatchLearn\Videos\Models\Video::whereHas('genres', function ($query) { $query->where('slug', '=', $this->param('slug')); })->get();

}

?>

So when you go to for example: www.yoursite.com/movies/genres/action you would get only movies that have a genre of action. Of course below PHP block you would have a some sort of loop to display those movies, something like this:

{% for movie in movies %}

{{ movie.title }}

...

{% endfor %}

So I did that and what I get on movies/genres/:slug site is:

where('slug', '=', $this->param('slug')); })->get(); } ?>

All tags are closed.

What I would like to achieve is the category page for movies.

Thank you, great tutorials!

ivandoric commented 5 years ago

I answered you on Youtube.

But I'm not sure what you mean by: "where('slug', '=', $this->param('slug')); })->get(); } ?> All tags are closed."

What does that mean. Did you write your code in PHP block?

Also let's continue this discussion here instead of YouTube because we can share code more easily here.

pierzo commented 5 years ago

Ok, link to screen exerpt

https://photos.app.goo.gl/G3CArK6Exk6kxnih7

ivandoric commented 5 years ago

Show me your code for that page. Seems to me that you didn't put it in PHP block.

pierzo commented 5 years ago

`

<?php

function onStart(){ $this['movies'] = Kominki\Realizacje\Models\Realizacje::whereHas('typy', function ($query) { $query->where('slug', '=', $this->param('slug')); })->get();

}

?>

{% for realizacja in realizacje %}
<h2>{{ realizacja.nazwa_realizacji }}</h2>
...

{% endfor %}

`

ivandoric commented 5 years ago

Look, I told you several times to put your code in PHP block. Did you do that? Because I can't figure that out from your code. Did you watch the video about PHP blocks that I linked for you on YouTube?

Anyway your file should look something like this.:

title = "Single video"
url = "/:category/:slug"
layout = "default"
is_hidden = 0
==

// THIS IS PHP BLOCK. notice "==" symbols at the beginning and the end. 

<?php
function onStart()
{

    $this['movies'] = Kominki\Realizacje\Models\Realizacje::whereHas('typy', function ($query) {
    $query->where('slug', '=', $this->param('slug'));
    })->get();
}
?>

// END OF PHP BLOCK

==

// Your HTML + Twig code goes here.

Hope this helps.

pierzo commented 5 years ago

I apologize for my ignorance of the subject. Now I know what's going on with this php block.

What I want to achieve above all is the categories. Let's say I want to do a car dealer website.

I create a cars database where there are columns: id, slug, car_name, description.

I create a second database of a car type with columns: id, slug, car_type (eg van, pickup, sedan)

And now I would like to have three sides

  1. mysite.com/cars/ here all car categories are shown as links. When I click on a link, for example a van, I go to the page:

  2. mysite.com/cars/van/ All van cars are displayed here as links. And when I click on one of them, I go to the page:

  3. mysite.com/cars/van/:slug selected van car

I understand that I need to create a pivot database cars_types with columns car_id and type_id.

Or maybe... In the first database, add the column "category_id" and display on the page the list similar to:

record.category_id

Maybe it will be easier for us to get along :)

pierzo commented 5 years ago

Categories should be easier to achieve than tagging or filtering. But I can not do it or it is not in the documentation. I would ask on the forum but it is read-only.

ivandoric commented 5 years ago

Take a look at this video, it deals with something similar to what you are asking. https://www.youtube.com/watch?v=sZXdruO2ac8