Re: Turn off Cake processing for a file via view

2006-07-20 Thread I. E. Smith-Heisters

lol. I wasn't entirely sure what webroot/files was for. On the off
chance it had some very strange and special purpose in the CakePHP
hierarchy, I figured I'd leave it alone. The symlinks are because I'm
doing some mojo with a route and including the files within a CakePHP
layout (see 
http://groups.google.com/group/cake-php/browse_frm/thread/6e85b3aa89c7f57a),
so I needed the files to be in two places.

On 7/20/06, AD7six <[EMAIL PROTECTED]> wrote:
>
> Hi Ian,
>
> Out of curiosity..
>
> I. E. Smith-Heisters wrote:
> > /html/app/webroot/archive : -> symlink to /files (since webroot/files
> > already existed)
> I would have thought that that folder exists to put files in, what´s
> the reason for all the symlinks, instead of just putting the files in
> /html/app/webroot/files/?
>
> Regards,
>
> AD7six
>
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Turn off Cake processing for a file via view

2006-07-19 Thread I. E. Smith-Heisters

Yes, that does work! And it works better than my script, since it was
getting a false mime-type for .tar.gz files. So what I've actually done
is something like this:

/files : contains files
/html/ : DocumentRoot
/html/app/views/resources/files : -> symlink to /files
/html/app/webroot/archive : -> symlink to /files (since webroot/files
already existed)

Then a simple
$this->controller->redirect("/archive/$location");
in the view file makes things downloadable.

Thanks again.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Turn off Cake processing for a file via view

2006-07-17 Thread I. E. Smith-Heisters

I tried doing a $this->redirect() in the view to the file, eg.
(/app/views/resources/files/foo) but it still came up with a missing
controller error. The following code allows me to do what I'm trying.
Hope someone finds it useful.

Note that the 'dl' type makes the browser create a "Save As" dialog. To
turn that off and make the browser decide what to do depending on the
mime-type, comment out the "Content-disposition" line.

Thanks for your help, all.
-Ian

pageTitle = $resource['Resource']['name'];
$location = $resource['Resource']['location'];
$file =
"{$_SERVER['DOCUMENT_ROOT']}/app/views/resources/files/{$location}";
?>

render("files/{$location}");
include("$file.thtml");
} elseif ($resource['Resource']['type'] === 'link') {
$this->controller->redirect($location);
} elseif ($resource['Resource']['type'] === 'dl') {
$this->layout = null;
$this->autoLayout = false;

$mimeType = mime_content_type($file);
if (isset($mimeType) && strlen($mimeType) > 0)
header("Content-Type: $mimeType");
header("Content-Disposition: attachment; filename=" .
basename($file));
header("Content-Length: " . filesize($file));
@readfile ($file);
die;
}
?>


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Turn off Cake processing for a file via view

2006-07-16 Thread I. E. Smith-Heisters

Hi,

is there a way that a view can just dump a file without Cake doing any
processing. Right now, I sort of have it working by doing something
like this:

render("files/{$location}");
$this->autoLayout = false;
} elseif ($resource['Resource']['type'] === 'dl') {
$file =
"{$_SERVER['DOCUMENT_ROOT']}/app/views/resources/files/{$location}";
$mimeType = mime_content_type($file);
$fp = fopen($file, "rb") or die ('File not found');
if (isset($mimeType) && strlen($mimeType) > 0)
header("Content-Type: $mimeType");
header("Content-Disposition: attachment; filename=" .
basename($file));
header("Content-Length: " . filesize($file));
while (!feof($fp)) {
print fread($fp, 4096);
}
fclose($fp);
}
?>

But the downloaded file is just the CakePHP page with the file contents
included within! And furthermore, this seems to be a kludgey and
unportable solution, even if I could get it working.

Is there anyway to just tell Cake to turn serving the file over to
Apache?

TIA. And sorry if this question has already been asked; I don't think I
found the right search terms.

-Ian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: include arbitrary content file

2006-07-07 Thread I. E. Smith-Heisters

Okay, I've got (what I think is ) a *better* solution (I'm quite proud
of this, because I'm a n00b).

I have a controller called resources_controller.php that was using
renderElement() to grab the static HTML.

1) I created a directory for the archive files, call it
/app/views/resources/files
2) I created a new route like this:
  $Route->connect('/resources/files/*', array('controller'
=> 'resources', 'action' => 'display'));
3) I copied the display() function from pages_controller.php into
resources_controller.php, and edited the line
   $this->render(join('/', $path));
to look like
   $this->render('files/'.join('/', $path));
