Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/13/2012 in Posts

  1. I think it really depends on the kind of beginner you have in mind. Someone who knows HTML farely well and maybe has some idea of programming (let's say through JS), but no PHP knowledge might actually like something like i.e. Smarty. For someone with no programming experience, but willing to learn, it might not make a difference at all. In my experience, what "scares" people about pure PHP templating is the syntax. It's pretty close to HTML, but introduces some things they usually don't have to deal with in pure HTML like single/double quotes, special characters etc. Most template engines use a syntax which is easier to distinguish from plain HTML at first glance. That's what "comforts" them. Bottom line, as long as it's optional, a template engine might indeed attract more users without driving away the PHP-only folks. But beware – it might as well become Pandora's box. You add one template engine, people want another one …
    3 points
  2. I'm not sure if that's what you looking for and if you already know it. Since users are like pages you can just populate or assign a value to a field and then save it. Checkboxes have state 0 or 1 vor checked. Assuming the checkbox field is the "game1completed". $user->game1completed = 1; $user->save(); This should work That's ok the way you do it, though not very scaleable and flexible. This approach may work if you only have 3 games and there wont be any more ever. There's other ways of doing it without checkbox. 1. Using a page that stands for a game. So you could create a template with only the default title field and call it "game-completed". Now you create pages for each game using that template somewhere. If you now create a page field "games_completed" that allows multiple pages for that particular template and assign it to the user template. Then you use that field to save and add a reference to the game the user completed. // get game page using it's name or id or path $game = $pages->get( "template=game-completed, name=game1" ); // assign the game page to the page field on user object $user->games_completed = $game; $user->save(); To check the pages // to see if or what games the user completed foreach ( $user->games_completed as $game ) { echo "Game:" . $game->title; } // or to output users that have completed a particular game $game = $pages->get( "/games/game1/" ); $users_completed = $users->find("games_completed=$game"); foreach ( $users_completed as $u ) { echo "User:" . $u->name; } 2. You could also use a textfield to store the game informations as JSON encoded string. And read the string and decode it when needed. But this way it would not be possible to use nice selectors and not so flexible. 3. One that would allow for saving games, along with some informations like score and time, would be to create pages for each game completed as children of the user page. Create a template "game-saved" that has the fields needed for the meta information. Then create new page when saving the game using this template and the user as parent. To be able to add child pages to the user pages, you first need to allow children for the system "user" template (use filter on template list to see it and edit it) under family tab. // create new page $game = new Page(); $game->template = $templates->get( "game-saved" ); $game->title = "Game1"; // parent is the user page (user = special page) $game->parent = $user; // assign some values $game->score = $somevar; $game->time_completed = $timevar; // save it. $game->save(); Checking for games could be like this $game1 = "game1"; // get all users that have completed "game1" foreach( $users as $u ) { // check if user has a child page using the name "game1" if( count( $u->children->find( "name=$game1" ) ) ) { echo "User: " . $u->name; } } To output game informations // or cycle the completed games and output if( $user->numChildren ) ) { foreach( $user->children as $game ) { echo "Game: $game->title<br/>"; echo "Score: $game->score<br/>"; echo "Score: $game->time_completed<br/>"; } } else { echo "no games completed"; } The field is yours.
    2 points
  3. Hey, it got me (who never got his mind around PHP in various attempts), into learning about strftime, strtotime, date and all that stuff this morning. So thanks PW for teaching me yet another lesson in PHP. Watch your backs, I might take the whole thing over some time.
    2 points
  4. $pages->get() will always return a Page object, so rather than doing this: if($type_of_oper) { you should do this: if($type_of_oper->id) { When a $pages->get() doesn't match anything, it returns a NullPage. The easiest way to check for a NullPage is by seeing if it has an id, like above. Though you could also do this if you preferred: $p = $pages->get($selector); if($p instanceof NullPage) { // no page found } else { // page found }
    1 point
  5. That depends how you want or need to do it. Depends on how you proceed after the game is completed in flash. You could call a javascript from the flash game and do some simple ajax to call a php script. I remember you can simply use the trick: getURL("javascript:saveGame('game1', 2332, 109233)"); Easy enough if you know how, but there's many resources out there. More advanced would be to use some connector or comunicate back and forth with callbacks. But just some pseudo code: // on the page where the flash game is using jquery function saveGame( game, userid, score ) { $.ajax({ url: '/ajax/saveGame.php', type: 'post', data: { 'game': game, 'score': score, 'userid' : userid }, dataType: "json", onsuccess: function(data) { if( data.status == 1 ) alert( "GameSaved!" ); } }); } Then some simple php under /ajax/saveGame.php // bootstrap PW index include( "../index.php" ); // get some fuel; create PW variables as if in a template file $sanitizer = wire( "sanitizer" ); $input = wire( "input" ); $pages = wire( "pages" ); $users = wire( "users" ); $game = $sanitizer->name( $input->post->game ); $score = (int) $input->post->score; $user_id = (int) $input->post->userid; // get the user object $user = $users->get($user_id); // do some magic; // if successful echo json_encode( array( 'status' => 1 ) ); Or you could simply use a getURL to redirect to a certain page after game is completed. You could add a get var to the url, read that out in php and use it to save some informations. /some/url/?game=game1&score=42 Then in the php template script use $game = $sanitizer->name($input->get->game); $score = (int) $input->get->score; Or if you use a php file that is not connected to PW use the bootstrap, as in the previous script, to get access to PW through using "wire()". Edit: Oh and hello Chad, welcome to the forums!
    1 point
  6. Thanks for testing Apeisa and Sinnut. Right now the intended audience is us, as you might guess from the included blog entries. But once everything is worked out with it, the intended audience is folks that want to write blog entries and don't know how to do any development. That's the audience that we have no connection with at all right now, but is WordPress's biggest audience. I'm not too worried about this audience understanding the PHP side of it, because I want to make it technically unnecessary for them to have to do anything at that level. But in order to best support that audience, I also think there needs to be some abstraction on the code side. I did start out with a structure a lot more like the basic profile. But after working with it a bit, decided to build this in the best and most efficient way I knew how. We're already covering the basics in the default site profile, but don't have anything out there that shows how to build something for larger scale. While this isn't particularly large scale, I decided to approach the profile from a development perspective in the same way I'd approach a site I'm building for a client. Though I'll usually bundle some of this stuff into modules, distancing it from the site templates. I may still do that, but still debating the merits of it in this case. Another factor here is that I wanted to support really easy theme-ability, where you'd never have to make the same change in more than one place. If you want to make this thing run on Twitter Bootstrap rather than Zurb Foundation, all you need to do is replace a few classnames at the top of the file (in the constructor). If you want to make all images follow HTML(5) rather than XHTML syntax, then you only need to change it in one place, and so on for any tag. I didn't want to commit 100% to one CSS framework over another, so trying to keep some things abstracted here so I could swap in another framework without having to change the code. For the sidebar widgets, I'm thinking about taking a module approach for those rather than a template one. That way people could install a new widget (as a module) in one shot rather than having to add a template, add fields to it, and create a page for it.
    1 point
  7. Not sure if this works, but let's assume your repeater field is called "repeater": function listPageFields($page) { echo "<h1>{$page->title}:</h1>"; echo $page->renderFields(); foreach($page->repeater as $p) { echo $p->renderFields(); } if($page->numChildren) { foreach($page->children as $child) listPageFields($child); } } listPageFields($pages->get('/'));
    1 point
  8. The page fieldtype refers to the page object itself, and not the id. So this should work: $news = $pages->find("template=news-post, news_section=$page, limit=5");
    1 point
×
×
  • Create New...