XF 2.0 How to create a new page for each entity?

Can you elaborate in which context you're working? Page and entity?

So my add-on retrieves content from a JSON file and saves that content to an entity and then displays each one on add-on's index page (/dev-tracker. Each entity has its own unique 8 character string ID.

I want each intity to have a page and the URL structure would be after the add-on's URL. /dev-tracker/entry/absjwusu for example
 
Look at how Forum controller handles this. The index page takes unique IDs and reroutes them to the appropriate controller action.
 
Could someone assist me with how to use $params correctly?

If I use this piece of code in the actionEntry, it works fine and retrieves the requested entry.

PHP:
$testEntry = $entryRepo->findEntry()->where('entry_id', 'bdkwgnna')->fetch();

But if I put this code in the actionEntry, it won't work.

PHP:
$testEntry = $entryRepo->findEntry()->where('entry_id', $params->entry_id)->fetch();

Is this the correct usage of $params?

Here is the actionEntry function in my public controller.
PHP:
public function actionEntry(ParameterBag $params)
{
    $entry = $this->assertEntryExists($params->entry_id);

    $entryRepo = $this->getEntryRepo();
    $testEntry = $entryRepo->findEntry()->where('entry_id', $params->entry_id)->fetch();

    $this->assertCanonicalUrl($this->buildLink('dev-tracker', $params->entry_id));

    $viewParams = [
        'entry' => $entry,
        'testEntry' => $testEntry
    ];

    return $this->view('AH\DevTracker:Entry\View', 'ah_dev_tracker_entry_view', $viewParams);
}

Thank you.
 
Is entry.bdkwgnna mapped to entity_id? You could add
'id' => $params->entry_id to your viewParams and output them in the template to see if the id is wrong.
 
Well, that's why I asked what your route is. There is no action defined, so I assume your actionIndex routes to actionEntry - but how exactly does your route look like (route format)?
 
Either remove action prefix "Entry" and add entry to the and of the url
/dev-tracker/entry/bdkwgnna/entry

or rename your function to actionEntryIndex (no more changes needed)

or create a reroute to actionEntry in your actionIndex if route contains "/entry/". (that doesnt work that way)

I would rethink the route format.

Edit2: nvm i tried it myself, it works as you defined your routes. There's probably somewhere else a problem, although you could try the first thingy.
 
Last edited:
I'm trying to do this again:

This is my route:
189822

The "id" is the id of the entry in the database. The "entry_id" is the id of the entry that came from the JSON url. Each entry in the JSON has it's own id like "azpzodja."

If I go to http://localhost/index.php?dev-tracker/azpzodja.440, then it brings me to the index.

I have the view action in the public controller:
Code:
public function actionView(ParameterBag $params)
{
    $entry = $this->assertEntryExists($params->id);

    $viewParams = [
        'entry' => $entry
    ];

    return $this->view('AH\DevTracker:DevTracker\View', 'ah_dev_tracker_view', $viewParams);
}

Thank you to anyone who can help
 
Back
Top Bottom