Jump to content

Help to work with field and pages


Enver
 Share

Recommended Posts

I am developing a little app for my university to pass it, the problem is to count some number,

i used field page for select stuff

in my Template AddProject i have 4 fields beside name and title

template AddProject with field

------- Field "SelectUSer" (user1, user2, user3) this field / page / Single page (Page) or boolean false when none selected

------- Field "SelectStatus" (Active, Inactive) this field / page / Single page (Page) or boolean false when none selected

------- Field "SelectProf" (Name, Name2, Name3) this field / page / Single page (Page) or boolean false when none selected

------- Field "SelectSource" (10,20,30,40,50,60,70,80,90,100) this Field is Select not page

and i have a page when i list projects 

ListProject

----------Project 1

------------Field "SelectUSer" (user1)

------------Field "SelectStatus" (Active)

------------Field "SelectProf" (Name)

------------Field "SelectSource" (20)

----------Project 2

------------Field "SelectUSer" (user2)

------------Field "SelectStatus" (Active)

------------Field "SelectProf" (Name2)

------------Field "SelectSource" (50)

----------Project 3

------------Field "SelectUSer" (user3)

------------Field "SelectStatus" (Active)

------------Field "SelectProf" (Name3)

------------Field "SelectSource" (80)

i want to query 

Project 1 | User1 | Active | Name | 20

Project 2 | User2 | Active | Name2 | 50

Project 3 | User3 | Active | Name3 | 80

also 

query for user to grab field related to user and page

user1 | Active | and Field SelectSource to get number from pages which have selected user1 or other user

Link to comment
Share on other sites

you can use the api, and selectors to 'query' your data.  For the page fields i believe you can use a subfield selector, like SelectProf.title

i'm not totally clear on what you are asking - did you do the following before posting:

1.) Read (study) api section on selectors  http://processwire.com/api/selectors/

2.) Look at the source code of the various profiles including the default, blog and skyscrapers

3.) Carefully looked at the cheatsheet and gained an understanding of the $page object http://cheatsheet.processwire.com/

you should possibly post the code that you are using now and we can try to troubleshoot what you are trying to do. It's hard to help when you only post a sort of theoretical explanation

  • Like 1
Link to comment
Share on other sites

First thanks for replay i will try to make it easy

all what i need is to get field from different page they are related  to  user page selected

$findmylisting = $pages->find("id!=40, template=user, sort=name");
	foreach($findmylisting as $findit) {
	
	echo "{$findit->fullname} - {$findit->email} - {$findit->name}@mail.com - {here i want to sum fields 'SelectSource' from page addProject where is the user selected}";
	
	}

so lets say i have 4 other pages(page template addProject) they have field SelectSource with numbers so you pick a number and also have a field select userProfile "SelectUser" in query i want to get or find how many pages are selected userprofile (example "user1") and count all SelectSource numbers like 20+30+50

user can be selected on 2-3 different addProject pages so i just want to publish in user profile SelectSource Field + sum them if user is selected in 3 pages and SelectSource is in one page 20 other page 30 and other page 50,

Link to comment
Share on other sites

@Enver -

i think you are trying to return values of the page selects; that if they are single page selects then you can just output those like:

$findit->pageSelect->name_of_field_you_want_to_return_from_the_page_that_is_selected_on_this_page_select_field

Link to comment
Share on other sites


$findmylisting = $pages->find("id!=40, roles=superuser, template=user, sort=name");

		foreach($findmylisting as $findit) {
		
		$stateAdd = $pages->get("$findit->state")->title;
		
		$resourceTypeAdd = $findit->resourceType;
		
		$getTest = $findit->pageSelect->ProfName;

		echo "<p>{$findit->fullname}  -  {$getTest} - {$stateAdd} - {$resourceTypeAdd}</p>";
}

output

Notice: Trying to get property of non-object in /home/drit/domains/demo/public_html/site/templates/test.php on line 10

John Smith - New Jersey - Direct

