magento 2 custom collection pager with dynamic urlSetup version for module 'Sample_CustomController' is not specifiedI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2: How to override newsletter Subscriber modelMagento 2: toolbar url problems in custom module with custom routerHow to solve Front controller reached 100 router match iterations in magento2I have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.3 Can't view module's front end page output?Magento 2 How to remove price filter from category if module is enable?Getting Errors after MySQL database importWarning: session_regenerate_id(): Session object destruction failed. on Magento 2 Checkout

What is "oversubscription" in Networking?

How did Lefschetz do mathematics without hands?

Who are these Discworld wizards from this picture?

Prime parity peregrination

What are good ways to spray paint a QR code on a footpath?

What does grep -v "grep" mean and do?

Boolean Difference with Offset?

Different budgets within roommate group

What game is this character in the Pixels movie from?

Balanced parentheses using STL C++

What's the rule for a natural 20 on a Perception check?

In native German words, is Q always followed by U, as in English?

Using a concentration spell on top of another spell from another spell list?

Why do we use a cylinder as a Gaussian surface for infinitely long charged wire?

Handling a player (unintentionally) stealing the spotlight

Company threatening to call my current job after I declined their offer

Should fiction mention song names and iPods?

Find first and last non-zero column in each row of a pandas dataframe

How can a valley surrounded by mountains be fertile and rainy?

Why is there "que" in this sentence?

Does any Greek word have a geminate consonant after a long vowel?

Why were the first airplanes "backwards"?

Most important new papers in computational complexity

Why do I need two parameters in an HTTP parameter pollution attack?



magento 2 custom collection pager with dynamic url


Setup version for module 'Sample_CustomController' is not specifiedI created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?Magento 2: How to override newsletter Subscriber modelMagento 2: toolbar url problems in custom module with custom routerHow to solve Front controller reached 100 router match iterations in magento2I have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.3 Can't view module's front end page output?Magento 2 How to remove price filter from category if module is enable?Getting Errors after MySQL database importWarning: session_regenerate_id(): Session object destruction failed. on Magento 2 Checkout






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I use backend option to set an url for my page, now i want to add pager to that page:



$pager = $this->getLayout()
->createBlock(
'MagentoThemeBlockHtmlPager',
'module.custom.pager'
)->setAvailableLimit(array(2=>2))
->setShowPerPage(true)
->setCollection(
$this->getCustomCollection()
);
$this->setChild('pager', $pager);


this code adds pager but it shows module URL(specified in route.xml) URL if we use pager and not the specified one.



public function match(MagentoFrameworkAppRequestInterface $request)

$path = trim($request->getPathInfo(), '/');
$array = explode('/', $path);
if(strpos($path, $this->getFrontendUrl()) !== false)
$request->setModuleName('modulename')
->setControllerName('index')
->setActionName('index');
if(isset($array[1]))
$request->setParam('param', $array[1]);

else
return false;

return $this->actionFactory->create(
'MagentoFrameworkAppActionForward',
['request' => $request]
);

/**
* @return string
*/
public function getFrontendUrl()
return $this->_scopeConfig->getValue('section/group/customurl', MagentoStoreModelScopeInterface::SCOPE_STORE);



one option which I'm aware of is to use URL rewrites, is there any other way?










share|improve this question



















  • 1





    please explain briefly

    – Rk Rathod
    Jun 19 at 12:52











  • I have url which we set in backend for module, pager uses url specified in routes.xml. need that pager would use url from backend and not from routes.xml

    – Naberd Zendi
    Jun 19 at 13:16











  • added my code to repository: github.com/Naberdz/producttags you can see the problem when you visit tag page and try to use pager.

    – Naberd Zendi
    Jun 19 at 14:58

















0















I use backend option to set an url for my page, now i want to add pager to that page:



$pager = $this->getLayout()
->createBlock(
'MagentoThemeBlockHtmlPager',
'module.custom.pager'
)->setAvailableLimit(array(2=>2))
->setShowPerPage(true)
->setCollection(
$this->getCustomCollection()
);
$this->setChild('pager', $pager);


