Jump to content

teppo

PW-Moderators
  • Posts

    2,960
  • Joined

  • Last visited

  • Days Won

    90

Community Answers

  1. teppo's post in Bootstrapping ProcessWire gives an error on image resize??? was marked as the answer   
    What you've got there is an instance of Pageimages, i.e. multiple Pageimage objects. Note that when bootstrapping ProcessWire you've got output formatting off, which means that this is what you typically get when requesting the value of an image field.
    If you just want to grab the first image and resize it, use first():
    echo $page->images->first()->size(100,100); If you're unsure about how many images there will be, you'll need to iterate over them with foreach or something similar. Like @horst pointed out, if you provide us with a bit more context, it'll be easier to help you out.
  2. teppo's post in Exclude certain children based on template was marked as the answer   
    $categories = $pages->get(1077)->children("template!=exclude")->shuffle();

  3. teppo's post in PW 3 devns CLI not recognising pw classes was marked as the answer   
    As far as I can tell, there are two solutions to your issue:
    <?php namespace ProcessWire; require 'index.php'; var_dump(new Page()); ... or:
    <?php require 'index.php'; var_dump(new \ProcessWire\Page());
  4. teppo's post in Adding content to top of admin field was marked as the answer   
    If those values come from other fields, you could always use the Textarea Markup module to achieve this.
  5. teppo's post in Problems with addHookAfter WireHttp::send was marked as the answer   
    The problem is very likely something not visible in your post above. Testing with the setup below, I had no issues getting this to work under latest version of the devns branch:
    <?php # /site/modules/TestHook.module class TestHook extends WireData implements Module { public static function getModuleInfo() { return array('autoload' => true); } public function init() { $this->addHookAfter('WireHttp::send', $this, 'hookCheckAuth'); } public function hookCheckAuth(HookEvent $event) { die("dying"); } } <?php # /site/templates/basic-page.php $http = new \ProcessWire\WireHttp; $http->send('/');
  6. teppo's post in Get Value from Field was marked as the answer   
    Labels are field-specific, i.e. generally they apply everywhere the field is used. Values on the other hand are always page-specific, i.e. each page has a separate value for each field.
    This is why you should be asking for the value of this field from a specific page. For current page you can use $page, and for other pages you can, for an example, do this: $pages->get('/page/url/').
    <?php echo $page->caracteristicas_superficie; ?> <?php echo $pages->get('/page/url/')->caracteristicas_superficie; ?>Or: <?php echo $page->get('caracteristicas_superficie'); ?> <?php echo $pages->get('/page/url/')->get('caracteristicas_superficie'); ?>I would suggest taking a proper look at https://processwire.com/api/ before stumbling any further. The basic stuff is all explained there
  7. teppo's post in Test if Page field is multiple or single was marked as the answer   
    Not sure if I'm getting your question right, but why not simply check if the value of the field is an instance of PageArray:
    if ($page->field_name instanceof PageArray) { // iterate }
  8. teppo's post in Weird image->httpUrl behavior creating links on wrong domain was marked as the answer   
    Disregarding your particular issue (which might mean that you serve this site with multiple domains, could be a caching issue, could be connected to your httpHosts setting in /site/config.php, or be something entirely different) for a moment, do you really need httpUrl, or could you use url instead?
    Relative URLs wouldn't have this issue at all. Just saying.
  9. teppo's post in Another guy in trouble with search pagination was marked as the answer   
    @heldercervantes: actually, it looks like you're missing one part, which would be $input->whitelist('q', $q). Check out the code (and comments) here for an explanation.
    Whitelisted GET params are automatically included in the pagination.
  10. teppo's post in strange /?/ repeated requests crashing site was marked as the answer   
    Take a look at this topic, and particularly Soma's answer there. The question mark means that ProcessWire doesn't yet know which page was requested. Either your site is getting more traffic than the (MySQL) server can handle, or there's something else going wrong.
    Might be worthwhile to take a closer look at Apache logs if you want to find out what exactly is going on traffic-wise. Additionally checking MySQL slow queries log (if you've got that enabled and can access it) could provide some sort of insight 
  11. teppo's post in Is there a way to convert a selector in SQL using PW engine? was marked as the answer   
    None that I'm aware of. Of course you can always use PageFinder for this, but it's going to look a bit hacky:
    $selectors = new Selectors("template=blog-post, limit=5, sort=name"); $pagefinder = new PageFinder(); $options = array('returnVerbose' => true); $sql = $pagefinder->getQuery($selectors->getArray(), $options)->getQuery(); // .. and so on, depending on what exactly you're looking for
  12. teppo's post in Unusual URL path showing up in Google Analytics - anyone else seen this? was marked as the answer   
    Yeah, that explains it perfectly. In fact, if I open www.thesharktankproducts.com/products/ I end up at index.php?it=products/. The problem is that you're doing your own custom redirect after ProcessWire has already rewritten the URL to index.php?it=some-url 
    You might want to take a look at ProcessWire's default .htaccess rules. There's similar www redirect there, though it works the other way around: non-www URLs are prefixed with www. The important thing is the position of this rule in the .htaccess file; you'll want to add your custom rule to similar position.
    Generally speaking, though, redirects like that should be placed as early as possible in the .htaccess file, since that's the most efficient way: you don't want to parse any extra rules, if there's going to be a redirect that makes it necessary to go through that very same process again anyway.
  13. teppo's post in Is there a notes/description field module? was marked as the answer   
    Also: http://modules.processwire.com/modules/inputfield-textarea-markup/. Self-promotion, again
  14. teppo's post in problem with getting page with pageid was marked as the answer   
    @mrkhan, there seems to be a slight misunderstanding here. Your $pid isn't page ID, it's a Page. You don't need $pages->get() to grab the page, you already have it.
    // title of the page echo $page->page_side_menu->title; // URL of the page echo $page->page_side_menu->url; // body field of the page (assuming that it has field called body) echo $page->page_side_menu->body; // .. or, if you really want to store it in $paged first: $paged = $page->page_side_menu; echo $paged->title; See what I mean?
  15. teppo's post in What is the last (or first) child in physical order? was marked as the answer   
    If you want results in a specific order, use "sort":
    $pages->find('parent=/blog/, sort=sort')->last(); // and if you want just one item, don't forget limit // (or use get(), and check viewability separately) $pages->find('parent=/blog/, sort=sort, limit=1')->last();
  16. teppo's post in navigate prev and next was marked as the answer   
    NullPage is an object, kind of a placeholder for non-existing page, and that is very different from NULL (PHP's way of saying that a variable has no value at all). They're not the same thing, so NullPage == null is not true. It's that simple, really.
  17. teppo's post in Redirection but not as I know it was marked as the answer   
    This sort of thing is rather easy to set up using mod_rewrite too, and if there's a lot of content, that's often only sensible option. This thread might be of help to you, the problem is essentially the same. Note, though, that you should be careful with 301 redirects -- since in theory they're "permanent" browsers can cache them for a very long time. For temporary, short-term solution use 302's instead.
  18. teppo's post in image thumb access? was marked as the answer   
    If you need an image (or thumb) for each individual member, then using it within foreach loop is just fine.
    Also, size() creates the thumb, but you'll still have to call the URL of said thumb; $member->image->size(100,100)->url etc.
  19. teppo's post in Add User Edit Permission To A Page was marked as the answer   
    This isn't exactly what I had in mind (thought you had those users already, just wanted to give them permission to edit a page), but there's an example of creating an user at the bottom of the $user page.
    If you just want to use Page Edit Per User and grant specific user access to a page via API, that looks more like this:
    // I'm assuming that you're already creating pages via API; not going into detail about that.. $p = new Page; $p->template = $templates->get("some-template"); $p->parent = $pages->get("/some-parent/"); $p->name = "some-page-name"; $p->save(); // give current current user access to edit previously created page $user->editable_pages->add($p); $user->save('editable_pages');
  20. teppo's post in page field values was marked as the answer   
    $page->pattern_type should return an instance of PageArray, which won't have field "title" -- or any other fields for that matter. PageArrays are collections of Pages, and Pages are the ones with fields (and in any case you wouldn't be able to iterate title field as in your example).
    Try iterating Pages contained in that PageArray, like this:
    foreach ($page->pattern_type as $pt) { echo $pt->title; }
  21. teppo's post in Only getting numeric id from field was marked as the answer   
    Sounds a bit like "collection" might be a Page type field. If that's the case, try something like $page->collection->title (if it's set to contain one Page) or $page->collection->first()->title (if it's set to contain multiple Pages).
  22. teppo's post in contents of a page array was marked as the answer   
    There's a bit of difference between operators "*=" and "%=". Quoting from the documentation:
     
     
    In many cases %= is more "forgiving" and generally just finds more results than *=, so I'd try if that helps. It might also make more sense to search by name, which is often identical to title, just all lowercase characters and spaces etc. converted to dashes:
     
    // find with name and use %= (SQL LIKE oeprator): $english = $pages->get("template=language, name%=english"); // alternative approach if you know that there's "english" at the *beginning* of the name: $english = $pages->get("template=language, name^=english");
  23. teppo's post in Permanent login for an iOS Web App was marked as the answer   
    You might want to check out Login Persistent, perhaps that could be of help here? I've no experience of iOS Web Applications and no idea how they work, so this might be completely unrelated too
  24. teppo's post in Find page name when deleting it permanently from trash was marked as the answer   
    @zyON: at that point the original name, one without "pageid_" prefix, is nowhere to be found. Hence you actually need to strip the prefix to get the original name.
    Take a look at how ProcessWire itself does this when restoring pages from trash: https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Pages.php#L1006.
  25. teppo's post in Empty a page field via frontend was marked as the answer   
    Values for page type fields that store multiple values are PageArrays. Since PageArray extends WireArray, you can use it's methods here -- such as removeAll().
    Running $page->countries->removeAll() before adding new items should do the trick. It'll clear the PageArray and you can start from clean slate, so to speak. You should also take a look at other WireArray and PageArray methods, as those provide some nice ways to manage stored items etc.
×
×
  • Create New...