Building Web Page
Archived from the Xataface Users forum.
butchseaman — Thu Jan 28, 2010 2:56 pm
Is there some kind of documentation about how to build a web page using Xataface?
I mean putting the index and other pages in xataface/database and managing things through xataface.
Thanks
Butch
shannah — Thu Jan 28, 2010 3:08 pm
I don’t think I have created any specific documentation on this, but you might want to check out the webpage module.
http://weblite.ca/svn/dataface/modules/ … readme.txt
I have been working on a new CMS that accomplishes a similar thing but is more refined and powerful, but this module should give you some good pointers.
butchseaman — Fri Jan 29, 2010 10:39 am
I think I understand… but maybe do you have a demo of this module in operation. The portion I am wrestling with is point 2 in the installation:
- Copy the n1_pages directory into your application’s tables directory.
Thanks
Butch
shannah — Fri Jan 29, 2010 10:42 am
Basically this module just includes a single table definition for a table named “n1_pages”. It also includes the configuration directory for this table. This directory is named “n1_pages” after the table name, and like all table configuration directories, it goes inside the ‘tables’ directory of your application. It is just as if you created a table yourself for your application and set up the configuration for it in a fields.ini file etc….
-Steve
butchseaman — Fri Jan 29, 2010 11:22 am
ok… maybe it the browsing portion I am having the problem with.
if my page is located at http://localhost/ipsg/test_page
how would that relate to
index.php?-table=n1_pages&-action=page&page_path=%%page_path%%
shannah — Fri Jan 29, 2010 11:27 am
index.php?-table=n1_pages&-action=page&page_path=/ipsg/test_page
if your app was located a http://localhost/
or
index.php?-table=n1_pages&-action=page&page_path=/test_page
if your app was located at http://localhost/ipsg
You see the page_path parameter is just specifying a find on the page_path field of the n1_pages table. So it matches whatever you put in the “path” field of your record.
I would use this module as a learning tool only. Once you see how it’s done (there really isn’t much to it), it isn’t hard to set up your own thing that fits into how you want your app to work. Essentially you just need an htmlarea field and a custom template. The rest is all book-keeping.
butchseaman — Fri Jan 29, 2010 11:57 am
ok… well then i was navigating to the correct place…
this is the error
Fatal error: No template found for action ‘page’.On line 48 of file F:\PortableApps\xampp\htdocs\xataface\actions\default.php in function printStackTrace()
On line 1114 of file F:\PortableApps\xampp\htdocs\xataface\Dataface\Application.php in function handle(array(array(page,page)))
On line 1594 of file F:\PortableApps\xampp\htdocs\xataface\Dataface\Application.php in function handleRequest()
On line 5 of file F:\PortableApps\xampp\htdocs\ipsg\index.php in function display()
in F:\PortableApps\xampp\htdocs\xataface\actions\default.php on line 48
shannah — Fri Jan 29, 2010 12:02 pm
What URL produced that error?
butchseaman — Fri Jan 29, 2010 12:13 pm
http://localhost/ipsg/index.php?-table= … ipsg/butch
shannah — Fri Jan 29, 2010 12:16 pm
The page action should be defined in the n1_pages directory. Did you add the n1_pages directory into the tables directory of your application?
(i.e. you should have tables/n1_pages/actions/page.php)
butchseaman — Fri Jan 29, 2010 12:23 pm
ok… this is what I am not understanding for some reason…
I have:
tables > n1_pages > fields.ini
I am not understanding the syntax of what it would look like
(i.e. you should have tables/n1_pages/actions/page.php)
is this in a file called n1_pages or an entry into the ini and if so can you give me idea of what the syntax would be
shannah — Fri Jan 29, 2010 12:44 pm
You need this entire directory.http://weblite.ca/svn/dataface/modules/ … /n1_pages/
Not just the fields.ini file.
Copy this directory so you’ll have:
tables/n1_pages/
in your application.
This directory includes the fields.ini file, actions, templates, and all the other stuff that is used.
butchseaman — Fri Jan 29, 2010 1:25 pm
ok… I got them working.. thank you for your patience. I am not sure what i missed or how i missed it… but with out you sending the directory structure I don’t think I would have ever figured this out.
Now just so I am clear… this same directory structure and content would be used for each page if I understand correctly… with the different names for the pages of course
Butch
shannah — Fri Jan 29, 2010 1:46 pm
I’m not sure I understand the question. You can store unlimited webpages with this setup. Each webpage is a record of this table.
(Note that the .htaccess portion is very helpful for making the URLs look nice).
This module is a good sample for learning as it demonstrates such concepts as custom actions, templates, .htaccess (mod_rewrite), and delegate classes. If you understand how and why everything works in this, it will be quite easy to roll your own CMS that works exactly the way you like.
butchseaman — Fri Jan 29, 2010 2:36 pm
Yes… I see what you are talking about. I think I just need to spend a little time working with this… but you did a great job once again…
butchseaman — Fri Jan 29, 2010 12:23 pm
ok… this is what I am not understanding for some reason…
I have:
tables > n1_pages > fields.ini
I am not understanding the syntax of what it would look like
(i.e. you should have tables/n1_pages/actions/page.php)
is this in a file called n1_pages or an entry into the ini and if so can you give me idea of what the syntax would be
shannah — Fri Jan 29, 2010 12:44 pm
You need this entire directory.http://weblite.ca/svn/dataface/modules/ … /n1_pages/
Not just the fields.ini file.
Copy this directory so you’ll have:
tables/n1_pages/
in your application.
This directory includes the fields.ini file, actions, templates, and all the other stuff that is used.
butchseaman — Fri Jan 29, 2010 1:25 pm
ok… I got them working.. thank you for your patience. I am not sure what i missed or how i missed it… but with out you sending the directory structure I don’t think I would have ever figured this out.
Now just so I am clear… this same directory structure and content would be used for each page if I understand correctly… with the different names for the pages of course
Butch
shannah — Fri Jan 29, 2010 1:46 pm
I’m not sure I understand the question. You can store unlimited webpages with this setup. Each webpage is a record of this table.
(Note that the .htaccess portion is very helpful for making the URLs look nice).
This module is a good sample for learning as it demonstrates such concepts as custom actions, templates, .htaccess (mod_rewrite), and delegate classes. If you understand how and why everything works in this, it will be quite easy to roll your own CMS that works exactly the way you like.
butchseaman — Fri Jan 29, 2010 2:36 pm
Yes… I see what you are talking about. I think I just need to spend a little time working with this… but you did a great job once again…
mikewassil — Fri Jan 29, 2010 4:19 pm
Actually, if you know a little php, and probably you already do, creating a frontend drawing data from the same MySQL tables that you populate with Xataface is actually pretty easy to accomplish. This frontend that advertises my business does just that:
http://www.thedocumentsguy.com/
Each page of this “document” is a database record maintained via Xataface. The front end consists of a single php script, a single MySQL query, an index.php redirect to initiate the first query and an .htaccess to format the urls. The php script calls the query and functions as a template using css to format the content.
Here’s the php script:
- Code: Select all
- `<?php
$page = @$_GET[‘q’] ;
include “inc/header.php”;
include “dbq1.php”;
?>
<?php include “inc/footer.php”; ?>`
Here’s the query:
- Code: Select all
- `<?php
$page = @$_GET[‘q’] ;
$limit=1000;
$link = mysql_connect(“localhost”, “user”, “password”) or die(mysql_error());
mysql_select_db(“database”) or die(mysql_error());$query = “select * FROM Pub WHERE Name like ‘$page’”;
$numresults = mysql_query($query);
$numrows = mysql_num_rows($numresults);if ($numrows == 0)
{
$no = (“The page: "” . $page . “" has been renamed. Select one of the action tabs above.”);
}if (empty($s)) {
$s=0;
}$query .= “ limit $s,$limit”;
$result = mysql_query($query) or die(“Couldn’t execute query”);while ( $row = mysql_fetch_assoc($result) ){
/*
Content display and formatting starts here.
*/$main = $row[‘Main’];
$menu = $row[‘Menu’];
}
mysql_close($link);
?>`
Here’s the .htaccess:
- Code: Select all
RewriteEngine on RewriteRule \.htaccess - [F] RewriteRule \.(txt|gif|jpe?g|css|ico)$ - [L] RewriteCond %{HTTP_HOST} ^(www\.thedocumentsguy\.com)?$ RewriteRule ^page/?([^/\.]+)\.html$ get1.php?q=$1 [L]
Here’s the “index.php” file that starts the ball rolling:
- Code: Select all
- `<html>
</html>`
You’ll likely notice that the “pages” of this document have really long and unusual page names. That came about because of Google Ads. When I first set up this site using page names like “home”, “introduction”, and other such single word generic names, the Google Ads I was getting were totally not related to the business I’m advertising. Such stuff as “Gay guys blah, blah, blah…” , “Hot singles, blah, blah, blah…”, “Swinging this and that…”. After some trial and error I discovered that the Google Ads that showed on the pages were being influenced by the “Guy” in my website name “TheDocumentsGuy” because the individual page names were not distinctive. So to get Google to throw more relevant ads, I changed the page names to what they are now. Putting “opensource” in each page name got rid of all the junk ads.
Michael
butchseaman — Sat Jan 30, 2010 7:12 am
Thanks Mike…
I will play with this a see what i get going.
Butch
butchseaman — Sat Jan 30, 2010 9:02 am
Well… Mike
Guess I am missing something. all I seem to get is
The page: “” has been renamed. Select one of the action tabs above.
Just so you know what I have done..
I have a table called ‘home’ with a field called ‘name’ - in that that is where I have my body text with html tags.
I have the dbq1 query point to this db and table
I am sure I am off on how this is to work… can you point in the the right direction..?
Thanks
Butch
mikewassil — Sat Jan 30, 2010 12:51 pm
butchseaman wrote:Well… Mike
Guess I am missing something. all I seem to get is
The page: “” has been renamed. Select one of the action tabs above.Just so you know what I have done..
I have a table called ‘home’ with a field called ‘name’ - in that that is where I have my body text with html tags.
I have the dbq1 query point to this db and table
I am sure I am off on how this is to work… can you point in the the right direction..?
Thanks
Butch
Possibly a couple of things. First, I didn’t intend for you just to drop in the code and it would work. The code is specifically written to work with my database and directory/file structure. So you have to modify a bit to fit your situation. You must make sure the table and field names in your database match whatever “dbq1.php” is looking for. Specifically:
- Code: Select all
$query = "select * FROM Pub WHERE Name like '$page'";
change “Pub” to whatever your actual table name is, and change “Name” to whatever your actual field name for the record name is. The query is case sensitive, so be sure of matching your table and field names exactly, thus in your case:
- Code: Select all
$query = "select * FROM home WHERE name like '$page'";
The query is finding your database, otherwise you’d get a php error. “The page: “” has been renamed…” means the query is not finding a record, either because it didn’t find the table or didn’t find a record in the table with the page name requested. I think it likely found the table, otherwise you’d get a “Couldn’t execute query” error. The “$no” variable is just a more sophisticated “404 error”. To see how $no works correctly, hit this link:
http://www.thedocumentsguy.com/page/new.html
If your “The page: “” has been renamed…” looks similar, you’re getting close, that is, it’s displaying header and footer stuff but just no page content! To avoid $no you have to have an actual record in the database table with a field labeled “name” and some content in that field. Then you can enter a URL like:
- Code: Select all
http://www.<yourdomain>.com/page/<field"name"content>.html
You also have to have a field labeled “Main” with something in it in order to display any content for the page. But the page should display OK with or without any actual content. Note: you can rename the field “Main” to anything you like, but make sure you change dbq1 to match your field name:
- Code: Select all
$main = $row['YourMainContentFieldName'];
Second, you must have the .htaccess file set up correctly, hence:
- Code: Select all
RewriteRule ^page/?([^/\.]+)\.html$ get1.php?q=$1 [L]
“get1.php” must be the same as whatever name you gave the above “php script”. I used “get1” because it’s getting a single record for a single page. You can name it anything you like, but the .htaccess file must point to it in order for everything to work as designed. Here’s my directory/file structure, which might help you see how things are laid out:
root (the documentsguy.com)
.htaccess
dbq1.php
get1.php
index.php
….. css (dir)
………. default.css
….. inc (dir)
………. header.php
………. footer.php
Make sure you’ve got some html header stuff in “header.php”. Put </body> and </html> in “footer.php” or at the bottom of “get1.php” (or whatever you name it) if you don’t want to have a separate footer file. By the way, header.php should not contain </body> and </html> and footer.php should not contain <html> and <body>. Also, using .php instead of .html enables you to create html files that have tags missing without causing problems. In this case, since both the header and footer files are being included, get1.php combines the html elements from those two files into a single completed properly tagged html page.
Of course, for testing purposes, you can leave out the header and footer includes, and just put the correct html tags in get1.php until you get it working. If you still can’t get this working, please include your database name, field names, your version of dbq1.php, get1.php and .htaccess and I might then be able to troubleshoot it for you.
Hope this helps, Michael