this code adds pager but it shows module URL(specified in route.xml) URL if we use pager and not the specified one.



public function match(MagentoFrameworkAppRequestInterface $request)

$path = trim($request->getPathInfo(), '/');
$array = explode('/', $path);
if(strpos($path, $this->getFrontendUrl()) !== false)
$request->setModuleName('modulename')
->setControllerName('index')
->setActionName('index');
if(isset($array[1]))
$request->setParam('param', $array[1]);

else
return false;

return $this->actionFactory->create(
'MagentoFrameworkAppActionForward',
['request' => $request]
);

/**
* @return string
*/
public function getFrontendUrl()
return $this->_scopeConfig->getValue('section/group/customurl', MagentoStoreModelScopeInterface::SCOPE_STORE);



one option which I'm aware of is to use URL rewrites, is there any other way?










share|improve this question



















  • 1





    please explain briefly

    – Rk Rathod
    Jun 19 at 12:52











  • I have url which we set in backend for module, pager uses url specified in routes.xml. need that pager would use url from backend and not from routes.xml

    – Naberd Zendi
    Jun 19 at 13:16











  • added my code to repository: github.com/Naberdz/producttags you can see the problem when you visit tag page and try to use pager.

    – Naberd Zendi
    Jun 19 at 14:58













0












0








0








I use backend option to set an url for my page, now i want to add pager to that page:



$pager = $this->getLayout()
->createBlock(
'MagentoThemeBlockHtmlPager',
'module.custom.pager'
)->setAvailableLimit(array(2=>2))
->setShowPerPage(true)
->setCollection(
$this->getCustomCollection()
);
$this->setChild('pager', $pager);


this code adds pager but it shows module URL(specified in route.xml) URL if we use pager and not the specified one.



public function match(MagentoFrameworkAppRequestInterface $request)

$path = trim($request->getPathInfo(), '/');
$array = explode('/', $path);
if(strpos($path, $this->getFrontendUrl()) !== false)
$request->setModuleName('modulename')
->setControllerName('index')
->setActionName('index');
if(isset($array[1]))
$request->setParam('param', $array[1]);

else
return false;

return $this->actionFactory->create(
'MagentoFrameworkAppActionForward',
['request' => $request]
);

/**
* @return string
*/
public function getFrontendUrl()
return $this->_scopeConfig->getValue('section/group/customurl', MagentoStoreModelScopeInterface::SCOPE_STORE);



one option which I'm aware of is to use URL rewrites, is there any other way?










share|improve this question
















I use backend option to set an url for my page, now i want to add pager to that page:



$pager = $this->getLayout()
->createBlock(
'MagentoThemeBlockHtmlPager',
'module.custom.pager'
)->setAvailableLimit(array(2=>2))
->setShowPerPage(true)
->setCollection(
$this->getCustomCollection()
);
$this->setChild('pager', $pager);


this code adds pager but it shows module URL(specified in route.xml) URL if we use pager and not the specified one.



public function match(MagentoFrameworkAppRequestInterface $request)

$path = trim($request->getPathInfo(), '/');
$array = explode('/', $path);
if(strpos($path, $this->getFrontendUrl()) !== false)
$request->setModuleName('modulename')
->setControllerName('index')
->setActionName('index');
if(isset($array[1]))
$request->setParam('param', $array[1]);

else
return false;

return $this->actionFactory->create(
'MagentoFrameworkAppActionForward',
['request' => $request]
);

/**
* @return string
*/
public function getFrontendUrl()
return $this->_scopeConfig->getValue('section/group/customurl', MagentoStoreModelScopeInterface::SCOPE_STORE);



one option which I'm aware of is to use URL rewrites, is there any other way?







magento2 magento2.3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 20 at 4:06









poojan sharma

7071 silver badge10 bronze badges




7071 silver badge10 bronze badges










asked Jun 19 at 12:50









Naberd ZendiNaberd Zendi

698 bronze badges




