Jump to content

wire('pages')->get with a var in get


simonGG
 Share

Recommended Posts

Hi there,
can anybody please explain to me why this dosent work?
Im really new to php - cheatsheet says:  Get the page matching the given selector string...
So selector string is not meant to be normal string i guess?

Thanks Simon

<?php namespace ProcessWire;
    require_once '../index.php';

    $siteVar = $_GET["target"];
    $theSiteName = "site-".$siteVar;
    $p = wire('pages')->get( $theSiteName );
Link to comment
Share on other sites

Are you intentionally bootstrapping ProcessWire? The selector string can be a normal string, but since a while you can use arrays too. But using arrays is more advanced. So stick to simple strings for now ;)

You selector should work, but you use case is now clear. Is the get variable being set?

What does ...

echo $theSiteName;

... say?

Link to comment
Share on other sites

Firstly, be very careful with user supplied data in a selector string - you need to sanitize it. Also, it would be helpful to know what you are wanting the selector to be. I can't really see how "site-" at the beginning of any selector would be what you want. You should definitely read that link that @LostKobrakai noted. Most likely you are wanting to use a page path, but it's impossible for us to know based on your example.

Link to comment
Share on other sites

Hi there,

the example i postet was just dummy code to illustrate my problem.
Let me explain what's really happening:

I have a js function called createColorItem.js

define(function () {

	var scriptURL 	= cmsURLS.urls.root + 'php/updateColorItem.php',
	 	_target 	= cmsURLS.urls.target,
		_dropRect, 
		_color;

	return {
		create: function (itemData, EventBus) 
		{
			_dropRect 	= 	itemData[0].toString();
			_color 		= 	itemData[1].toString();

			var scriptURL = cmsURLS.urls.root + 'php/createColorItem.php';
			
			$.ajax({
				url: scriptURL,
				type: 'GET',
				data: {
					target: 	_target, 
					dropRect: 	_dropRect,
					color: 		_color
				},
			}).done(function(data) 
			{
				//.. 
			});
		}
	};
});

As you can see it calls php function updateColorItem.php

<?php namespace ProcessWire;

    require_once '../index.php';

    $drop_rect  = $_GET["dropRect"];
    $item_color = $_GET["color"];
    $target     = $_GET["target"];

    $color_items = wire('pages')->get('/color_items_desktop/')->children();
    $newIndex = count($color_items)+1;

    $p = new Page();
    $p->template    = 'color_item';
    $p->parent      = wire('pages')->get('/color_items_desktop/');
    $p->title       = 'colorItem'.$newIndex;
    $p->save();

    $p->desktop_drop_rect       = $drop_rect; // TODO: das muss es auch für tablet und mobile geben
    $p->color                   = $item_color; 

    $p->save();

    echo $p->id;

So this all works fine! But i what i want to achieve is this:

$targetPage = "color_items_".$target;
$color_items = wire('pages')->get($targetPage)->children();

And this is not working? 

Look behind the scene (whit the working code)
http://devbureau.de/video/

Cheers Simon

PS: Yes all GET vars are coming - and i dont sanitize atm - because it's for one singe user/client ... he wont try to kill his system .) 
PPS: This is a visual grid editor (backend) for the front end

First Image is the frontend - secon grid editor

frontend.jpg

backend.jpg

Link to comment
Share on other sites

I don't see where you are defining the $target in:

$targetPage = "color_items_".$target;

Also, keep in mind that "/color_items_desktop/" is not exactly the same as "color_items_desktop" which is what I am expecting you are ending up with.

Link to comment
Share on other sites

Sorry this was c&p mistake - i edited the php code...
And yes that was the mistake - now i define $targetPage like so:

$targetPage = "/color_items_".$target."/";

An everything works fine (banging my head on the table)
Tanks a lot adrian!!! 

Cheers Simon

Link to comment
Share on other sites

I startet this project without maken a proper plan befor.
A lot of tired night work ... it total mixed atm some pages 
use dashes some underscore - i will unify this soon.

But this pages will not be reacable in the browser via url.
Ther a more a kind of container

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...