0

I can get all my entries, including entry url titles:

    $entries = ee('Model')->get('ChannelEntry')
         ->filter('status', 'IN', array('open'))
         ->order('title', 'ASC')
         ->all();

    foreach ($entries as $key => $entry) {
        $path = ee()->config->item("base_url") 
        $path .= $entry->url_title;
    }

But is it possible to get the full url of all entries in a module? for example:

http://ee5-modules.localhost/blog/entry/the-one-where-we-shake-it-ff
0

Ehhh, yes and no. If you use the Channel URL explicitly for how you display entries in that channel, you can generate a list by pulling up that model as well.

The real problem here is that a channel entry is in no way tied down to a specific URL; I can have 100 different template groups and 100 different templates in each, and call an entry from any channel I want. There is no implicit URL for a channel entry; unless, as I said, you use the Channel URL setting on a channel to explicitly display entries in that channel, so this would be a self-imposed URL restriction.

Here is a rough example of how you might list all of the entries in one channel if this is the case:

$entries = ee('Model')->get('ChannelEntry')
                      ->filter('status', 'IN', array('open'))
                      ->filter('channel_id', 'IN', array('47'))
                      ->order('title', 'ASC')
                      ->all();

$channel = ee('Model')->get('Channel')
                      ->filter('channel_id', 'IN', array('47'))
                      ->all();

foreach ($entries as $key => $entry) {
    $path = $channel[0]->channel_url . '/';
    $path .= $entry->url_title;
    echo $path;
    echo "<br>";
}

So this is really rough. For example, I don't check if the Channel URL ends in a /, and just append one regardless, you'd want to test to see if one is there first before just appending. Also, in this example, I'm hard-coding a channel id of 47 (just a channel in an install I have somewhere to test real quick).

Now if you really had to do this for each channel and each entry, you could place a loop in a loop, but this would result in an O(n^2) timed algorithm, and be quite slow if you have a large number of channels/entries. Whatever you are trying to do this for, I wouldn't recommend it for any production applications that get used in public facing templates; this should be for a data export or something.

I'm not super familiar with the EE Model construct, and there may be some trickery you can pull to make this faster or more efficient, but this code example can at least do what I think you are looking for.

6
  • Thank you for taking the time to reply. Maybe I'm taking the wrong approach, what if there is an override set up in a template? EE 'knows' the route to every entry, should i be looking at template routes maybe, is that possible through a Model? – wot Apr 13 '19 at 8:50
  • Again, channel entries can live anywhere in your EE system. Just throw a {exp:channel:entries entry_id="12345"} in any template and it will pull that entry. There are also template routes, besides Channel URL settings, that can create a path that will load an entry. Where entries/url-paths live in an EE system is self discipline, and not an enforced mechanism. You'll have to tell us how your installation works for us to help. Do you use Structure? Do you use template routes? I'm sorry, but EE does not 'know' the route, you determine it in your implementation. – jrothafer Apr 13 '19 at 8:56
  • ok, understood, I don't use Structure or Detour, so your answer is as close as I can get for 'raw' channel entries, how would I access template routes (is it possible, should I post this as another question)? – wot Apr 13 '19 at 9:49
  • 1
    The best way we can help is if you post specifics about how channel entries and their intended URLs work for your application. Don't reveal the application domain, but how your entries end up on specific URL patterns is important. Is it template based? Channel URL based? A combination? Give examples of URLs that match exactly single entries. We might have a better chance of helping you. Remember; there is no deterministic way to define your URL patterns in EE other than how you define them. Post another question if you can answer the questions in this comment. – jrothafer Apr 13 '19 at 10:00
  • Sorry if I'm sounding a little harsh, I'm not trying to be, but you really can define where a channel entry outputs to a URL in many ways and to multiple URLs. I hope I am actually helping, or at least shedding light! – jrothafer Apr 13 '19 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.