Hi
I was looking for some help using the Views API. I want to query on custom fields when I make my node listing so I dont' think I can use the form to generate my page. I am trying to use the various handlers to just make a simple listing available as a first step. I took the example table description from the API.txt file and put it in my module with no changes except the name:
function fhsstadmin_views_tables()
{
$tables['fhsstadmin_users'] = array(
"name" => "fhsstadmin_users",
"join" => array(
"left" => array(
"table" => "node",
"field" => "uid"
),
"right" => array(
"field" => "uid"
),
),
// The rest is identical to the API.txt version
);
return $tables;
}
From my limited understanding that should actually make the table viewable already? But how to view it?
I tried ?q=fhsstadmin_users , ?q=views/fhsstadmin_users and ?q=fhsstadmin/fhsstadmin_users but none of them do anything? I don't think I need any special handlers or anything like that?
Its probably trivial but how do I bring up the view listing?
Thanks,
Mark
Comments
Much progress but not there yet ..
Hi
I am still trying to get this to work. I have realised that, although still not understanding it all, I was really really lost when I first posted my question. My goal :
I have a custom node with data stored in a table "fhsstadmin_evaluation". It has a field "evaluatorid" and it also has nid. I want to list all my nodes where evaluatorid is the current user id. I think this should be very simple with the views module.
Here is where I am now:
I realised what "expose table" means. So I try to make my table available:
That should make it available and it has nid so I can join on node.nid=fhsstevaluation.nid.
Then I need to make the correct field from my table available to do the sorting on.
Now I start to lose it - do I need a handler? Can I use the handler from the views module?
And the last thing I need is a filter to make sure that it actually filters on the available field:
Here I think the I need a special handler so I stole the one from the views module and made some approx. random changes to get the function below but I don't really understand what I am doing here - just changed uid to be my field and used the global table stuff.
The end result is an error from mysql which looks like this:
I think that there is hope - some of the stuff in the error looks correct. I am sure anyone who has used views successfully can quickly point me in the right direction and I'd really appreciate some help with this.
Thanks,
Mark
--
Mark Horner
Jabber/AIM/Yahoo/Gizmo/Skype/Google: marknewlyn
Co-author:
http://www.nongnu.org/fhsst
http://savannah.gnu.org/projects/fhsst
"Life is but a seg-fault away ...
Life received signal SIGSEGV, Segmentation fault.
0x42074d40 in
I'm trying to do this also
Hi Mark - I'm wanting to do this as well, but I'm afraid I can't help with a solution!
I have a lot of information that I want to be able to search with, and it's hard to decide what info should be part of taxonomy, and what info should be part of a node's data field.
Too stubborn to quit
I have made much progress through trial and error. I find it hard to debug because I keep modifying my module but things are cached so you need to be careful about making sure you see what you changed. For example I got it working, delete the handler and the view still worked so I thought it didn't matter. Anyway here is the code which has allowed me to make custom views for my module where the nodes listed where written by the current user but the node.uid is different:
I cannot explain why it works necessarily but I am getting there :) Maybe we can turn this into a tutorial for people like me!
It would still be great to have an expert weigh in.
Cheers,
Mark
--
Mark Horner
Jabber/AIM/Yahoo/Gizmo/Skype/Google: marknewlyn
Co-author:
http://www.nongnu.org/fhsst
http://savannah.gnu.org/projects/fhsst
"Life is but a seg-fault away ...
Life received signal SIGSEGV, Segmentation fault.
0x42074d40 in
Small mistake in the above "solution"
The custom handlers weren't necessary - it should just be:
But now its working properly I think.
-
Mark Horner
Jabber/AIM/Yahoo/Gizmo/Skype/Google: marknewlyn
Co-author:
http://www.nongnu.org/fhsst
http://savannah.gnu.org/projects/fhsst
"Life is but a seg-fault away ...
Life received signal SIGSEGV, Segmentation fault.
0x42074d40 in
Custom handlers?
Which part of the code is the un-necessary custom handlers?
unnecessary bits
The commented out line in the filter must go and then you don't need to declare the handler it points at.
So bascially I made my field available to the views system and then I have the filter which lets me make that field equal to the current users id.
Mark
Oh sorry -
I didn't see that commented out line in the code - thanks!
Wow, really really missed
Wow, really really missed this one. Sorry! Here are some comments.
The above is exactly perfect.
There is no point in an additional field here unless you have a handler that uses it; I would remove that. Also, in general Drupal doesn't have IDs available for display, and that's what a 'field' actually means here. I could be wrong, though -- the ID could be meaningful to a user, and I'm making an assumptions.
Second, 'name' => "Module: Evaluator ID" if you would. It helps keep the list of fields readable.
The above looks good.
The above looks good.
Comment similar to above. My initial guess is that you misunderstand the 'fields' section, likely due to it not being explained very well.
Same comments as above.
Please don't do this with a global -- use the misnamed _views_get_tables(). This is a clear indication that function is named incorrectly because obviously outside modules may need to call it.
distinct is its own filter; I wouldn't force it here unless absolutely neccesary.
I realize you found the handlers unnecessary, which is good -- they weren't in this case.
-- Merlin
[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]
-- Merlin
[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]
Thanks
Thanks for the detailed reply. I'll go through it properly. I think I am getting the hang of things now so it'll hopefully reinforce the things I might understand!
Mark
A request
It would be great if sometime you could post a tutorial on how to use views module to search a custom node or flexinode.
I'd love to know how to use the api to search, sort, and display info based on both taxonomy, and data within the node.
Help using Views module API to display list of custom nodes
We need a tutorial section called: CUSTOM MODULE and add this thread to it.
Actually, add views to example module
http://drupaldocs.org/api/head/file/contributions/docs/developer/example...
Apache is bandwidth limited, PHP is CPU limited, and MySQL is memory limited.