enable module view instead of default view

Hi,

I've implemented the sample files from the simple module tutorial. In the CMS everything is working but on the front-end /articles/{slug} ends up on my default view instead of view/articles.php.

I have also added $pages['articles/:any'] = array('view' => 'articles'); to _variables/global.php

If I add an exit(); at the end of the view/articles.php, the page is displayed correctly.

What is redirecting my view to my default view? And how can I prevent this?

Thanks in advance.

Comments

  • Did you set this up in a fuel/application/views/_variables/articles.php file?

    $vars['view'] = 'articles';
    

    Also, is the page redirecting or displaying the wrong view?

  • edited September 2021

    Setting this up in _variables/articles.php does not change anything.

    /articles/{slug} shows me the view/articles.php

    but
    /articles shows me my view/_layouts/home.php which is my default view
    It's displaying the wrong view, not redirecting.

  • Did you specify the $max_page_params in the fuel/application/config/MY_fuel.php?

    $config['max_page_params'] = array('articles' => 1);
    
  • Yes, I tried all 4 "Finding the View" from the tutorial, but no effect.

    This is my views/articles.php. URL without a slug only works with an exit(); at the end.

    <?php 
    $slug = uri_segment(2);
    
    if ($slug) :
    
        $article = fuel_model('articles', array('find' => 'one', 'where' => array('slug' => $slug)));
    
        if (empty($article)) :
            redirect_404();
        endif;
    
    else:
        $tags = fuel_model('tags');
    endif;
    
    if (!empty($article)) : ?>
    
        <h1><?=fuel_edit($article)?><?php echo $article->title?></h1>
        <div class="author"><?=$article->author->name?></div>
        <img src="<?=$article->image_path?>" alt="<?=$article->title_entities?>" class="img_right" />
        <article><?=$article->content_formatted?></article>
    
    
    <?php else: ?>
    
        <h1>Articles</h1>
    <?php foreach($tags as $item) : 
    echo $item->name;
    ?>
    <?php endforeach; ?>
    
    <?php endif; 
    exit(); //----- WORKS ONLY WHITH THIS ONE
    
  • I'm having a hard time replicating your issue. Do you have a page called "articles" created in the Pages module that may be interfering?

  • Nope, all my pages are in dutch ;-)

    Will it help if I create a controller for it. Like @almostcompletely suggested in one the tickets?

  • A controller should supersede the automatic view mapping so yes, you can try that.

Sign In or Register to comment.