Jump to content

kixe

Members
  • Posts

    803
  • Joined

  • Last visited

  • Days Won

    10

Posts posted by kixe

  1. @Jan Romero

    $page->parents("parent=$foo") //or
    $page->parentsUntil("parent=$foo")

    will return a pageArray.
     

    $page->closest("parent=$foo")

    will include foo too.

    $page->parent("parent=$foo")

    yes thats the best solution. Never used this as a method. Thanks! :rolleyes:
     

    @matjazp
    You should use Jan Romeros Solution like:

    $page->parent("parent=/foo/") // searching for the name of parent
    $page->parent("parent=1022") // searching for the id of parent
    
    • Like 2
  2. $page->rootParent returns foo of course.

    $page->rootParent returns Home of course. :rolleyes:

    this should work

            $p = $page;
            while($p->parentID != 1) {
                $p = $p->parent;
            }
    

    Edit: better: Jan Romeros solution (Thanks)

    $page->parent("parent=/foo/")
    
  3. @BernhardB & Marty
    You can install the module via Soma's Modules Manager or download it manually and put it in the modules folder. This should work. I will try to fix installation with the 'Download and Install' option in PW.

    1 hour later:

    I could fix it. Should work now. Thank you for reporting.

    • Like 2
  4. or use processwire's new automatic page name feature (i'm using it a lot)..

    @macrura

    Ahh, thats what you are talking about

    For everybody:

    If you want to use this feature you have to create a new field of fieldtype PageTable.

    'Automatic Page Name Format' could be set under the 'Input' Tab.

    Since it is quite unlikely that the same page name is generated your example will work, but it is not a clean solution.

    Edit: Forget about the preceding line :rolleyes:

    I tried it out again and I have to correct myself again.

    Not good, because you will get an mysql error if you do it more than one time

    $page = new Page();
    $page->parent = 'parentname';
    $page->template = 'templatename';
    $page->name = 'foo';
    $page->save();

    Better, because name will be autogenerated unique.

    $page = new Page();
    $page->parent = 'parentname';
    $page->template = 'templatename';
    $page->title = 'foo';
    $page->save();
    
    // or
    
    $page = new Page();
    $page->parent = 'parentname';
    $page->template = 'templatename';
    $page->save();
  5. processwire's new automatic page name feature (i'm using it a lot)..

    $page->name = uniqid();           
    

    @Macrura

    This is not processwires new automatic page name feature. It is a php function which generates a hex converted string of microtime().

    Since it is quite unlikely that the same page name is generated your example will work, but it is not a clean solution.

    Edit: Forget about the preceding line :rolleyes:

    If you want to generate a page by processwires api with a unique page name, you have to could use the add() method. No need to instantiate a page object in your template.

    $parent = 'parentname';
    $template = 'templatename';
    $name = 'foo';
    $pages->add($template,$parent,$name);
    

    With this function you get pages with the title 'foo' and the name 'foo-[n]'. [n] is a counter which makes the name unique.

    You could add a fourth parameter to set other page properties like status or so. The fourth parameter has to be an array.

    $pages->add($template,$parent,$name,array('status'=>1));

    Even if you leave out $page->name = uniqid(); in your example the page will be generated unique.

    In both cases the counter doesn't work properly since it counts all siblings and not only those with the same name.

    • Like 3
  6. And too bad about WordPress if that's what they are using. I don't think they even know about PW. I will have to have a talk with them sometime. :)

    A cute devil in pub turns out to drop a clanger. Never get involved with the devil. I need more Smileys here - in the pub, like glass of beer or so. Back to serious discussion ...

  7. .... It can happen.

    Yes, its not the biggest problem I have. But there should be a way to solve this.

    ProcessLogin.module (v101) gives an error notice if an index.php file from an older pw-version is found in the root directory.

    I played with this one too. I got 6 entries in errors.txt with the same message by one click.

    Two is ok, but six is too much for the best CMS in the world, isn't it?

    :P

    • Like 1
  8. I triggered it by installing and uninstalling.
    This way of log writing (outside a try catch handler) is very rare in core. I found it here:

    FieldtypeComments.module -> after creating a field of type Comments.
    ProcessPageSort.module -> after a page has been moved or after sort settings has been changed under tab 'children'.

    Could you please try out this and tell me if you get duplicated entries in messages.txt? Thanks.

  9. I don't know how the module works. But 'name' is a reserved word for the pagename, which is stored in database table 'pages'. It is not a field like 'title', which is assigned to the page. Try another word than 'name'.

    some other reserved words, which cannot be used for field names:

    • created
    • modified
    • status
    • sort
  10. Consider that users, templates, permissions roles etc. are in fact also pages. Not a good idea to give editors the possibiliy to mess up this.
    Follow Somas recommendation and build some additional custom datetime fields.
    If you need the original values as initial value, you could do this in your template

    $page->of(false);
    $page->set('CustomFieldModified', $page->modified);
    $page->set('CustomFieldCreated', $page->created);
    $page->save();
    
    echo $page->CustomFieldCreated;
  11. During module development I've recognized a strange behaviour. Logfile entries in errors.txt and messages.txt are always created twice. This happened on different servers in different environments with different modules.

    I tested it with this small module:

    <?php
    class Debug extends WireData implements Module {
    
        public function init() {
    	$this->message(microtime(),Notice::logOnly); // same with $this->error()
        }
    }
    
    /*log file entries:
     * 2014-11-07 05:52:14    admin    [...]/admin/module/    0.43575100 1415335934
     * 2014-11-07 05:52:14    admin    [...]/admin/module/    0.43575100 1415335934
    */
    
    

    whereas only a simple entry is generated when I provoke an error an catch it to log with exception handling.

    <?php
    class Debug extends WireData implements Module {
    
    	public function init() {
    		try {
    			foo($bar);
    		} catch(Exception $e) {
    			$this->error($e->getMessage(), Notice::log); 
    		}
    	}
    }
    
    /*log file entry:
     * 2014-11-07 12:45:19  admin  [...]/admin/module/    Error:  Call to undefined function foo() (line 16 of [...]/site/modules/Debug.module)
     */
    

    Happened this before anywhere? Any Experiences with that? Any Ideas? Couldn't find out the reason for that!

  12. @sforsman

    If I understood mr-fan correctly, he would like it to be interpreted as a thousands separator - which it currently is not doing, entering "40.559" would result in "40.56" in the database (if configured to use two-digit decimal precision).

    I think he doesn't want, but the module and/or system does it!

    @mr-fan

    but with more than 3 digits it don't round and set value to 40.559 without position after decimal point....

    Did you try exactly 3 digits? or also more than 3?
     

    Hey guys,
    while playing around with it I get the following results:

    40,558 => 40558 // comma thousands separator
    40,5587 => 40.56 // comma as decimal separator
    40.558 => 40.56 // dot as decimal separator

    40,558.89 => 40558.89 // comma as thousand separator, dot as decimal separator
    40.558,89 => 40558.89 // the other way round
     

  13. Looks like a thousands separator. Check it with:

    $locale_info = localeconv();
    print_r($locale_info);
    
    /* output maybe?
     *
     *
     * Array
     * (
     *  [thousands_sep] => .
     *
     * //other stuff
     * )
     */

    You could change local settings with setlocale() to handle thousands and decimal separators or add the following line to the module

    $value = str_replace(".",",",$value); // there is already something like this. Just uncomment and switch search and replacement string.
    

    Would be nice to have an option in the module which sanitize the input depending on local settings. Or a config field in the module settings?

  14. If you want to make license visible in your custom PW Installation, you could place the following few lines in /wire/modules/Process/ProcessModule.module
     

     if(!empty($moduleInfo['license'])) {
                $hreflicense = (!empty($moduleInfo['hreflicense']))?" - <a href='$moduleInfo[hreflicense]'>".$this->_('read more')."</a>":"";
                $table->row(array($this->_x('License', 'edit'), $moduleInfo['license'].$hreflicense));
            }

    just behind this line (989)

      
     if(!empty($moduleInfo['author'])) $table->row(array($this->_x('Author', 'edit'), $moduleInfo['author']));
    
    

    Now you can set license Name and link to license page in your Modules Info like.

    public static function getModuleInfo() {
    
    	return array(
    			// other settings
    			'license' => 'CC-BY',
    			'hreflicense' => 'http://creativecommons.org/licenses/by/4.0/'
    			);
    }
    

    Would be nice to add this option to core.

     

    post-1246-0-01061500-1413196075_thumb.jp

    • Like 2
×
×
  • Create New...