Jump to content

Search the Community

Showing results for tags 'function'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development


There are no results to display.

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start





Website URL







Found 11 results

  1. So I have a form, once completed, will create new pages. All in all, this is eazy-peezy for me now. I guess I need a bit of guidance on how to actually structure the rest of my code. I thought I could just write a function (_func.php) and pass the fields to the function and let it do its' thing. However, I am kinda hitting a road block when I do it this way. I currently am passing first name, last name, city, state (options field), and making pages based on the first/last names. I guess where I run into some issues is I am trying to check to see if the "page" already exists, and if it does, throw out an error: In the home template: if(isset( $_POST['submit'])) { $firstName =Trim (stripslashes($_POST['firstname'])); $lastName = Trim(stripslashes($_POST['lastname'])); $fullName = $firstName . $lastName; $city = Trim(stripslashes($_POST['city'])); $state = Trim(stripslashes($_POST['state'])); $lowerCaseName = strtolower($fullName); $people = $pages->find("template=person"); foreach ($people as $person) { $checkFirstName = $person->first_name; $checkLastName = $person->last_name; $checkFullName = $checkFirstName . $checkLastName; if ($checkFullName === $lowerCaseName) { echo "<p>" . "This person has already created a page. Please choose a different name." . "</p>"; } else { echo "hey"; processNewPerson(need_to_pass_person_details_to_function); } } // end foreach In _func.php: function processNewPerson($list) { $u = new Page(); $u->template = "person"; $u->parent = wire('pages')->get("/people/"); $u->title = ; $u->first_name = ; $u->last_name = ; $u->state = ; $u->city = ; $u->save(); $u->setOutputFormatting(false); } I am a little unsure of how to actually pass all the information to the template, as well as if this is even the best approach to do this. Would it make more sense to do this in a class, or keep it the way it is?
  2. Okay folks, I am trying to put a character limit on a body of text. I am using the following function, which is place in the _func.php file: function wordLimiter($str, $limit = 120, $endstr = '…'){ $str = strip_tags($str); if(strlen($str) <= $limit) return $str; $out = substr($str, 0, $limit); $pos = strrpos($out, " "); if ($pos>0) { $out = substr($out, 0, $pos); } return $out .= $endstr; } This works just fine on it's own. When placed in Hanna code I get a fatal error, "Call to undefined function wordLimiter()". Code in hanna <?php echo "<div class=\"grid_xs-1\">"; foreach ($pages->find("template=property") as $properties) { //attempt at defining $summ to call wordLimitor() $summ = wordLimiter($properties->body); echo " <div class=\"col-5 card property\"> <a href=\"{$properties->url}\"> <img src=\"{$properties->images->first->size(500,500)->url}\"> </a> </div> <div class=\"col-7\"> <h3>{$properties->title}</h3> <p>{$summ}</p> </div> <div class=\"col-12 grid details\"> <div class=\"col\"> <i class=\"fa fa-dollar\" aria-hidden=\"true\"></i> {$properties->price}</div> <div class=\"col\"> <i class=\"fa fa-bed\" aria-hidden=\"true\"></i> {$properties->bedroom}</div> <div class=\"col\"> <i class=\"fa fa-bath\" aria-hidden=\"true\"></i> {$properties->bathroom} </div> <div class=\"col\"> <i class=\"fa fa-arrows\" aria-hidden=\"true\"></i> {$properties->square_feet} SqFt</div> </div>"; } echo "</div>"; I have also tried placing the function wordLimiter() at the top of the Hanna but it give a different error, " Cannot redeclare wordLimiter() " Am I missing something here? Limitation somewhere?
  3. Hi, I can not run following function code. Help please. Thank you function konular($template,$catPageId,$ColCount,$ColSize,$ImgX,$ImgY) { $x = 0; $category = wire('pages')->get($catPageId); echo '<h2><a href="'.$category->url.'">'.$category->title.'</a></h2>'; $selector= 'template='.$template.', limit=4, sort=random'; $subs = wire('pages')->find("$selector"); foreach ($subs->children as $tree_item) { $item_image=$tree_item->images->first()->size($ImgX,$ImgY); if($x % $ColCount == 0) echo '<div class="row">'; echo '<div class="col-sm-'.$ColSize.'" style="margin-bottom:10px; padding-top:10px;padding-bottom:10px; ">'; echo '<h3><a href="'.$tree_item->url.'">'.$tree_item->title.'</a> </h3>'; echo'<a href="'.$tree_item->url.'"><img src="'.$item_image->url.'" class="img-responsive" style="width:100%"></a>'; echo '<p>'.$tree_item->summary.'</p>'; echo '</div>'; $x++; if($x % $ColCount == 0) echo '</div>'; } } $subs query and category title are working well. But then query results do not appears.
  4. hello to all processwire dudes... I need your help again As you can see in my code i want to call a simple function i the processwire lazy cron hook. Lazy cron works and execute the "echo 30 seconds have passed!" But the function syncMobileDE(); does not return any results. Thanks for your advises! public function init() { $this->addHook('LazyCron::every30Seconds', $this, 'myHook'); } public function myHook(HookEvent $e) { $seconds = $e->arguments[0]; echo "30 seconds have passed!"; $this->syncMobileDE(); } public function syncMobileDE($event) { /** @var Page $page */ $page = $event->arguments(0); if($page->template->name == 'fahrzeugangebot') { $this->listCars(); $this->initDetail(); $this->message("Mobile.de synchronisiert"); } }
  5. I just started trying to clean up an old site, and possible utilize some things I have learned over the past year (especially since my knowledge of php has gotten much better). I was trying to utilize a function to switch out the included header based on the url, but I can't seem to get it right. I started off with: // Include New Header function headerSwap(){ $homepage = $config->httpHost; $header_one = "/page-link-one/"; $header_two = "/page-link-two/"; switch($homepage){ case "/page-link-one/"; include('headerone.inc'); break; case "/page-link-two/"; include('headertwo.inc'); break; default: include('default.inc'); } } However, it seems that it is always using the default case. I tried echoing $homepage, but that doesnt seem to be returning anything. Any help on this would be amazing.
  6. Hey all, For my website I had to make a connection with an external DB. In that DB there are categories of products in different languages, and I want to import these categories in the languages that are available in processwire, I can do that with a very long code but I want to make it shorter. So I wrote a function to get the categories, but the different languages of the category names not, only if I insert the ISO-code hard-code. So here is my code: protected function get_category() { $languages = wire("languages"); try { $prestashp = $this->get_dbPrestashop(); foreach($languages as $language) { $iso_code= $language->name ; $categories = $prestashp->query( "SELECT l.id_lang, l.iso_code, cl.description, cl.name AS category_title, cl.id_shop, c.active, c.id_category, c.id_parent, c.position, cl.link_rewrite FROM ps_category c INNER JOIN ps_category_lang cl ON c.id_category=cl.id_category LEFT JOIN ps_lang l ON cl.id_lang=l.id_lang WHERE c.active='1' AND cl.id_shop='1' AND c.id_parent = '2' ORDER BY c.position "); } }catch(Exception $e) { $this->message('Failed to show categories. Try again later.'); return false; } return $categories; } So in the DB there is Deutsch, Dutch, English(default), Spanish, Italian. And when I edit the template the different languages of the category names need to be imported in the right tab of the field. https://gyazo.com/52a3549a8adaed2d5f44cac6dfb6d9d3 As you can see, there are language tabs above the field, and the names of the category in that language need to be insterted there. Anyone have an idea how I can fix this?
  7. Hi guys, I'm trying to create a function to show the first picture of a page based on the rendernav function in _init.php. I'm succeding at showing all the images, but i can't find a way to show just the first image. Thanks in advance for anyhelp & merry christmass !!! function renderNavImages(PageArray $items) { // $out is where we store the markup we are creating in this function $out = ''; // cycle through all the items foreach($items as $item) { //trying to render 1st image foreach($item->images as $image) { //$imagen = $page->image->first(); $out .= "<img src='$image->url' />"; } // render markup for each navigation item as an <li> if($item->id == wire('page')->id) { // if current item is the same as the page being viewed, add a "current" class to it $out .= "<li class='current'>"; } else { // otherwise just a regular list item $out .= "<li>"; } // markup for the link $out .= "<a href='$item->url'>$item->title<br />$item->image</a> "; // if the item has summary text, include that too if($item->summary) $out .= "<div class='summary'>$item->summary</div>"; // close the list item $out .= "</li>"; } // if output was generated above, wrap it in a <ul> if($out) $out = "<ul class='nav'>$out</ul>\n"; // return the markup we generated above return $out; }
  8. Hello all, So me being a noob can't figure out how can I use $pages->get or find in my custom function. function printTitle($page_id){ echo "Title of the page is ".$pages->get("id={$page_id}"); } Above code is giving me error : Error: Call to a member function get() on a non-object From what I've read probably, I should be using $wire('pages')->get. But this gives following error: Error: Function name must be a string Removing $ from wire solves above error but it doesn't print anything. Any help would be very much appreciated. Thanks a lot.
  9. Dear ProcessWire-Community, first of all I want to apologize for my weak english. I'm german and will try my best, but I hope you can forgive me if I missspell something or can't explain it in the right way. Further I want to point out, that in the last few weeks I've become a big fan of the ProcessWire CMS. The free structure with no useless functions and the great community made this CMS to one of my favourite CMSs. And that's the reason why I would like to ask for your help. I'm developing right now an medium-sized website and for this website I'm using the Template Twig Replace-Module. This module is great for saving lots of PHP-syntax, but is also very strict when you code wrong. For this website I want to implement an search and front-end-login-function and even though there are great tutorials for those functions available in PHP, I don't know how to translate those functions into the Twig-syntax. For the front-end-login-function I would like to try out this script. And for the search-function I would like to use the function from the search.php-template file, which is available when you first download ProcessWire. Now here is my question: Would somebody of you like to help me translate those functions into the Twig-Syntax or could someone explain to me how to use PHP-functions within the Template Twig Replace-Module. I know this is a lot to ask for and that this is a ProcessWire-forum and not a Twig-forum, but you would help me a lot. Sincerely, Andreas
  10. Hi there, I am struggling with a very simple variable. I'm using the following function to get the url of a certain child: <?php echo $page->find("projects")->url ?> But it returns an error: Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Selectors.php line 165) #0 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Selectors.php(190): Selectors->create('projects', '', '') #1 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Selectors.php(63): Selectors->extractString('has_parent=1, p...') #2 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Pages.php(143): Selectors->__construct('has_parent=1, p...') #3 [internal function]: Pages->___find('has_parent=1, p...', Array) #4 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Wire.php(271): call_user_func_array(Array, Array) #5 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Wire.php(229): Wire->runHooks('find', Array) #6 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Page.php(786): Wire->__call('find', Array) #7 /Applications/XAMPP/xamppfiles/htdocs/cms/wire/core/Page.php(786): Pages->find('has_parent=1, p...', Array) #8 /Applications/XAMPP/xa This error message was shown because you are logged in as a Superuser. Error has been logged. The page called 'projects' exists, what could be the problem? Thanks in advance
  11. In the API section of PW website I found a comment made by Apeisa. He wrote: // If the page is editable, then output a link that takes us straight to the page edit screen: if($page->editable()) { echo "Edit"; } I'd like to use this function but the code shown above won't print a link - just a static string. How to edit this so the output would be a link leading to the exact page edit screen in admin control panel? Thanks. PS. Link to the page where I found the comment: http://processwire.com/api/variables/page/
  • Create New...