Monday, August 31, 2009

Re: Using Cake models from non-cake project

It really is as simple as Felix writes. It is just that his post is
from 2006 and a few details have changed.

I just tried this on 1.2 stable and it does work:

$_GET['url'] = 'favicon.ico';
require_once('path_to_app_dir'.DS.'webroot'.DS.'index.php');
// and then for example:
$PostModel =& ClassRegistry::init('Post');
print_r( $PostModel->find('all') );


Notice:
That it is called DS now unless you use your own slashes in paths.
That your best option for brining a model to life is ClassRegistry.
You wil need to have a real Cake app to point to. It needs database
configs and (naturally) the models defined.

/Martin


On Aug 30, 6:38 pm, tbirand <tbir...@gmail.com> wrote:
> Hi Thiago, thanks for the answer. Unfortunately I don't think that
> works either, as the shells aren't really external scripts and I don't
> see a way of including them in order to make use of the models. Any
> other suggestions?
>
> On Aug 29, 9:06 pm, Thiago Nuic Vidigal <tvidi...@gmail.com> wrote:
>
>
>
> > I dont know if it will do what you want, but you can create your own cake
> > shell as described i the book...
>
> > On Sat, Aug 29, 2009 at 1:25 PM, tbirand <tbir...@gmail.com> wrote:
>
> > > Hello all,
>
> > > I've just started working with CakePHP a few days ago, and I really
> > > like it. I develop Ruby on Rails apps as well, but having a similar
> > > approach under PHP is most welcome since most of my clients have PHP
> > > enabled hosts and I'm a bit more familiar with the language.
>
> > > That being said, I've a question that I couldn't find an answer to so
> > > far; is there any way to use the models in my cake application from an
> > > outside non-cake php script? This is possible with Rails, I'm sure it
> > > can be done here as well but after searching for a few hours I thought
> > > I'd post here. Anyone have an idea? (I've already tried the technique
> > > describet at
> > >http://debuggable.com/posts/the-ultimate-cakephp-bootstrap-technique:...
> > > to no avail.) I need to do this so I can use some newer db tables and
> > > their respective models in a legacy php application until I have the
> > > time to completely rewrite it.
>
> > > Thanks in advance,
>
> > > T.J.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: