Compare commits

...

2 Commits

4 changed files with 53 additions and 3 deletions

View File

@ -2,9 +2,40 @@
namespace Lycoreco\Apps\Recipes\Controllers;
use Lycoreco\Apps\Recipes\Models\RecipeModel;
use Lycoreco\Includes\BaseController;
use Lycoreco\Includes\Routing\HttpExceptions;
class SingleRecipeController extends BaseController
{
protected $template_name = APPS_PATH . '/Recipes/Templates/single.php';
}
protected function get_model()
{
if (isset($this->__model))
return $this->__model;
$this->__model = RecipeModel::get(
array(
[
'name' => 'obj.id',
'type' => '=',
'value' => $this->url_context['url_1']
]
)
);
if (empty($this->__model))
throw new HttpExceptions\NotFound404('Recipe not found');
return $this->__model;
}
public function get_context_data()
{
$context = parent::get_context_data();
$context['recipe'] = $this->get_model();
return $context;
}
}

View File

@ -15,10 +15,27 @@ class RecipeModel extends BaseModel
public $field_status;
public $field_created_at;
public $category_name;
const STATUS = [[ 'publish', 'Publish' ], [ 'pending', 'Pending' ]];
static protected $search_fields = ['obj.title'];
static protected $table_name = 'recipes';
static protected $additional_fields = array(
[
'field' => [
'tb1.name AS category_name'
],
'join_table' => 'ingredients tb1 ON tb1.id = obj.category_id'
],
[
'field' => [
],
'join_table' => 'recipe_ingredients tb2 ON tb2.recipe_id = obj.id'
]
);
static protected $table_fields = [
'id' => 'int',
'title' => 'string',

View File

@ -1 +1,3 @@
Single Recipe item
<pre>
<?php var_dump($context['recipe']); ?>
</pre>

View File

@ -4,6 +4,6 @@ use Lycoreco\Apps\Recipes\Controllers;
use Lycoreco\Includes\Routing\Path;
$recipes_urls = [
new Path('/recipe/[:string]', new Controllers\SingleRecipeController(), 'single'),
new Path('/recipe/[:int]', new Controllers\SingleRecipeController(), 'single'),
new Path('/catalog', new Controllers\CatalogController(), 'catalog'),
];