698 bronze badges







  • 1





    please explain briefly

    – Rk Rathod
    Jun 19 at 12:52











  • I have url which we set in backend for module, pager uses url specified in routes.xml. need that pager would use url from backend and not from routes.xml

    – Naberd Zendi
    Jun 19 at 13:16











  • added my code to repository: github.com/Naberdz/producttags you can see the problem when you visit tag page and try to use pager.

    – Naberd Zendi
    Jun 19 at 14:58












  • 1





    please explain briefly

    – Rk Rathod
    Jun 19 at 12:52











  • I have url which we set in backend for module, pager uses url specified in routes.xml. need that pager would use url from backend and not from routes.xml

    – Naberd Zendi
    Jun 19 at 13:16











  • added my code to repository: github.com/Naberdz/producttags you can see the problem when you visit tag page and try to use pager.

    – Naberd Zendi
    Jun 19 at 14:58







1




1





please explain briefly

– Rk Rathod
Jun 19 at 12:52





please explain briefly

– Rk Rathod
Jun 19 at 12:52













I have url which we set in backend for module, pager uses url specified in routes.xml. need that pager would use url from backend and not from routes.xml

– Naberd Zendi
Jun 19 at 13:16





I have url which we set in backend for module, pager uses url specified in routes.xml. need that pager would use url from backend and not from routes.xml

– Naberd Zendi
Jun 19 at 13:16













added my code to repository: github.com/Naberdz/producttags you can see the problem when you visit tag page and try to use pager.

– Naberd Zendi
Jun 19 at 14:58





added my code to repository: github.com/Naberdz/producttags you can see the problem when you visit tag page and try to use pager.

– Naberd Zendi
Jun 19 at 14:58










1 Answer
1






active

oldest

votes


















0














Fixed my problem by creating custom pager and adjusted getPagerUrl function to match needed result



controller _prepareLayout function to initialize pager:



$pager = $this->getLayout()
->createBlock(
'WemessageProductTagsBlockCustomPager',
'wemessage.tags.pager'
)->setAvailableLimit(array(2=>2))
->setShowPerPage(true)
->setCollection(
$this->getTaggedCollection()
);
$this->setChild('pager', $pager);
$this->getTaggedCollection()->load();


custom pager :



class CustomPager extends MagentoThemeBlockHtmlPager


/**
* @var MagentoFrameworkAppConfigScopeConfigInterface
*/
protected $_scopeConfig;
/**
* @var MagentoStoreModelStoreManagerInterface
*/
protected $_storeManager;

/**
* Constructor
*
* @param MagentoFrameworkViewElementTemplateContext $context
* @param MagentoFrameworkRegistry $registry
* @param WemessageProductTagsModelTagsFactory
* @param array $data
*/
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
MagentoStoreModelStoreManagerInterface $storeManager,
array $data = []
)
parent::__construct($context, $data);
$this->_scopeConfig = $scopeConfig;
$this->_storeManager = $storeManager;


/**
* @return string
*/
public function getFrontendSlug()
return $this->_scopeConfig->getValue('producttags/options/tagslug', MagentoStoreModelScopeInterface::SCOPE_STORE);


/**
* Retrieve page URL by defined parameters
*
* @param array $params
* @return string
*/
public function getPagerUrl($params = [])

$urlParams = [];
$urlParams['_current'] = true;
$urlParams['_escape'] = true;
$urlParams['_use_rewrite'] = true;
$urlParams['_fragment'] = $this->getFragment();
$urlParams['_query'] = $params;
return str_replace('producttag/index/index', $this->getFrontendSlug(), $this->getUrl($this->getPath(), $urlParams)); //producttag defined in routes.xml







