Jump to content

Zeka

Members
  • Posts

    1,065
  • Joined

  • Last visited

  • Days Won

    11

Posts posted by Zeka

  1. Hi, community. 

    I'm using a hook to path to change URL of some pages.

    	wire()->addHook("Page(template=services-category|service)::path", function($e) {
    		$page = $e->object;
    		$e->return = "/{$page->name}/";
    	});

    Then in template where I enable URL segments, I use code like 

    if (input()->urlSegment(1)) {
    	$pagename = input()->urlSegment(1);
    	$match = pages()->findOne("template=services-category|service, name={$pagename}");
    	if (!$match->id) throw new Wire404Exception();
    	echo $match->render();
    	return $this->halt();
    }

    Typical. I have the template file for "service" template, so I can use $page->render() and because of it, these pages are also accessible from their old URLs.

    So my question is how to prevent these pages being accessible from their original URLs without removing template file for their template?  

    Eugene. 

  2.  try {
                    $form->processInput($input->post);
                    $session->CSRF->validate();
                }
                            
                catch (WireCSRFException $e) {
    
                    echo "Processing aborted. Suspected attempt to forge the submission. IP logged." . $e->getMessage();
                    /*
                     * Some code to execute whenever the token gets spoofed
                     * Like sending a notification mail with the spoofer's IP address
                     */
    
                    die(); // live a great life and die() gracefully.
                }

    or

    // when processing form (POST request), check to see if token is present
    if($session->CSRF->hasValidToken()) {
      // form submission is valid
      // okay to process
    } else {
      // form submission is NOT valid
      throw new WireException('CSRF check failed!');
    }

     

    • Like 1
  3. How results are sorted if you don't specify a "sort" in your selector

    In $page->children() and $page->siblings() the results are automatically sorted by the page's default sort field that you specify in the admin. If not specified in the admin, the pages will be sorted by the order they are placed in the admin. This behavior can be overridden by specifying your own "sort=[property]". With $pages->find() and $page->find(), if you don't specify your own "sort=[property]", the results are sorted according to MySQL's text searching relevance. If no text searches are performed in your find(), the results are unsorted. As a result, it is generally a good idea to include a "sort=[property]" when using $pages->find(), especially if you care about the order and your find() operation is not text/relevance related.

    • Like 2
  4. Hi @kongondo

    I have this setup: 

    • MenuItem1
      • Submenuitem_01( allowed children)
      • SubmenuItem_02 ( allowed children)
    • MenuItem2
      • Submenuitem_03 ( allowed children)
      • SubmenuItem_02 ( allowed children)

    I'm using getMenuItems for building my menu, but the issue is that I get children of Submenuitem_02 as children only of the last Submenuitem_02 ( parent_id  =  id of the last Submenuitem_02 ), but I expected that I will get duplications of children pages with right parent_id for every Submenuitem_02

    Of course, I can get children in my custom function but I think that in this case, getMenuItems doesn't work as expected and could be improved.

    What do you think about it? 

    Thanks, Eugene. 

  5. Hi.

    I have found very useful to store some data like translations and some global settings inside $wire object by

    $wire->set("custom", $custom);

    What are pros and cons of using it?

    And there is the thing in the docs that I can't understand:

    Injection of dependencies to Wire derived objects:
    $this->wire($widgets);

    Can somebody explain what are dependencies in this case? 

    Thanks, Eugene. 

  6. Hi @kongondo

    Thank you for so great module!

    I use 0.1.7 version of module and get 

    PHP Notice: Array to string conversion in ...\ProcessMenuBuilder\MarkupMenuBuilder.module:922

    Here is how I use it

    $menu_page = pages(1023);
    if($lang_name == "ukrainian") {
        $menu_page = pages(1024);
    }
    
    $menu = $menuModule->getMenuItems($menu_page, 1, [
        "current_class_level" => 2
    ]);

    Changing this line

    $menuItems = '';

    to 

    $menuItems = array();

    fixes it. 

    Am I missing something? 

×
×
  • Create New...