XF 2.2 Routes and Params

Taylor J

Well-known member
I'm currently having some issues getting a id from a param.

I'm attempting to grab the blog_id from the following localhost/userblogs/blog/first-blog.2/add but in the ParameterBag variable I am getting blog_id back as 0. I'm wondering if this is due to how I have the routes setup?
1722100596537.webp
1722100652051.webp

This is currently on my actionBlogAddPreview function for the editors preview bbcode.
 
I should add I have been having this issue with more than just this singular instance.

I have cheated a way to get the blog_id for the save process on a blog post by using a hidden input with
<xf:hiddenval name="blog_id" autocomplete="off">{$blogId}</xf:hiddenval> and I can use that again here but I would rather use it through the params to keep the templates a bit cleaner.
 
Does your preview URLs include the blog ID correctly? If you inspect the HTML, it should be data-preview-url="/userblogs/blog/first-blog.2/add-preview". I see in your other post that you're passing $blogPost into {{ link(...) }} even though it presumably doesn't exist yet?
 
Does your preview URLs include the blog ID correctly? If you inspect the HTML, it should be data-preview-url="/userblogs/blog/first-blog.2/add-preview". I see in your other post that you're passing $blogPost into {{ link(...) }} even though it presumably doesn't exist yet?
When viewing the page's source it's showing up as
data-preview-url="/userblogs/blog/0/add-preview"

But when inspecting using chromes dev tools it's showing as the following
1722259747748.webp

$blogPost at that time was/is created and does exist. I'm actually having another routing issue (i think, can't get {{ link("userblogs/post", $blogPost) }} to work as it is linking to localhost/userblogs/post without an id attached) which I need to make another post on to get help with that as well lol.
 
Realized that the baseURI is not what I would need to look at

1722262523665.webp

so it's not including the id correctly which I am guessing is also the issue/cause for the above link issue I described.

For the preview function, could this be because I'm passing in a non saved/newly created entity?

PHP:
 public function actionBlogAddPreview(ParameterBag $params)
    {
        $message = $this->plugin('XF:Editor')->fromInput('message');
        $blogId = $this->filter('blog_id', 'int');
        /** @var \TaylorJ\UserBlogs\Entity\Blog $blog */
        $blog = $this->assertBlogExists($blogId);
        $blogPost = $blog->getNewBlogPost();

        $tempHash = $this->filter('attachment_hash', 'str');
        /** @var \XF\Repository\Attachment $attachmentRepo */
        $attachmentRepo = $this->repository('XF:Attachment');
        $attachmentData = $attachmentRepo->getEditorData('taylorj_userblogs_post', $blogPost, $tempHash);
        $attachments = $attachmentData['attachments'];

        return $this->plugin('XF:BbCodePreview')->actionPreview(
            $message,
            'blog_post',
            \XF::visitor(),
            $attachments
        );
    }
PHP:
public function getNewBlogPost()
    {
        $blogPost = $this->_em->create('TaylorJ\UserBlogs:BlogPost');
        $blogPost->blog_id = $this->blog_id;

        return $blogPost;
    }
 
So it does turn out that the way I had my routes setup for blogPosts was a bit off and now the issue from post #4 above where the link builder wasn't adding the post id but I've since figured that out.
 
Back
Top Bottom