Notice: Trying to get property of non-object in /home/drit/domains/demo/public_html/site/templates/test.php on line 10

Parker Demo - New York - Direct

Link to comment
Share on other sites

The problem is this field is not at template "user" where i am using find 

$findmylisting = $pages->find("template=user, sort=name");

this filed is at "AddProject " template every post on this template can select a user which is added at user template 

Link to comment
Share on other sites

hey Enver - i guess the issue is again that i can't seem to follow the logic of your templates/fields relations as well as how those are interacting with users as well asd page selects;

Are you trying to output user info on the frontend? i think you might need to use check_access=0 see the cheatsheet for more info

Link to comment
Share on other sites

Everything is calling fine user info in front end you need to be login to get this info everything at this point is fine i am getting all datas from user information which use template user, 

here is another template called "addProject" inside this template is field called "ProfName" field type Page on this field i can select one user which is under "/admin/access/users/" what i am trying to call is:

find users, list them and find Project Name where is selected this user on addProject,

sample:

template addProject

------------Project1 (Field(ProfName)has selected "user1")

------------Project2 (Field(ProfName)has selected "user1")

------------Project3 (Field(ProfName)has selected "user2")

------------Project4 (Field(ProfName)has selected "user3")

------------Project5 (Field(ProfName)has selected "user4")

find users (template user)

user1 "Project1 + Project2" 

user2 "Project3" 

user3 "Project4" 

user3 "Project5" 

Thanks for your time trying to help me on this.

Link to comment
Share on other sites

assuming that you already know about the pages field having to be a single page (not a page array) if you are outputting them like you are (and not foreaching through the variable as if it is an array), then there's no reason why this shouldn't work:

    <?php
    
    $findmylisting = $pages->find("id!=40, roles=superuser, template=user, sort=name");
     
    foreach($findmylisting as $f) {
        
        $stateAdd = $pages->get("$f->state")->title;
 
    echo '<p>';
    echo  $f->fullname;
    echo  $stateAdd;
    echo  $f->resourceType;
    echo  $f->ProfName;
    echo '</p>';
    }

again i really don't get your naming convention here, it seems quite counter-intuitive, meaning that I cannot easily discern looking at your code what any of the variables are intended to represent;

so this is a coding style sort of issue and at least in my experience and reading about general coding and PHP programming, you should really be aiming for readable code, not just the formatting but also what things represent semantically.

you should also add comments, like

<?php 
// $foo is a page select which gets the selectable pages from the template bar and returns a single page blah blah blah

obviously we have separated each variable out onto it's own line so that you can comment each one out to precicely find which one is causing your error, and then experiment from there with why you are getting the error.

We have clearly determined the cause of the error that you posted, which was because you were using a non-existant field name.

  • Like 2
Link to comment
Share on other sites

This what i am trying to get is similar to http://processwire.com/blogtest/categories/

you have categories name and under them you have pages they have selected different categories 

lets say we have category:

Best Practices and in this category we have different pages this is same what i am trying to get beside categories i have users 

    $findmylisting = $pages->find("id!=40, roles=superuser, template=user, sort=name");
     
    foreach($findmylisting as $f) {
        
        $stateAdd = $pages->get("$f->state")->title; //State Field Page select(/states/...) State in user template 
 
    echo '<p>';
    echo  $f->fullname; //user Full Name Field
    echo  $stateAdd;
    echo  $f->resourceType; //Resource Field Page select(/resource/...) in user template
    echo  $f->ProfName; //Field ProfName page Select(/admin/access/users/...) in addProject template not in user template
    echo '</p>';
    }
Link to comment
Share on other sites

Hi Enver,

so you're simply trying to output a field that is on a 'related' page to the selected user, but where that select takes place is on the project, not on the user.

so this is also pretty simple, as you foreach through the users, you also have to do a page search (using api and selector) to find the page(s) that have the current user selected.

so within the foreach do another $pages->get("template=addProject, profName=$f"); or something like that - if there are multiples then you would do $pages->find, and then you'll end up with a page array so you'll do a nested loop

  • Like 1