At this point, the archive files are visible by calling
/resources/files/foo
4) Then I put this in views/resources/view.thtml
echo $this->render("files/{$location}");
$this->autoLayout = false;
where $location is something like "foo".

The result is that requests to "/resources/files/foo" show the contents
of foo.thtml, within the Cake layout, while "/resources/view/3"
includes that view, as well as any other handling done in the resources
view.thtml file.

The question I have, is that $this->autoLayout = false; is a kludgey
way of avoiding the headers rendering twice. How might I modify
ResourcesController::display() so that it returns the content as a
string without the layout if called by ResourcesController:view(), but
renders the full layout if it's called otherwise?

Thanks for the help.
-Ian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: include arbitrary content file

2006-07-06 Thread I. E. Smith-Heisters

Ohhh... I like that solution a lot. The renderElement solution is a
bit kludgey, since these aren't exactly elements, but this seems more
elegant. 

Thanks again.
-Ian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: include arbitrary content file

2006-07-05 Thread I. E. Smith-Heisters


AD7six wrote:
> Hi Ian,
>
> 1) Cake isn't set in motion for any file that exists on the file system
> so: If they are complete html pages and you don't need/want cake to do
> anything with them then you could create a folder in your webroot and
> access/link to them directly as "/AnyFolder/File.html".
>
> 2) If they are static pages that do not contain a head you could just
> put them in your app/views/pages/ directory and change the extension to
> thtml and then you can access them as /Pages/OldHtmlFile.
>
> Hope that helps, Cheers,
>
> AD7six

Thanks. I was looking more to wrap the html page within the default
Cake template. So, my view would just have an include line which would
pull all the content from foo.html, and present it within the Cake
framework. jb's renderElement() solution works more or less like I'd
imagined.

Thanks though.
-Ian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: include arbitrary content file

2006-07-05 Thread I. E. Smith-Heisters


Jon Bennett wrote:
> place them in the /view/elements/ dir then use $this->renderElement 
> ('myfile');
>
> you can also place sub directories in there as well, say
>
> /views/elements/arbitrary_content_files/
>
> hth
>

Indeed, that did help. Thanks. It's still not quite what I'd imagined,
since it requires the file to end in .thml--which at the least will
require me to rename all my files.. perhaps I'll just write an
extension to the View class...

Thanks much!
-Ian

> jb
>
> >
> > But all of these yield a "No such file or directory" error. However, I
> > can see the file fine if I point the browser at /files/foo.html
> >
> > Does anyone have suggestions on how to get this to work? I can't find
> > any helper function that looks like it's supposed to do this. Is there
> > a better/recommended way to do it?
> >
> > Thanks,
> > ian
> >
> >
> > >
> >
>
>
> --
>
>
> jon bennett
> t: +44 (0) 1225 341 039 w: http://www.jben.net/
> iChat (AIM): jbendotnet Skype: jon-bennett


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



include arbitrary content file

2006-07-04 Thread I. E. Smith-Heisters

Hi all,

I have a bunch of static HTML files (and perhaps later some PHP files)
that I'd like to include wholesale in a view. I thought perhaps the
/app/webroot/files/ directory would be appropriate for holding them, so
I've tried a few things like:

