abdus
Members-
Posts
743 -
Joined
-
Last visited
-
Days Won
42
Everything posted by abdus
-
Can you share your code? Do you have namespace ProcessWire; declared at the top of your file?
-
That fat arrow is a typo, it was meant to be a skinny arrow $config->paths. Thanks for the heads up
-
Assuming your templates folder is set up like this: /site/templates home.php my-template.php includes/ helpers.php Then inside a template file you can do // my-template.php include 'includes/helpers.php'; // OR include __DIR__ . '/includes/helpers.php'; __DIR__ magic constant resolves to the directory of the script and by concatenating it you can build paths for other files. What happens when the file is in the parent directory, say /site/? Then: include '../helpers.php'; // OR $config->paths->site . 'helpers.php'; // OR include realpath('../helpers.php');
-
Although your approach would be a bit faster (less function calls overall), it can be turned into a hook and be called on any class that extends WireArray, basically any collection returned by ProcessWire API // /site/ready.php wire()->addHookMethod('WireArray::chunk', function (HookEvent $e) { $chunkSize = (int)$e->arguments(0) ?? 1; $e->return = array_chunk($e->object->getArray(), $chunkSize); }); A common use case is to build grids <?php $myPages = $pages('template=my-template'); ?> <div class="grid"> <?php foreach ($myPages->chunk(5) as $chunk): ?> <div class="row"> <?php foreach ($chunk as $item): ?> <div class="col"><?= $item->title ?></div> <?php endforeach; ?> </div> <?php endforeach; ?> </div>
- 2 replies
-
- 5
-
-
- array_chunk
- chunk
-
(and 2 more)
Tagged with:
-
Call to undefined function wire() with Ajax
abdus replied to entschleunigung's topic in Getting Started
I certainly agree. I create a template and page called api for basic JSON outputs. One other method to handle arbitrary urls without using any page/template can be hooking into ProcessPageView::pageNotFound like this // /site/ready.php wire()->addHookBefore('ProcessPageView::pageNotFound', function (HookEvent $e) { if ($e->input->url === '/api/create/') { $pageId = $e->input->post->int('id'); $content = $e->input->post->text('text'); // your logic // or hand it to another function / class etc. header('Content-Type: application/json'); echo json_encode([ 'pageId' => $pageId, 'content' => $content ]); exit(); } }); -
I wasn't really sure what was the real issue here, but by manually removing Modules.wire and Modules.site entries from caches table in DB, the issue was resolved after a brief Teamviewer support .
-
I doubt home.php gets processed at all. Try echoing something and see if anything shows up. Or try force logging in yourself (put $session->forceLogin('admin') see if you can access backend) If not, use site/ready.php (if it doesnt exists, create it) to put these codes in and see if it makes any difference
-
Than the ClearCacheAdmin module isn't the problem, something else is at play here. Let's try clearing module cache. Add this in home.php and visit homepage again $modules->refresh();
-
Put this on home.php template and visit homepage $modules->uninstall('ClearCacheAdmin');
-
Shit. Try logging in from an incognito window. If that doesnt work, go to /site/modules and rename ClearCacheAdmin to something else
-
That shouldnt have happened, does refreshing the page get rid of it?
-
One other thing is the file compiler. Try deleting site/assets/cache/FileCompiler directory. https://processwire.com/blog/posts/processwire-3.0.14-updates-file-compiler-fields-and-more/
-
Did you enable template caching? Try disabling it from Setup > Templates > my-template > Cache (or flush page cache from Modules > Page Render) or use @Soma's plugin (https://github.com/somatonic/ClearCacheAdmin) Template cache (by default) is disabled for logged in users, so when you're logged in you're seeing whatever you're supposed to see, but when you log out you see the last cached version of that page.
-
Select DISTINCT values of a fields in a pages selector
abdus replied to abmcr's topic in General Support
That wouldn't work here though. That method filters out the duplicate elements, not the elements that have the same field value. -
Call to undefined function wire() with Ajax
abdus replied to entschleunigung's topic in Getting Started
Wrap the function with if(! function_exists('doSomething')) { // function doSomething() {...} } It works when used inside home.php because _func.php was included after the PW took over the request. But when you're calling the function directly apache calls _func.php instead of index.php and PW will not be defined until you include it. http://php.net/manual/en/function.function-exists.php -
Call to undefined function wire() with Ajax
abdus replied to entschleunigung's topic in Getting Started
When you're sending a request to a file that's not called by ProcessWire, wire() will not be defined. You need to bootstrap processwire manually using include '../../../index.php' at the top of your _func.php -
Select DISTINCT values of a fields in a pages selector
abdus replied to abmcr's topic in General Support
Not necessarily a faster way (I haven't tested its performance), but you can do $uniques = array_unique($p->explode('city')): -
For that: <?php namespace ProcessWire; $list = new Commentlist($page->comments, [ 'useVotes' => true, 'useStars' => true, // other options 'headline' => '', // '<h3>Comments</h3>', 'commentHeader' => '', // 'Posted by {cite} on {created} {stars}', 'dateFormat' => '', // 'm/d/y g:ia', 'encoding' => 'UTF-8', 'admin' => false, // shows unapproved comments if true 'useGravatar' => '', // enable gravatar? if so, specify maximum rating: [ g | pg | r | x ] or blank = disable gravatar 'useGravatarImageset' => 'mm', // default gravatar imageset, specify: [ 404 | mm | identicon | monsterid | wavatar ] 'usePermalink' => false, // @todo 'upvoteFormat' => '↑{cnt}', 'downvoteFormat' => '↓{cnt}', 'depth' => 0, 'replyLabel' => 'Reply', ]); echo $list->render();
-
Aside from the unfortunate fact that I completely misread your question (just read the post title, thought you were trying to create comments), depending on the DB scheme you've selected, which field you need to populate will change, but try something like this $c = new Comment(); $c->text = 'This is a comment'; $c->email = 'asd@asd.com'; $c->cite = 'abdus'; $c->website = 'https://google.com'; $c->stars = 5; $c->upvotes = 10; $c->downvotes = 1; // $c->parent_id = 0; // or another comment's id // $c->status = Comment::statusApproved; // $c->ip = '127.0.0.1'; // $c->user_agent = 'Chrome'; // $c->created_users_id = $users('admin')->id; $page->of(false); $page->comments->add($c); $page->save('comments');
-
Did you enable urlSegments for the home template? Setup > Templates > home > Urls
-
$sane = $sanitizer->pageName('Prospère Jouplaboum', Sanitizer::toAscii); $exists = $pages->count("name=$sane") > 0;
-
To check if there's any events involving current contributor, use $fe->count, then with a simple if block, you can decide whether to show the events <?php $fe = $pages->find("contributors=$page, template=event"); // $page is the current page ?> <?php if ($fe->count): // dont show if there arent any events ?> <div class="written_list_participant"> <h2>Events</h2> <ul> <?php foreach ($fe as $e): ?> <li><a href="<?= $e->url ?>"><?= $e->title ?></a></li> <?php endforeach; ?> </ul> </div> <?php endif; ?>
-
I guess @ryan agrees with @Peter Knight's vision. After latest commits, here's how the new UIKit theme looks:
-
PagesEditor class uses $sanitizer->pageName() a bit differently. // Users.php add() -> PagesType::add() // PagesType.php public function ___add($name) { // ... $page->parent = $parent; $page->name = $name; // ... try { $this->save($page); } // ... } // PagesEditor.php protected function savePageQuery(Page $page, array $options) { // ... if(strpos($page->name, $this->untitledPageName) === 0) $this->pages->setupPageName($page); $data = array( 'parent_id' => (int) $page->parent_id, 'templates_id' => (int) $page->template->id, 'name' => $this->wire('sanitizer')->pageName($page->name, Sanitizer::toAscii), // ... ); // ... }