Link to comment
Share on other sites

Now is outputting but is repeating same value from first user 

here is code 

    $findmylisting = $pages->find("id!=40, template=user, sort=name");
     
    foreach($findmylisting as $f) {
        
    $stateAdd = $pages->get("$f->state")->title;
	
	$gewt = $pages->get("template=addProject");
 
    echo '<p>';
    echo  $f->fullname . " | ";
    echo  $stateAdd . " | ";
    echo  $f->resourceType . " | ";
    echo  $gewt->profName->title;
    echo '</p>';
	
    }

do i need to use foreach inside foreach or just a search using api 

this is output 

Andy Bamos | New York | Direct | Demo1ProfName

Gana Fisher | New York | Direct | Demo1ProfName

Art Demo | New Jersey | Indirect | Demo1ProfName

Ash Khurta | New Jersey | Direct | Demo1ProfName

Link to comment
Share on other sites

$gewt = $pages->get("template=addProject"); // is always getting the first page found, a page object, not an array

I asume that profName is a field with the type of Page, (1 page object) 

Now every time the loop loops it wil get the firstpage, get the Pagefield and echo the title of that page.

So if you have 400 users, it will echo 400 times the same thing.

$guest = $roles->get("guest");
$users = $users->find("roles!=$guest->id, sort=name");

foreach($users as $u) {
	
	// $gewt = $pages->get("template=addProject"); <--  first found page, with the template addProject
	
	echo "<p>";
	echo $u->fullname . " | ";      // Custom text field or something
	echo $u->state->title . " | ";  // Field type of Page, single page
	echo $u->resourceType . " | ";  // Custom text field or something
	// $gewt->profName->title;      <--  --> always same page, always the same title of that page.
	echo "</p>";
	
}
Link to comment
Share on other sites

Thanks Martijn and Macrura 

here is a code what i did and is query exactly what i looked for 

    $findmylisting = $pages->find("id!=40, template=user, sort=name");
     
    foreach($findmylisting as $f) {
        
    $stateAdd = $pages->get("$f->state")->title;
	

    echo '<p>';
    echo  $f->fullname . " | ";
    echo  $stateAdd . " | ";
    echo  $f->resourceType . " | ";
	echo "(";
		$gewt = $pages->find("template=addProject, projectManager=$f");
			foreach($gewt as $demos) {
				echo $demos->profName->title . ", ";
			}
	echo ")";
	
    echo '</p>';
	
    }

output

Gent Gatoro | New Jersey | Direct | (Sanofi, Catalent, )

Demo Strato | New Jersey | Direct | (Sanofi, Catalent, Spice,)

Grov Avat| New Jersey | Direct | (Sanofi, )

Bench Datop | New Jersey | Direct | (Alexd, Howsr, )

Link to comment
Share on other sites

Sorry for all of this i made here but now its everything working how i wanted i read some posts and other stuff mix some stuff @Macrura  did on post and in the end i found it work trying different ways,

this is a code fixed my trouble

 $findmylisting = $pages->find("id!=40, template=user, sort=name");
     
    foreach($findmylisting as $f) {
        
    $stateAdd = $pages->get("$f->state")->title;
	

    echo '<p>';
    echo  $f->fullname . " | ";
    echo  $stateAdd . " | ";
    echo  $f->resourceType . " | ";
	echo "(";
		$gewt = $pages->find("template=addProject, projectManager=$f");
			foreach($gewt as $demos) {
				echo $demos->profName->title . ", ";
			}
	echo ")";
	
    echo '</p>';
	
    }

Thanks Martijns and Macrura . 

Link to comment
Share on other sites

cool - and don't be afraid to rtrim your $demos...

<?php

    echo "(";
        $gewt = $pages->find("template=addProject, projectManager=$f");
                $out = '';
            foreach($gewt as $demos) {
                $out .= $demos->profName->title . ", ";
            }
            echo rtrim($out, ", ");
    echo ")";
 

;)

  • Like 2
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

×
×
  • Create New...