Compare commits
No commits in common. "318a40c22238a9c910b016d77249e439905a9193" and "5b1d4e60da82fc1f8cd2d14302572e17dc2523c1" have entirely different histories.
318a40c222
...
5b1d4e60da
@ -2,40 +2,9 @@
|
|||||||
|
|
||||||
namespace Lycoreco\Apps\Recipes\Controllers;
|
namespace Lycoreco\Apps\Recipes\Controllers;
|
||||||
|
|
||||||
use Lycoreco\Apps\Recipes\Models\RecipeModel;
|
|
||||||
use Lycoreco\Includes\BaseController;
|
use Lycoreco\Includes\BaseController;
|
||||||
use Lycoreco\Includes\Routing\HttpExceptions;
|
|
||||||
|
|
||||||
class SingleRecipeController extends BaseController
|
class SingleRecipeController extends BaseController
|
||||||
{
|
{
|
||||||
protected $template_name = APPS_PATH . '/Recipes/Templates/single.php';
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -15,27 +15,10 @@ class RecipeModel extends BaseModel
|
|||||||
public $field_status;
|
public $field_status;
|
||||||
public $field_created_at;
|
public $field_created_at;
|
||||||
|
|
||||||
public $category_name;
|
|
||||||
|
|
||||||
const STATUS = [[ 'publish', 'Publish' ], [ 'pending', 'Pending' ]];
|
const STATUS = [[ 'publish', 'Publish' ], [ 'pending', 'Pending' ]];
|
||||||
|
|
||||||
static protected $search_fields = ['obj.title'];
|
static protected $search_fields = ['obj.title'];
|
||||||
static protected $table_name = 'recipes';
|
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 = [
|
static protected $table_fields = [
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'title' => 'string',
|
'title' => 'string',
|
||||||
|
|||||||
@ -1,3 +1 @@
|
|||||||
<pre>
|
Single Recipe item
|
||||||
<?php var_dump($context['recipe']); ?>
|
|
||||||
</pre>
|
|
||||||
@ -4,6 +4,6 @@ use Lycoreco\Apps\Recipes\Controllers;
|
|||||||
use Lycoreco\Includes\Routing\Path;
|
use Lycoreco\Includes\Routing\Path;
|
||||||
|
|
||||||
$recipes_urls = [
|
$recipes_urls = [
|
||||||
new Path('/recipe/[:int]', new Controllers\SingleRecipeController(), 'single'),
|
new Path('/recipe/[:string]', new Controllers\SingleRecipeController(), 'single'),
|
||||||
new Path('/catalog', new Controllers\CatalogController(), 'catalog'),
|
new Path('/catalog', new Controllers\CatalogController(), 'catalog'),
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user