Jump to content

siilak

Members
  • Posts

    18
  • Joined

  • Last visited

Posts posted by siilak

  1. User registration example:

    public static function addUser($data) {
        RestApiHelper::checkAndSanitizeRequiredParameters($data, [
          'username|selectorValue',
          'password|string',
          'email|text',
        ]);
    
        $item = new User();
        $item->setOutputFormatting(false);
        $item->name = $data->username;
        $item->pass = $data->password;
        $item->email = $data->email;
        $item->addRole('guest');
        $item->save();
        
    }

     

    • Like 3
  2. On 12/24/2017 at 11:11 PM, pwuser1 said:

    I want to make interactive websites with ajax as well.

    There are nice and easy examples in GitHub for using Processwire Rest API with Vue / Angular / React

    Whit them you can easily build nice websites with smooth page render, navigation and more.

  3. I also made function for Page Reference field in pagefields.php.

    private function getReference($p, $apiField) {
            $p->of(false);
            $pages = $apiField->name;
            $id = $p->get($pages);
            $apiFields = [];
    
            if ($id) {
                $output[$pages]['title'] = $id->title;
                $output[$pages]['name'] = $id->name;
                $output[$pages]['url'] = $id->url;
                return $output;
            }
            return $apiFields;
        }

    Then add this to function "getAllFields"

    else if ($apiFieldType instanceof FieldtypePage) {
                    $apiFields = array_merge($this->getReference($p, $apiField), $apiFields);
                }

     

    • Like 1
  4. There is a solution for filefield. In pagefields.php file add after image_fields

    'file_fields' => [ 'fields' => ['description', 'httpUrl'], ],

    Then after private function getImages

    private function getFiles($p, $fld)
        {
            $fldName = $fld->name;
            $files = [];
            $i = 0;
            foreach ($p[$fldName] as $file) {
    
                $fileConf = $this->conf['file_fields'];
    
                foreach ($fileConf['fields'] as $fileField) {
                    $files[$fldName][$i]['file'][$fileField] = $file[$fileField];
                }
    
                $i++;
            }
    
            return $files;
        }

    Then make a change for field type  

    	if ($fldType instanceof FieldtypeImage) {
                    $flds = array_merge($this->getImages($p, $fld), $flds);
                } else if ($fldType instanceof FieldtypeFile) {
                    $flds = array_merge($this->getFiles($p, $fld), $flds);
                } else if ($fldType instanceof FieldtypeRepeater) {
                    $flds = array_merge($this->getRepeaters($p, $fld), $flds);
                } else {
                    $flds = array_merge($this->getFields($p, $fld), $flds);
                }

     

    • Thanks 1
  5. 6 hours ago, microcipcip said:

    @siilak Unfortunately I think I did not test the REST API with the file type, only with images. I think it requires changes to work with video type.
    As I said in the first post in this thread

    Thank you for a answer. In pagefields.php are good solution for a images. I also trying to write a file field part.

  6. I added file field called "video". Result in API is 

    "video": [
            {
                "data": "filename.mp4",
                "description": "[\"\"]",
                "modified": "2018-04-22 23:08:59",
                "created": "2018-04-22 23:08:59",
                "filedata": null
            }
        ],

     

    But how I can show "data" field as a httpUrl with full path "/site/assets/files/PageID/filename.mp4"

  7. One good thing with a PW is you not need any modules to build something.
    For social media Icons you can use textfields and displaying is pure php and font awesome icons or with some front end framework (Foundation, bootstrap, uikit etc).

    For example:

    Make new field called instagram and you can display like this with Font Awesome:

    <?php if ($page->instagram) { ?>
        <a href="http://instagram.com/<?php echo $page->instagram; ?>" target="_blank"><i class="fa fa-2x fa-instagram"></i></a>
    <?php } ?>

     

  8. I made a template for add new page. Page is added under home page.

    <?php include('./_header.php'); ?>
    <?php
    
    // Load FormHelper module and also set wire('fh') variable
    $fcm = $modules->get('FrontendContentManager');
    
    // add a new page based on a template and a parent object
    $parent = $pages->get('name=home');
    $form = $fcm->add($parent, $parent->template);
    
    // jsConfig needed by ckeditor
    echo $fcm->JsConfig();
    
    // outpunt needed scripts for inputfield modules, ...
    foreach ($config->styles as $file) { echo "<link type='text/css' href='$file' rel='stylesheet' />\n"; }
    foreach ($config->scripts as $file) { echo "<script type='text/javascript' src='$file'></script>\n"; }
    
    ?>
        <div class="uk-container uk-container-center">
            <h1><?php echo $page->title; ?></h1>
            <?php
    
            // output the forom
            echo $form;
    
            ?>
        </div>
    
    <?php include('./_footer.php'); ?>
    

    and only result I get is this. Any help?

    https://www.dropbox.com/s/2mwtksa20qxs5bk/Screen%20Shot%202016-03-10%20at%2011.52.48.png?dl=0

    • Like 1
  9. Hi

    I can dsplay post author username 

    echo "Posted by ";
    echo $page->createdUser->name;
    

    Its ok, but I also want to print user images

    foreach ($page->createdUser->images as $userimage) {
       $thumb = $userimage->size(480, 480);
       echo "<img src='{$thumb->url}' alt='{$thumb->description}' />";
    }
    

    But its not working. Any help?

×
×
  • Create New...