share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f278886%2fmagento-2-custom-collection-pager-with-dynamic-url%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Fixed my problem by creating custom pager and adjusted getPagerUrl function to match needed result



    controller _prepareLayout function to initialize pager:



    $pager = $this->getLayout()
    ->createBlock(
    'WemessageProductTagsBlockCustomPager',
    'wemessage.tags.pager'
    )->setAvailableLimit(array(2=>2))
    ->setShowPerPage(true)
    ->setCollection(
    $this->getTaggedCollection()
    );
    $this->setChild('pager', $pager);
    $this->getTaggedCollection()->load();


    custom pager :



    class CustomPager extends MagentoThemeBlockHtmlPager


    /**
    * @var MagentoFrameworkAppConfigScopeConfigInterface
    */
    protected $_scopeConfig;
    /**
    * @var MagentoStoreModelStoreManagerInterface
    */
    protected $_storeManager;

    /**
    * Constructor
    *
    * @param MagentoFrameworkViewElementTemplateContext $context
    * @param MagentoFrameworkRegistry $registry
    * @param WemessageProductTagsModelTagsFactory
    * @param array $data
    */
    public function __construct(
    MagentoFrameworkViewElementTemplateContext $context,
    MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
    MagentoStoreModelStoreManagerInterface $storeManager,
    array $data = []
    )
    parent::__construct($context, $data);
    $this->_scopeConfig = $scopeConfig;
    $this->_storeManager = $storeManager;


    /**
    * @return string
    */
    public function getFrontendSlug()
    return $this->_scopeConfig->getValue('producttags/options/tagslug', MagentoStoreModelScopeInterface::SCOPE_STORE);


    /**
    * Retrieve page URL by defined parameters
    *
    * @param array $params
    * @return string
    */
    public function getPagerUrl($params = [])

    $urlParams = [];
    $urlParams['_current'] = true;
    $urlParams['_escape'] = true;
    $urlParams['_use_rewrite'] = true;
    $urlParams['_fragment'] = $this->getFragment();
    $urlParams['_query'] = $params;
    return str_replace('producttag/index/index', $this->getFrontendSlug(), $this->getUrl($this->getPath(), $urlParams)); //producttag defined in routes.xml







    share|improve this answer



























      0














      Fixed my problem by creating custom pager and adjusted getPagerUrl function to match needed result



      controller _prepareLayout function to initialize pager:



      $pager = $this->getLayout()
      ->createBlock(
      'WemessageProductTagsBlockCustomPager',
      'wemessage.tags.pager'
      )->setAvailableLimit(array(2=>2))
      ->setShowPerPage(true)
      ->setCollection(
      $this->getTaggedCollection()
      );
      $this->setChild('pager', $pager);
      $this->getTaggedCollection()->load();


      custom pager :



      class CustomPager extends MagentoThemeBlockHtmlPager


      /**
      * @var MagentoFrameworkAppConfigScopeConfigInterface
      */
      protected $_scopeConfig;
      /**
      * @var MagentoStoreModelStoreManagerInterface
      */
      protected $_storeManager;

      /**
      * Constructor
      *
      * @param MagentoFrameworkViewElementTemplateContext $context
      * @param MagentoFrameworkRegistry $registry
      * @param WemessageProductTagsModelTagsFactory
      * @param array $data
      */
      public function __construct(
      MagentoFrameworkViewElementTemplateContext $context,
      MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
      MagentoStoreModelStoreManagerInterface $storeManager,
      array $data = []
      )
      parent::__construct($context, $data);
      $this->_scopeConfig = $scopeConfig;
      $this->_storeManager = $storeManager;


      /**
      * @return string
      */
      public function getFrontendSlug()
      return $this->_scopeConfig->getValue('producttags/options/tagslug', MagentoStoreModelScopeInterface::SCOPE_STORE);


      /**
      * Retrieve page URL by defined parameters
      *
      * @param array $params
      * @return string
      */
      public function getPagerUrl($params = [])

      $urlParams = [];
      $urlParams['_current'] = true;
      $urlParams['_escape'] = true;
      $urlParams['_use_rewrite'] = true;
      $urlParams['_fragment'] = $this->getFragment();
      $urlParams['_query'] = $params;
      return str_replace('producttag/index/index', $this->getFrontendSlug(), $this->getUrl($this->getPath(), $urlParams)); //producttag defined in routes.xml







      share|improve this answer

























        0












        0








        0







        Fixed my problem by creating custom pager and adjusted getPagerUrl function to match needed result



        controller _prepareLayout function to initialize pager:



        $pager = $this->getLayout()
        ->createBlock(
        'WemessageProductTagsBlockCustomPager',
        'wemessage.tags.pager'
        )->setAvailableLimit(array(2=>2))
        ->setShowPerPage(true)
        ->setCollection(
        $this->getTaggedCollection()
        );
        $this->setChild('pager', $pager);
        $this->getTaggedCollection()->load();


        custom pager :



        class CustomPager extends MagentoThemeBlockHtmlPager


        /**
        * @var MagentoFrameworkAppConfigScopeConfigInterface
        */
        protected $_scopeConfig;
        /**
        * @var MagentoStoreModelStoreManagerInterface
        */
        protected $_storeManager;

        /**
        * Constructor
        *
        * @param MagentoFrameworkViewElementTemplateContext $context
        * @param MagentoFrameworkRegistry $registry
        * @param WemessageProductTagsModelTagsFactory
        * @param array $data
        */
        public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoStoreModelStoreManagerInterface $storeManager,
        array $data = []
        )
        parent::__construct($context, $data);
        $this->_scopeConfig = $scopeConfig;
        $this->_storeManager = $storeManager;


        /**
        * @return string
        */
        public function getFrontendSlug()
        return $this->_scopeConfig->getValue('producttags/options/tagslug', MagentoStoreModelScopeInterface::SCOPE_STORE);


        /**
        * Retrieve page URL by defined parameters
        *
        * @param array $params
        * @return string
        */
        public function getPagerUrl($params = [])

        $urlParams = [];
        $urlParams['_current'] = true;
        $urlParams['_escape'] = true;
        $urlParams['_use_rewrite'] = true;
        $urlParams['_fragment'] = $this->getFragment();
        $urlParams['_query'] = $params;
        return str_replace('producttag/index/index', $this->getFrontendSlug(), $this->getUrl($this->getPath(), $urlParams)); //producttag defined in routes.xml







        share|improve this answer













        Fixed my problem by creating custom pager and adjusted getPagerUrl function to match needed result



        controller _prepareLayout function to initialize pager:



        $pager = $this->getLayout()
        ->createBlock(
        'WemessageProductTagsBlockCustomPager',
        'wemessage.tags.pager'
        )->setAvailableLimit(array(2=>2))
        ->setShowPerPage(true)
        ->setCollection(
        $this->getTaggedCollection()
        );
        $this->setChild('pager', $pager);
        $this->getTaggedCollection()->load();


        custom pager :



        class CustomPager extends MagentoThemeBlockHtmlPager


        /**
        * @var MagentoFrameworkAppConfigScopeConfigInterface
        */
        protected $_scopeConfig;
        /**
        * @var MagentoStoreModelStoreManagerInterface
        */
        protected $_storeManager;

        /**
        * Constructor
        *
        * @param MagentoFrameworkViewElementTemplateContext $context
        * @param MagentoFrameworkRegistry $registry
        * @param WemessageProductTagsModelTagsFactory
        * @param array $data
        */
        public function __construct(
        MagentoFrameworkViewElementTemplateContext $context,
        MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
        MagentoStoreModelStoreManagerInterface $storeManager,
        array $data = []
        )
        parent::__construct($context, $data);
        $this->_scopeConfig = $scopeConfig;
        $this->_storeManager = $storeManager;


        /**
        * @return string
        */
        public function getFrontendSlug()
        return $this->_scopeConfig->getValue('producttags/options/tagslug', MagentoStoreModelScopeInterface::SCOPE_STORE);


        /**
        * Retrieve page URL by defined parameters
        *
        * @param array $params
        * @return string
        */
        public function getPagerUrl($params = [])

        $urlParams = [];
        $urlParams['_current'] = true;
        $urlParams['_escape'] = true;
        $urlParams['_use_rewrite'] = true;
        $urlParams['_fragment'] = $this->getFragment();
        $urlParams['_query'] = $params;
        return str_replace('producttag/index/index', $this->getFrontendSlug(), $this->getUrl($this->getPath(), $urlParams)); //producttag defined in routes.xml








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jun 21 at 9:02









        Naberd ZendiNaberd Zendi

        698 bronze badges




        698 bronze badges



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f278886%2fmagento-2-custom-collection-pager-with-dynamic-url%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?