include ("/app/webroot/files/foo.html");
include ("/files/foo.html");
include($html->url('/files/foo.html');

But all of these yield a "No such file or directory" error. However, I
can see the file fine if I point the browser at /files/foo.html

Does anyone have suggestions on how to get this to work? I can't find
any helper function that looks like it's supposed to do this. Is there
a better/recommended way to do it?

Thanks,
ian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: findAll order throws error inexplicably

2006-06-22 Thread I. E. Smith-Heisters

Thanks much, not just for the answer, but for the debugging tip which
will help me figure out future bugs. I'd tried 'table.field', thinking
it was raw sql, but doing 'model.field' did the trick. Thanks again.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



findAll order throws error inexplicably

2006-06-22 Thread I. E. Smith-Heisters

I'm calling this function from a controller:
$this->set('menu_items', $this->MenuItem->findAll(null, null,
array('ui_name')));
and I get the following error:
SQL Error in model MenuItem: 1052: Column 'ui_name' in order clause is
ambiguous
And I can't for the life of me figure out why. If I call findAll
without arguments, there's no problem, but it's unordered.

My model definition looks like this

class MenuItem extends AppModel {
var $name = 'MenuItem';
var $useTable = 'tester';
 ...
}

and the tester table looks like this:

mysql> describe tester;
+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra
|
+---+--+--+-+-++
| id| int(10) unsigned |  | PRI | NULL| auto_increment
|
| name  | varchar(255) | YES  | | NULL|
|
| ui_name   | varchar(50)  |  | | |
|
| parent_id | int(10) unsigned | YES  | | NULL|
|
+---+--+--+-+-++
4 rows in set (0.00 sec)

mysql>

And a basic sql command like this works:
mysql> select * from tester order by ui_name limit 3;
+-+---+--+---+
| id  | name  | ui_name  |
parent_id |
+-+---+--+---+
|  81 | NULL  | Articles |
  26 |
|  53 | basics| Basics   |
   6 |
|  54 | bigpicture| Big Picture  |
   6 |
+-+---+--+---+
3 rows in set (0.03 sec)

mysql>

I've tried findAll with all these combinations:
findAll('','','ui_name')
findAll('','','ui_name ASC')
findAll(null,null,'ui_name ASC')
findAll(null,null, array('ui_name'))
findAll(null,null, array('ui_name' => 'ASC'))
and a bunch of permutations of that. Any ideas why this isn't working?

Thanks,
Ian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Self Joining Model

2006-06-15 Thread I. E. Smith-Heisters

I haven't had much success/use for/with it. I would guess write a
custom loop, or modify guiTreeList() as described here:

http://groups.google.com/group/cake-php/browse_thread/thread/2ad5bc9ec2f5158c/60198efd89f6e095?q=findAllThreaded+guiListTree&rnum=2#60198efd89f6e095

But I've been using Cake for less than a day, so someone else should
know better than me.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Re: Self Joining Model

2006-06-15 Thread I. E. Smith-Heisters

Wow. That was simple. If I had an award to give, I'd give it to you.

Thanks, so much.
-ian


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---



Self Joining Model

2006-06-15 Thread I. E. Smith-Heisters

Hi all,

I've found a few threads on related subjects, but none of them offer a
solution:

http://groups.google.com/group/cake-php/browse_thread/thread/8ad0ebbb9171b5a4/82f28d0b433191be?q=finderSQL&rnum=7#82f28d0b433191be
http://groups.google.com/group/cake-php/browse_thread/thread/ed9f11b62fd2d223/c46ddbf9860e0be6?q=finderSQL&rnum=3#c46ddbf9860e0be6
http://groups.google.com/group/cake-php/browse_frm/thread/aba68ec53a2ae064/9988348a93f13d1e#9988348a93f13d1e

I have a table that looks like this:

+---+--+--+-+-++
| Field | Type | Null | Key | Default | Extra
|
+---+--+--+-+-++
| id| int(10) unsigned |  | PRI | NULL| auto_increment
|
| name  | varchar(255) | YES  | | NULL|
|
| ui_name   | varchar(50)  |  | | |
|
| parent_id | int(10) unsigned | YES  | | NULL|
|
+---+--+--+-+-++

which represents nested menus. I would think it would be trivial to
allow each MenuItem to have children (whose parent_id is equal to its
id) by using hasMany.

So, first I tried this:
class MenuItem extends AppModel {
var $name = 'MenuItem';
var $useTable = 'tester';

var $validate = array (
'name' => VALID_NOT_EMPTY,
);
var $hasMany = 'MenuItem';
}

but that just overwrites the main node,
$this->MenuItem->read():
array(1) {
  ["MenuItem"]=>
  array(0) {
  }
}

so I tried something like this instead:

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
)
);

which at least doesn't overwrite the main object, but still doesn't
populate the child array:
array(2) {
  ["MenuItem"]=>
  array(4) {
["id"]=>
string(1) "4"
["name"]=>
string(9) "community"
["ui_name"]=>
string(9) "Community"
["parent_id"]=>
NULL
  }
  ["child"]=>
  array(0) {
  }
}
So then I tried a finderSQL parameter

var $hasMany = array (
'child' => array (
'className' => 'MenuItem',
'finderSQL' => 'SELECT * FROM tester AS one LEFT JOIN 
tester AS two
ON one.id = two.parent_id'
)
);

but that has the same output on read() as the attempt with finderSQL
undefined. Unfortunately, I haven't found a single successful example
of using finderSQL, so it's hard to tell what sort of output the SQL
statement should have. I just grabbed and modded this statement from
one of the other threads I mentioned.

Okay, so then there's findAllThreaded and guiListTree. The former seems
to work (albeit it's kind of uncontrollable), but I really think this
part of the model belongs in the model definition.. The latter,
guiListTree doesn't seem to work as expected and is marked as
deprecated in the documentation..

So, does anyone have any suggestions for building a tree out of a
self-joining table?

Thanks much,
Ian Smith-Heisters


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---