nicksagona on 5.3.2
nicksagona on 4.5.11
nicksagona on 4.5.11
nicksagona on master
Patch expression issue for NOT … (compare)
nicksagona on v5-dev
Patch expression issue for NOT … (compare)
nicksagona on 3.7.1
nicksagona on master
Patch PHP 8 issue with named pa… (compare)
nicksagona on v3-dev
Patch PHP 8 issue with named pa… (compare)
nicksagona on 4.5.10
nicksagona on 4.5.10
nicksagona on v4-dev
Patch dirty save (compare)
nicksagona on master
Patch dirty save/set function (compare)
nicksagona on v5-dev
Patch dirty save/set function (compare)
nicksagona on 3.6.1
nicksagona on master
Patch setValue issue with Check… (compare)
nicksagona on v3-dev
Patch setValue issue with Check… (compare)
class Movies extends Pop\Db\Record
{
public function qualities()
{
return $this->hasMany('Qualities', 'movie_id'); // 'movie_id' is the FK
}
}
class Qualities extends Pop\Db\Record
{
public function movie()
{
return $this->belongsTo('Movies', 'id'); // 'id' is the primary key that is used to get the parent relationship
}
}
$movie = Movies::findById(1); // Get a single movie
$qualities = $movie->qualities(); // Get all qualities of that movie
print_r($movie->toArray());
print_r($qualities->toArray());
// Movie
Array
(
[id] => 1
[title] => Avengers
)
// Qualities of the movie
Array
(
[0] => Array
(
[id] => 1
[movie_id] => 1
[type] => Great
)
[1] => Array
(
[id] => 2
[movie_id] => 1
[type] => Exciting
)
)
$quality = Qualities::findById(1); // Get a single quality
$parentMovie = $quality->movie(); // Get that quality's parent movie
print_r($quality->toArray());
print_r($movie->toArray());
// Quality
Array
(
[id] => 1
[movie_id] => 1
[type] => Great
)
// Movie the quality belongs to
Array
(
[id] => 1
[title] => Avengers
)
movies
and a table qualities
with a FK qualities
.movie_id
referencing back to movies
.id
Thank you, Mr. Nick Sagona, for answering my question quickly. However, I don't think that's what I wanted to ask.
For example, in Laravel, a route is defined as follows:
Route::get('user/{id}/profile', function ($id) {
//
})->name('profile');
and to generate the url address (for href in <a>) the code is used:
$url = route('profile', ['id' => 1, 'photos' => 'yes']);
// /user/1/profile?photos=yes
Can something similar be done in popphp ?
/users/:id
or /users[/:id]
function ($id) { }
popphp
components (router, controller) and the view component
Ok. Understand . Sorry if I'm holding you back too much and thanks again for trying to help me. I read all your documentation about the PopPHP framework in the last two days and I didn't find what I asked as a question here. The PoPPHP framework is very nice and I would like to move on from Laravel to use it.
Let me try to ask you like this. In PopPHP routes we can define as follows:
$config = [
'routes' => [
'/products/:id' => [
'controller' => 'MyApp\Controller\ProductsController',
'action' => 'index',
'controllerParams' => [
'id' => 789
]
]
]
];
$app = new Pop\Application($config);
We have a defined route in the code above that responds to the url address /products/:id. The Route object has the properties controller, action, and controllerParams (but as far as I can see property name does not exist as in Laravel for the reverse process - generating url addresses via route object).
In PoPPHP, I assume that this route can be accessed using the code:
$myRoute = $app->router()->getRoutes()['/products/:id'];
There was a possibility to generate a url address from the route (for example for the href Edit button in the html table in the 3rd row the generated url address would be).
/products/3 - for dispaly details page for product 3
<table>
<tr>
<td><a href="/profile/1">Edit</a></td>
<td>Profile 1</td>
</tr>
<tr>
<td><a href="/profile/2">Edit</a></td>
<td>Profile 2</td>
</tr>
<tr>
<td><a href="/profile/3">Edit</a></td>
<td>Profile 3</td>
</tr>
</table>
<table>
<?php foreach ($profiles as $profile): ?>
<tr>
<td><a href="/profile/<?=$profile['id']; ?>">Edit</a></td>
<td>Profile <?=$profile['id']; ?></td>
</tr>
<?php endforeach; ?>
</table>
$router->addRoute('/profile/:id [
'controller' => 'MyApp\Controller\IndexController',
'action' => 'profile'
]);