It looks like you're new here. If you want to get involved, click one of these buttons!
Hello,
I am creating a module called article following the article in https://docs.getfuelcms.com/modules/tutorial
At the end, i created the file articles.php within /application/views/ directory, but the site returns 404 not found.
Can you please help me with it?
Here are my some code:
MY_fuel_modules.php
$config['modules']['articles'] = array(
'preview_path' => 'articles/{slug}',
'display_field' => 'title',
'sanitize_input' => array('template','php'),
);
Articles_model.php
class Articles_model extends Base_module_model {
function __construct()
{
parent::__construct('articles');
}
function form_fields($values = array(), $related = array())
{
$fields = parent::form_fields($values, $related);
$fields['content']['img_folder'] = 'articles/';
$fields['image']['folder'] = 'images/articles/';
return $fields;
}
}
class Article_model extends Base_module_record {
public function get_url()
{
return site_url('articles/'.$this->slug);
}
public function get_image_path()
{
return img_path('articles/'.$this->image);
}
}
THanks
Comments
Your model and declaration in MY_fuel_modules.php will give you access to edit the data within Fuel admin.
Your view should be used in conjunction with an Articles.php controller to give access to it on the front-end (public side)
The preview path set for the module is
articles/{slug}
and there is likely not a view file specified atviews/articles/my-slug-value.php
. There are a some additional ways to fix this (along with almostcompletely's recommendation to use a controller):Setup post pages configuration:
https://docs.getfuelcms.com/modules/simple#post_pages
You may also try adding the following to MY_fuel.php to route all requests to
articles/{slug}
to theviews/articles.php
file where you can have logic in your view file to grab the slug value (e.g.uri_segment(2)
).More can be found on that here:
https://docs.getfuelcms.com/general/pages-variables
Thank you @almostcompletely for your response.
As per your suggestion, I did the same and created a controller named Articles.php and now my url is example.com/articles/1 and I created a method like:
public function index($id) {
echo $id;
}
But still I got 404 not found.
What else did I need to do to achieve the view page.
I need to list a articles in one page and I need to display single article in another.
Can you please show me the right path? Also, do you have any complete example?
Thank you so much and still I am waiting your response.