Search the Community
Showing results for tags 'programmatically'.
-
Hi All, I am working on a module at the moment which in theory will create a few simple fields, templates and pages which will all be linked together. All is going well so far, I have it generating said fields, templates and pages, however I would like to also set the pages sort order and icon programmatically at this stage also. I have yet to see any documentation or any other threads where this has been brought up, is it even possible programmatically without interacting with the database directly? This is the snippet which is generating my pages on the fly at the moment. foreach($arrayOfPages as $name => $page) { $p = new Page(); $p->template = 'page'; $p->name = $page['URL']; $p->title = $name; $p->parent = wire('pages')->get('name='.$page['parent']); //is it possible to set the icon and sort order at this point, before saving? $p->save(); }
-
Hello, I am developing a module that lets a user create, modify and save a "TV Grid" (the schedule for a TV channel). Here you can view some images that illustrate the concept: https://www.google.com/search?q=tv+grid&tbm=isch Of course, those are just examples and do not represent my specific implementation, but with that I hope you get the idea. The module installs a template for a "channel" (among other things). The "channel" has a "Repeater" field, where I store the complete grid for that channel. The repeater (grid) contains repeater items (grid items) that represent a scheduled show, e.g. ["Friends", Monday, 1st show of the day, lasts 60 minutes]. The repeater field is hidden from the user if he/she tries to edit the channel page via the admin's page edition interface. The intended way to edit this TV grid is by using the module's page that I've developed, which provides a custom interface for creating, manipulating and saving the grid. This of course means that I'm doing many things programmatically. The problem is that the repeater items I'm creating via code using the user's input just WON'T save. I've made all the code changes I could think of, trying different stuff, without positive results. Looking at the database, I notice the following when I run my code: - The corresponding row for the repeater field in its table is updated/saved. - However, no new rows are created for the repeater item fields (e.g. TV Show, duration, day, etc.). Would you please help me out here? I'm becoming insane ... I've included some code below. /* * More code before this, ommited because it isn't relevant. */ // Get the channel object (a Page). $channel = wire("pages")->get($channelId); if(!$channel->id) { $this->error("Channel does not exist. Grid can't be processed."); return ""; } // We need to clean this channel's grid before working with it. // "channel" is the Page // "tvChannelGrid" is the Repeater $channel->tvChannelGrid->removeAll(); $channel->tvChannelGrid->save(); $channel->save(); // Save the page.*/ // Add the grid items received from the module's form to the channel's grid. foreach($tvGridData as $i => $item) { // "tvGridData" is an associative array with data received from a form. $showId = intval($item["tv_show_id"]); $duration = intval($item["duration"]); $day = intval($item["col"]); $row = intval($item["row"]); $gridItem = $channel->tvChannelGrid->getNew(); // this must be done according to the documentation. $gridItem->save(); // Save the newly built item. // Assign values to repeater fields. $gridItem->tvChannelGridShow = wire("pages")->get($showId); // FieldtypePage $gridItem->tvChannelGridShowDuration = $duration; // FieldtypeInteger $gridItem->tvChannelGridShowDay = $day; // FieldtypeInteger $gridItem->tvChannelGridShowRow = $row; // FieldtypeInteger $gridItem->save(); // Save the newly built item. $channel->tvChannelGrid->add($gridItem); // Add the new item to the repeater. } $channel->tvChannelGrid->save(); // Save the repeater. $channel->save(); // Save the page.
-
How can I save a processwire page programmatically? That is, create a new page or update an existing page. I tried the code below in a \site\templates\article.php... <?php // CREATE PAGE - howto? // MODIFY PAGE // Page /foo/bar/ exists. $mypage = $wire->pages->get("/foo/bar/"); $mypage->title = "Foo Bar Test Page"; // Change the title. $mypage->save(); print_r($mypage); ?> ... and then called a page using the Article template: Error Exception: Can't save page 0: : Pages of type NullPage are not saveable (in \wire\core\Pages.php line 508) #0 [internal function]: Pages->___save(Object(NullPage)) #1 \wire\core\Wire.php(271): call_user_func_array(Array, Array) #2 \wire\core\Wire.php(229): Wire->runHooks('save', Array) #3 \wire\core\Page.php(869): Wire->__call('save', Array) #4 \wire\core\Page.php(869): Pages->save(Object(NullPage)) #5 \site\templates\article.php(10): Page->save() #6 \wire\core\TemplateFile.php(92): require('...') #7 [internal function]: TemplateFile->___render() #8 \wire\core\Wire.php(271): call_user_func_array(Array, Array) #9 \wire\core\Wire.php(229): Wire->runHooks('render', Array) #10 \wire\modules\PageRender.module(236): Wire->__call('render', Array)