controller condition find :: only retrieving one record? :: foreach :: should be printing many

2009-05-23 Thread programguru


in my tasks controller, i am simply trying to find all tasks with status of
"Completed" and then of course echo them out in a foreach.

But for some reason, only one record is printing that meets the criteria,
but there are many more that should be.

Here is my code:

tasks_controller.php
function index() {
$this->Task->recursive = 0;
$this->set('tasks', $this->paginate());
   // code to pull the Completed status items
   $allStatuses= $this->Status->Task->find('all');
   $statuses = $this->Task->Status->find('all',
array('conditions'=>array('Status.name'=>'Completed')));
   $this->set(compact('task','statuses'));
}



tasks -  index.ctp

  
  






  



Any ideas as to why this is happening?

-- 
View this message in context: 
http://www.nabble.com/controller-condition-find-%3A%3A-only-retrieving-one-record--%3A%3A-foreach-%3A%3A-should-be-printing-many-tp23690573p23690573.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Parse content output

2009-05-23 Thread Teh Treag

Benedikt R.

In the book Practical CakePHP Projects, the authors discuss CakeTags
in chapter 11.  They use a subclass of Views that handles substitution
of content in the last stages of rendering.  I've modified theirs to
handle a  tag.  In the view, I render any  tags as the content of the file embedded in a 

http://books.google.com/books?id=3S0O6Egf-_4C&pg=PA317&lpg=PA317&dq=cakephp+caketags&source=bl&ots=z45NEFP37N&sig=9sTxAN7W2v7Anaj3sF3X9ZFh4cc&hl=en&ei=QasYSqmRJ4zMMNqbzZYP&sa=X&oi=book_result&ct=result&resnum=3

http://v2.cybergod.net/codesamples.zip


-teh

On May 23, 1:44 am, "Benedikt R."  wrote:
> Hey!
>
> Is there a cool way to parse content before doing an output?
>
> In the text items in my database I got placeholders like '[BLA...]' -
> these should be replace by specific source code, that's read from some
> files.
>
> The tool should also be available in the views, and be used like this:
> $this->Articles[Article][content]->replacePlaceholders();
>
> I just created a component, that helps me with that:
>
>          class ElementReplacerComponent extends Object {
>
>                 public $replacementsFolder = 'contentReplacements/';
>
>                 public $searchTemplate;
>                 public $searchContent = '';
>
>                 public $adSenseTemplate;
>                 public $adSenseContent = '';
>
>                 function initialize () {
>                         $searchTemplate = $this->replacementsFolder . 
> 'searchField.tpl';
>                         $adSenseTemplate = $this->replacementsFolder . 
> 'googleAdSense.tpl';
>
>                         if ( file_exists( $searchTemplate ) ) {
>                                 $fileHandler = fopen($searchTemplate, 'r');
>                                 $this->searchContent = fread($fileHandler, 
> filesize
> ($searchTemplate));
>                                 fclose( $fileHandler );
>                         }
>
>                         if ( file_exists( $adSenseTemplate ) ) {
>                                 $fileHandler = fopen($adSenseTemplate, 'r');
>                                 $this->adSenseContent = fread($fileHandler, 
> filesize
> ($adSenseTemplate));
>                                 fclose( $fileHandler );
>                         }
>                 }
>
>                 function parseContentItem( &$content ) {
>                         $content = str_replace('[BLZ-Suche]', 
> $this->searchContent,
> $content);
>                         $content = str_replace('[Google AdSense]', 
> $this->adSenseContent,
> $content);
>
>                         return 0;
>                 }
>         }
> ?>
>
> Is there a better way to do that (I think there is :-D)?
>
> Best regards,
> Benedikt
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Making multiple ajax requests at once give 403 error...

2009-05-23 Thread Andrew Koebbe

Ah ha! It was the Security.level = high in the core settings. As the
comments say...

CakePHP session IDs are also regenerated between requests if
'Security.level' is set to 'high'.

I set it to medium and the session IDs stay and the ajax requests all
work every time now. I wonder if it would be good for cake to not
change the sessionID when the user agent is XMLHttpRequest.

--Andrew

On May 23, 6:10 pm, Andrew Koebbe  wrote:
> Sorry for all of these messages. I'm continuing to see more and more
> pieces of the puzzle
>
> After looking at the response header of the first successful response,
> there is a set-cookie header:
>
> Set-Cookie
>
> CAKEPHP=deleted; expires=Fri, 23-May-2008 23:04:12 GMT; path=/
> CAKEPHP=ddfc467602564dd86ac7b7eb98e04020; path=/
>
> So the first successful response from cake resets the cookie, but the
> other requests are still going with the old cookie. So what I need is
> for cake not to reset the cookie. How do I do that?
>
> --Andrew
>
> On May 23, 5:59 pm, Andrew Koebbe  wrote:
>
> > Ok. So I found the culprit, but I'm not sure how to fix it.
>
> > The problem is the ACL. It seems like one of the ajax requests has the
> > credentials, but the other requests do not, so they are getting sent
> > to a login prompt. If allow access to the ajax controllers to everyone
> > then they work every time with the ajax request. Obviously allowing
> > access to the controllers to everyone is not desirable. So is there
> > something I need to change so that the credentials are being passed to
> > the controller?
>
> > --Andrew
>
> > On May 23, 5:45 pm, Andrew Koebbe  wrote:
>
> > > Nevermind. I've totally uninstalled firebug and I still get sporadic
> > > 403s on ajax requests. Sometimes everything will load, and sometimes
> > > only one request will work. I can't seem to find any rhyme or reason.
> > > Any help would be appreciated.
>
> > > --Andrew
>
> > > On May 23, 3:43 pm, Andrew Koebbe  wrote:
>
> > > > Ok. Oddly enough, when I disable firebug, all of the requests come
> > > > back just fine. I'd still like it to work with firebug so that I can
> > > > use it to debug everything. Anyone else had that problem?
>
> > > > --Andrew
>
> > > > On May 23, 3:35 pm, Andrew Koebbe  wrote:
>
> > > > > So I'm working with ExtJS and have a few grid that I'm populating with
> > > > > json data from Cake. The requests go out at the same time when the
> > > > > page loads, but only one of the requests succeed. Sometimes is one
> > > > > request and sometimes it's another. The failing requests get a 403. If
> > > > > i go to the url of one of the failing requests if works just fine.
>
> > > > > Looking at firebug shows that there is a response from Cake. There are
> > > > > no error messages, just the sql debug table. There are no error
> > > > > messages in the cake error log.
>
> > > > > Anyone got any ideas?
>
> > > > > --Andrew
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Making multiple ajax requests at once give 403 error...

2009-05-23 Thread Andrew Koebbe

Sorry for all of these messages. I'm continuing to see more and more
pieces of the puzzle

After looking at the response header of the first successful response,
there is a set-cookie header:

Set-Cookie

CAKEPHP=deleted; expires=Fri, 23-May-2008 23:04:12 GMT; path=/
CAKEPHP=ddfc467602564dd86ac7b7eb98e04020; path=/

So the first successful response from cake resets the cookie, but the
other requests are still going with the old cookie. So what I need is
for cake not to reset the cookie. How do I do that?

--Andrew

On May 23, 5:59 pm, Andrew Koebbe  wrote:
> Ok. So I found the culprit, but I'm not sure how to fix it.
>
> The problem is the ACL. It seems like one of the ajax requests has the
> credentials, but the other requests do not, so they are getting sent
> to a login prompt. If allow access to the ajax controllers to everyone
> then they work every time with the ajax request. Obviously allowing
> access to the controllers to everyone is not desirable. So is there
> something I need to change so that the credentials are being passed to
> the controller?
>
> --Andrew
>
> On May 23, 5:45 pm, Andrew Koebbe  wrote:
>
> > Nevermind. I've totally uninstalled firebug and I still get sporadic
> > 403s on ajax requests. Sometimes everything will load, and sometimes
> > only one request will work. I can't seem to find any rhyme or reason.
> > Any help would be appreciated.
>
> > --Andrew
>
> > On May 23, 3:43 pm, Andrew Koebbe  wrote:
>
> > > Ok. Oddly enough, when I disable firebug, all of the requests come
> > > back just fine. I'd still like it to work with firebug so that I can
> > > use it to debug everything. Anyone else had that problem?
>
> > > --Andrew
>
> > > On May 23, 3:35 pm, Andrew Koebbe  wrote:
>
> > > > So I'm working with ExtJS and have a few grid that I'm populating with
> > > > json data from Cake. The requests go out at the same time when the
> > > > page loads, but only one of the requests succeed. Sometimes is one
> > > > request and sometimes it's another. The failing requests get a 403. If
> > > > i go to the url of one of the failing requests if works just fine.
>
> > > > Looking at firebug shows that there is a response from Cake. There are
> > > > no error messages, just the sql debug table. There are no error
> > > > messages in the cake error log.
>
> > > > Anyone got any ideas?
>
> > > > --Andrew
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Making multiple ajax requests at once give 403 error...

2009-05-23 Thread Andrew Koebbe

Ok. So I found the culprit, but I'm not sure how to fix it.

The problem is the ACL. It seems like one of the ajax requests has the
credentials, but the other requests do not, so they are getting sent
to a login prompt. If allow access to the ajax controllers to everyone
then they work every time with the ajax request. Obviously allowing
access to the controllers to everyone is not desirable. So is there
something I need to change so that the credentials are being passed to
the controller?

--Andrew

On May 23, 5:45 pm, Andrew Koebbe  wrote:
> Nevermind. I've totally uninstalled firebug and I still get sporadic
> 403s on ajax requests. Sometimes everything will load, and sometimes
> only one request will work. I can't seem to find any rhyme or reason.
> Any help would be appreciated.
>
> --Andrew
>
> On May 23, 3:43 pm, Andrew Koebbe  wrote:
>
> > Ok. Oddly enough, when I disable firebug, all of the requests come
> > back just fine. I'd still like it to work with firebug so that I can
> > use it to debug everything. Anyone else had that problem?
>
> > --Andrew
>
> > On May 23, 3:35 pm, Andrew Koebbe  wrote:
>
> > > So I'm working with ExtJS and have a few grid that I'm populating with
> > > json data from Cake. The requests go out at the same time when the
> > > page loads, but only one of the requests succeed. Sometimes is one
> > > request and sometimes it's another. The failing requests get a 403. If
> > > i go to the url of one of the failing requests if works just fine.
>
> > > Looking at firebug shows that there is a response from Cake. There are
> > > no error messages, just the sql debug table. There are no error
> > > messages in the cake error log.
>
> > > Anyone got any ideas?
>
> > > --Andrew
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Making multiple ajax requests at once give 403 error...

2009-05-23 Thread Andrew Koebbe

Nevermind. I've totally uninstalled firebug and I still get sporadic
403s on ajax requests. Sometimes everything will load, and sometimes
only one request will work. I can't seem to find any rhyme or reason.
Any help would be appreciated.

--Andrew

On May 23, 3:43 pm, Andrew Koebbe  wrote:
> Ok. Oddly enough, when I disable firebug, all of the requests come
> back just fine. I'd still like it to work with firebug so that I can
> use it to debug everything. Anyone else had that problem?
>
> --Andrew
>
> On May 23, 3:35 pm, Andrew Koebbe  wrote:
>
> > So I'm working with ExtJS and have a few grid that I'm populating with
> > json data from Cake. The requests go out at the same time when the
> > page loads, but only one of the requests succeed. Sometimes is one
> > request and sometimes it's another. The failing requests get a 403. If
> > i go to the url of one of the failing requests if works just fine.
>
> > Looking at firebug shows that there is a response from Cake. There are
> > no error messages, just the sql debug table. There are no error
> > messages in the cake error log.
>
> > Anyone got any ideas?
>
> > --Andrew
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can this slug code be improved?

2009-05-23 Thread Teh Treag

number9,

Have you seen the sluggable behavior - 
http://bakery.cakephp.org/articles/view/sluggable-behavior?

Or better yet, read the section 'Stupid Easy URL Slugs' on page 42, or
mcurry's free CakePHP E-book -
Super Awesome Advanced CakePHP Tips
http://www.pseudocoder.com/archives/2009/05/13/free-cakephp-e-book-super-awesome-advanced-cakephp-tips/

-teh



On May 23, 11:07 am, number9  wrote:
> I pieced together this code from a few tutorials and was very happy
> with it until I realised it has a bit of a flaw! The code is placed in
> the app model, and automatically adds a .html extension, and turns the
> name field into a suitable URL. It also checks whether the slug is
> unique, if it isn't it will add a number before the slug so that it is
> unique. (If there is already a number there, then it will keep looping
> until it finds a unique number). All of this is done automatically,
> with no code in the controller/view as long as there is a "slug" and a
> "name" field.
>
> So what's the problem? Problem is, when something is updated (i.e.
> edit action), it sees the slug is not unique and adds a number... I
> have solved this by specifying the fields to save in each edit
> controller, but thought there must be an easier way to stop the code
> running for every edit function? The thing I like about this is that
> it requires no real setting up in the controllers. I know what I want
> to do in pseudocode in terms of an if/else statement somewhere, but
> cannot see how I could add it?
>
> Here is the code anyway:
>
> 
> class AppModel extends Model
> {
>
>         function beforeValidate() {
>             $modelName = $this->name; // Put the model's name in an easier to
> read variable
>
>             // If there's a slug field present, auto-populate it
>             if ($this->hasField('slug')) {
>               if (isset($this->data[$modelName]['name'])) {
>                 // If the model has a name, use that to make its slug
>                 $this->data[$modelName]['slug'] = 
> $this->createSlug($this->data[$modelName]['name']);
>
>               } else {
>                 // Otherwise, use anything that'll give it a unique
> identifier as it's easier for absolutely everything to use slugs -
> less exceptions to the rules make for simplicity.  I'm going to
> serialise the data (turn the array into a string) and make an MD5 sum
> of it (turn that into a few random-looking hex digits).  Hopefully
> this should be unique.  I'd be worried if it wasn't.
>                 $this->data[$modelName]['slug'] = md5(serialize($this->data
> [$modelName]));
>               }
>             }
>           return TRUE; // Go ahead and validate the data
>         }
>
>         function createSlug ($string, $id=null) {
>         // Turn names such as "It's wrinkled!" into slugs such as "its-
> wrinkled"
>         $slug = strtolower($string); // Make the string lowercase
>         $slug = str_replace('\'', '', $slug); // Take out apostraphes.
> CakePHP takes care of escaping strings before putting them into SQL
> queries. This is purely for aesthetic purposes - changing "that-s-
> cool" into "thats-cool"
>         $slug = ereg_replace('[^[:alnum:]]+', '-', $slug); // Turn any group
> of non-alphanumerics into a single hyphen
>         $slug = trim($slug, '-'); // Remove unnecessary hyphens from
> beginning and end
>         $slug = $slug.".html"; // add html extension so pages appear static.
>
>         // Now loop through slugs, if there is an identical one - add a
> number at the beginning.
>         $i = 0;
>         $params = array ();
>         $params ['conditions']= array();
>         $params ['conditions'][$this->name.'.slug']= $slug;
>                 if (!is_null($id)) {
>                 $params ['conditions']['not'] = array($this->name.'.id'=>$id);
>                 }
>                 while (count($this->find ('all',$params))) {
>                 if (!preg_match ('/-{1}[0-9]+$/', $slug )) {
>                 // trim .html extension so that number can be added:
>                 $slug = substr_replace($slug ,"",-5);
>                 // now reattach .html after number
>                 $slug .= '-' . ++$i.'.html';
>                 } else {
>                 $slug = preg_replace ('/[0-9]+$/', ++$i, $slug );
>                 }
>                 $params ['conditions'][$this->name . '.slug']= $slug;
>                 }
>         return $slug;
>         }
>
> }
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Error Handling

2009-05-23 Thread Teh Treag

Luiz,

Unique keys violation and stuff like that are issues that should occur
during validation.  Check out the manual - 
http://book.cakephp.org/view/125/Data-Validation

As for logging it, you can use the log method (available in all
classes which derive from Object) - http://api.cakephp.org/class/object

-teh

On May 23, 2:51 pm, Luiz Poleto  wrote:
> Hello all,
>
> I've been searching around, but i couldn't find the right directions for
> error handling using cake.
>
> For example, i would like to treat errors from database, like unique keys
> violation and sutff like that. Also, any other errors that would happen
> would be nice to treat and log it with information like the error number and
> error message when it comes to database errors.
>
> Does anybody can point me the right way of doing that?
>
> Thanks,
> Luiz Poleto
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: I don't know which association for my project.... please help me

2009-05-23 Thread Teh Treag

Avandgard,

This is a fairly common problem.  Once you start adding attributes
like quantity, and price to your join table (structures_users), it has
been recommended you use hasMany/belongsTo relationships between the
three tables involved.

Read the subsection 'What to do when HABTM becomes complicated?' on
this page - http://book.cakephp.org/view/85/Saving-Related-Model-Data-HABTM

-teh

On May 23, 12:51 pm, Avandgard  wrote:
> Hi all...
>
> I aheve three tables
>
> users (id, username...)
> structures (id, name, def_quantity, def_price)
> structures_users (id, user_id, structure_id, quantity, price)
>
> i tried HABTM, but i have problem with saving other data than user_id/
> structure_id please can you help me how to design it? I want to
> one user can to have many structures but only of one type (structures
> table) do you know how to do it?
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Making multiple ajax requests at once give 403 error...

2009-05-23 Thread Andrew Koebbe

Ok. Oddly enough, when I disable firebug, all of the requests come
back just fine. I'd still like it to work with firebug so that I can
use it to debug everything. Anyone else had that problem?

--Andrew

On May 23, 3:35 pm, Andrew Koebbe  wrote:
> So I'm working with ExtJS and have a few grid that I'm populating with
> json data from Cake. The requests go out at the same time when the
> page loads, but only one of the requests succeed. Sometimes is one
> request and sometimes it's another. The failing requests get a 403. If
> i go to the url of one of the failing requests if works just fine.
>
> Looking at firebug shows that there is a response from Cake. There are
> no error messages, just the sql debug table. There are no error
> messages in the cake error log.
>
> Anyone got any ideas?
>
> --Andrew
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Making multiple ajax requests at once give 403 error...

2009-05-23 Thread Andrew Koebbe

So I'm working with ExtJS and have a few grid that I'm populating with
json data from Cake. The requests go out at the same time when the
page loads, but only one of the requests succeed. Sometimes is one
request and sometimes it's another. The failing requests get a 403. If
i go to the url of one of the failing requests if works just fine.

Looking at firebug shows that there is a response from Cake. There are
no error messages, just the sql debug table. There are no error
messages in the cake error log.

Anyone got any ideas?

--Andrew
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: regarding the HTML link helper..

2009-05-23 Thread Andrew McCafferty

If you're not doing any advanced routing then this should work:

link('Go', '/users/index'); ?>


On 23 May, 15:21, Abhishek  wrote:
> Hi,
> When i use this to generate the  link
> $html->link('Go',array('controller'=>'users','action'=>'index'));
>
> The link generated by the above statement doesnt contain .. the action
> as index ..
>
> I know /controller/  and /controller/index is the same thing ..
>
> I need it for some other reason .. is there any way i can force the
> helper to show index also in the link ..
>
> Abhishek
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Error Handling

2009-05-23 Thread Luiz Poleto
Hello all,

I've been searching around, but i couldn't find the right directions for
error handling using cake.

For example, i would like to treat errors from database, like unique keys
violation and sutff like that. Also, any other errors that would happen
would be nice to treat and log it with information like the error number and
error message when it comes to database errors.

Does anybody can point me the right way of doing that?

Thanks,
Luiz Poleto

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Using Auth: Access denied even when I allow everything

2009-05-23 Thread Ricky Paz

If I were you, I would use $this->Auth->allowedActions(' * ') instead
of $this->Auth->allow. It works
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Searchable Behavior w/ Strings less then 3 characters

2009-05-23 Thread brian

You're using MySQL? Have a look here:

http://dev.mysql.com/doc/refman/5.1/en/fulltext-fine-tuning.html

On Sat, May 23, 2009 at 2:33 PM, Kyle Decot  wrote:
>
> I am using the Searchable Behavior on my website but I've noticed that
> if someone types something that is 3 characters or shorter, then
> nothing is returned. I understand that this is because FullText search
> is set up this way. Is there any way to change this? I get an awful
> lot of people that search for things like "VA" or "OH" instead of
> Virginia or Ohio and they get no results returned. Thanks for any help
> you can provide.
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problem with retrieving data with relationships

2009-05-23 Thread Ricky Paz

Hi,

You have to use belongsTo and hasMany for 1-n relationship, and not
hasOne and hasMany. In your PropertiesModel, put $belongsTo =
'Seller", and, inside SellerModel, put hasMany = 'Property'.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Objects vs. arrays

2009-05-23 Thread DanielMedia

The code above is for a Model but if you want presentational (in the
view) code, maybe consider creating an AppleHelper with that type of
logic instead.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can this slug code be improved?

2009-05-23 Thread DanielMedia

Can you just wrap it in a condition? (not sure if the will work but
give it a shot)

if(!$this->id){
 // Create slug...
}
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Searchable Behavior w/ Strings less then 3 characters

2009-05-23 Thread Kyle Decot

I am using the Searchable Behavior on my website but I've noticed that
if someone types something that is 3 characters or shorter, then
nothing is returned. I understand that this is because FullText search
is set up this way. Is there any way to change this? I get an awful
lot of people that search for things like "VA" or "OH" instead of
Virginia or Ohio and they get no results returned. Thanks for any help
you can provide.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Objects vs. arrays

2009-05-23 Thread DanielMedia

You could still have the isRed() function in your model.

class Apple extends AppModel {

 function isRed($color = null){
  if($color == 'red'){
   return true;
  }
  return false;
 }

}

So If you're working in your controller:

$apple = $this->Apple->read(null, $id);

if($this->Apple->isRed($apple['Apple']['color'])) {
 // logic...
} else {
 // other logic...
}
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



I don't know which association for my project.... please help me

2009-05-23 Thread Avandgard

Hi all...

I aheve three tables

users (id, username...)
structures (id, name, def_quantity, def_price)
structures_users (id, user_id, structure_id, quantity, price)

i tried HABTM, but i have problem with saving other data than user_id/
structure_id please can you help me how to design it? I want to
one user can to have many structures but only of one type (structures
table) do you know how to do it?

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Objects vs. arrays

2009-05-23 Thread brian

For the given example, it looks to me like you'd do this in the view:

if ($data['Apple']['color'] == 'red')

On Sat, May 23, 2009 at 9:59 AM, jakobjp  wrote:
>
> I've read a few discussions about CakePHP returning objects vs.
> arrays, and this is NOT intended to be such. I just have a question,
> related to it:
>
> I used to have (i.e. "before CakePHP") objects like this:
>
> class Apple {
>  var $color;
>  var $sweet;
>  function __construct($id = false) {
>    if ($id) $this->load($id);
>    return $this;
>  }
>  function load($id) {
>    ... do something to load apple with `id` = $id from db ...
>  }
>  function isRed() {
>    if ($this->color == 'red') return true;
>    else return false;
>  }
> }
>
>
> In my code I would then often work like this:
>
> $apple = new Apple(123);
> if ($apple->isRed()) echo 'Apple is red";
> else echo 'Apple is not red';
>
>
> Now my question:
> Where would a function like isRed() be located in the the CakePHP-way?
>
> Since in Cake I don't have an object to call a model's method on, I am
> not sure how to go about this...
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Database Record deletion problem

2009-05-23 Thread brian

It looks like you've fallen into the same trap that I have in the
past: trying to use an AdminsController to do all admin stuff. I found
that it became a real pain very quickly. I know that, with Cake, it
can be very confusing to create an "admin section" for your site.

Anyway, I think you're far better off just linking to your
GroupsController for this, calling admin_delete(). You can still have
a main admin page, just point links to your other controllers in order
to list, edit, delete, etc.

On Sat, May 23, 2009 at 2:00 AM, lakers fan  wrote:
> do I need to name my action as delete() right now its called deletegroup().
> because in the same admin controller i will deleting groups, users,
> permissions etc.. The url looks like this:
>
> http://localhost/cake/admins/deletegroup/id
>
> controller: admins
> action: deletegroup
> parameter: id
>
> Thanks,
> Bharani
>
>> Date: Fri, 22 May 2009 18:04:01 -0400
>> Subject: Re: Database Record deletion problem
>> From: bally.z...@gmail.com
>> To: cake-php@googlegroups.com
>>
>>
>> What's the URL in your links? Normally, the action would benamed
>> delete() or admin_delete().
>>
>> As an aside, you should probably put that code inside an if block:
>>
>> if ($this->Group->del($id)
>> {
>> $this->redirect(...)
>> }
>>
>> On Fri, May 22, 2009 at 6:14 AM, lakers fan  wrote:
>> > Hello,
>> >     I have a page with list of groups and along with each item there is
>> > a
>> > link to delete that group.  But deletion is not working.. here is the
>> > code
>> >
>> >  function deletegroup($id)
>> >  {
>> >   $this->Group->del($id);
>> >   $this->redirect(array('action' =>'groups'));
>> >  }
>> >
>> > when I move the mouse over the delete link, i see proper id value.. if i
>> > use
>> > the id to delete that record in phpmyadmin, it succeeds.. The Group
>> > object
>> > is valid too..  Am i missing anything?
>> >
>> > Thanks,
>> > Bharani
>> >
>> > 
>> > Windows Live™: Keep your life in sync. Check it out.
>> > >
>> >
>>
>> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: controller function call from cakephp helper class.

2009-05-23 Thread brian

You cannot, AFAIK. Maybe you can re-design things to avoid having to.
What are you trying to do?

On Sat, May 23, 2009 at 2:30 AM, arif hossen  wrote:
> Please help me.
>
> How i can call controller function from cakephp helper class.
>
>
> --
> Regards,
> Mohammad Arif Hossen
> Junior Web Developer
> United Group International(UGIBD)
> Mobile: +88 01714355911
>
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model with Dynamic Data Fields

2009-05-23 Thread DanielMedia

How about creating a multiple table setup? This would let you have
many attachments, etc per document. Then all you would have to do is
check the sub-tables for any data relating to the document's ID.

documents
--
id
title
body
created
modified

document_attachments
---
id
document_id
attachment
created
modified

document_numbers (Just an example based on your message above)
-
id
document_id
number
created
modified

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Parse content output

2009-05-23 Thread brian

On Sat, May 23, 2009 at 2:44 AM, Benedikt R.  wrote:
>
> Hey!
>
> Is there a cool way to parse content before doing an output?

The cool kids are using beforeRender() for this sort of thing ;-)

> In the text items in my database I got placeholders like '[BLA...]' -
> these should be replace by specific source code, that's read from some
> files.
>
> The tool should also be available in the views, and be used like this:
> $this->Articles[Article][content]->replacePlaceholders();

Why from the view, anyway? Shouldn't the content have already been
replaced? Or, do you want to update some content as it's being edited?
I guess that would make sense. I think I'd make the user submit it,
first, and redisplay it. I suppose it depends on your situation.

I would also consider storing the replacement data in a table, rather
than opening and reading a file. That way, you can grab the
replacement at the same time as your Article data. In fact, this would
allow you to do the replacement in Article::afterFind().

> I just created a component, that helps me with that:
>
>         class ElementReplacerComponent extends Object {
>
>                public $replacementsFolder = 'contentReplacements/';
>
>                public $searchTemplate;
>                public $searchContent = '';
>
>                public $adSenseTemplate;
>                public $adSenseContent = '';
>
>                function initialize () {
>                        $searchTemplate = $this->replacementsFolder . 
> 'searchField.tpl';
>                        $adSenseTemplate = $this->replacementsFolder . 
> 'googleAdSense.tpl';
>
>                        if ( file_exists( $searchTemplate ) ) {
>                                $fileHandler = fopen($searchTemplate, 'r');
>                                $this->searchContent = fread($fileHandler, 
> filesize
> ($searchTemplate));
>                                fclose( $fileHandler );
>                        }
>
>                        if ( file_exists( $adSenseTemplate ) ) {
>                                $fileHandler = fopen($adSenseTemplate, 'r');
>                                $this->adSenseContent = fread($fileHandler, 
> filesize
> ($adSenseTemplate));
>                                fclose( $fileHandler );
>                        }
>                }
>
>                function parseContentItem( &$content ) {
>                        $content = str_replace('[BLZ-Suche]', 
> $this->searchContent,
> $content);
>                        $content = str_replace('[Google AdSense]', 
> $this->adSenseContent,
> $content);

This looks prone to failure. Change it to [BLZ-SUCHE] &
[GOOGLE-ADSENSE] or use a case-insensitive replace because someone's
eventually going to get the case wrong.


>                        return 0;
>                }
>        }
> ?>
>
>
> Is there a better way to do that (I think there is :-D)?
>
> Best regards,
> Benedikt
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model with Dynamic Data Fields

2009-05-23 Thread brian

I would create a table, documents, that has the fields that all your
file types require (eg. id, filename) and one each for your doc types
(eg. text_docs, pdf_docs, etc.) and use something like
InheritableBehavior [1].

You could also use ExtendableBehavior [2] and save everything to a
single table. Personally, generally I prefer to do this sort of thing
with separate tables, though.

[1] 
http://bakery.cakephp.org/articles/view/inheritable-behavior-missing-link-of-cake-model
[2] http://bakery.cakephp.org/articles/view/extendablebehavior

On Sat, May 23, 2009 at 8:24 AM, marco.rizze...@gmail.com
 wrote:
>
> Hi
> My problem is about the project of the models of my web application
> I have a model Document . The problem is that this model must have
> dinamic data fields.
> A document can have like fields : title .text , data
> Another can have : title, number , attachment
> ect...
> This fields can have different type: some can be simple string, other
> can be file , other can be text .
>
> Substantially for the moment I have create only the model Document but
> I've no idea how to handle everything else
> I really hope that someone can help me
> Many thanks
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can this slug code be improved?

2009-05-23 Thread number9

I know what you mean, and that thought had crossed my mind. This isn't
actually for a blog, so page titles are less likely to be changed. The
reason I was worried about titles changing was as you pointed out -
the search engines, so that's why I hacked together a solution so the
slugs cannot be updated once set.

I hadn't come across Inflector (fairly new to cake and still
learning!) - just checked it out, the code I posted was taken from
various different places and wasn't actually mine. It is an easier way
but unfortunately it doesn't produce as good a result as using the php
functions. E.g. uppercase is allowed, apostrophes are turned into
hyphens. It is a messier way of doing things but it allows greater
control in my opinion.

Blog looks cool as well :)

Still not sure how I can stop this code from running during the edit
functions I need to over-ride the before validate function in the
app model...

On May 23, 5:55 pm, DanielMedia  wrote:
> I had a similar idea with regard to url slugs for my blog but
> ultimately decided that it would be a bad idea. I tend to tweak titles
> of articles as I expand on them so then I would have to worry about
> Google indexing the old title and then having to 301 redirect to the
> new title. Or people bookmarking an old title etc. It just gives much
> less flexibility to change the page title on the fly. I ended up just
> going with a url likehttp://domain.com/content/$id/my-cool-page-title/.
> Here's an example on my blog (Still in 
> development)http://code621.com/content/5/a-new-cakephp-community.
>
> Btw, for your slug function, why not just use: Inflector::slug
> ($pageTitle, '-') . '.html';
>
> You can change it to add your page numbering jammy. But that's a
> cleaner way to slugify.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: regarding the HTML link helper..

2009-05-23 Thread brian

Maybe if you create a route for it:

Router::connect(
'/users/index', // make this the way you want it to look
array(
'controller' => 'users',
'action' => 'index'
)
);

On Sat, May 23, 2009 at 10:21 AM, Abhishek  wrote:
>
> Hi,
> When i use this to generate the  link
> $html->link('Go',array('controller'=>'users','action'=>'index'));
>
> The link generated by the above statement doesnt contain .. the action
> as index ..
>
> I know /controller/  and /controller/index is the same thing ..
>
> I need it for some other reason .. is there any way i can force the
> helper to show index also in the link ..
>
>
> Abhishek
> >
>

--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Can this slug code be improved?

2009-05-23 Thread DanielMedia

I had a similar idea with regard to url slugs for my blog but
ultimately decided that it would be a bad idea. I tend to tweak titles
of articles as I expand on them so then I would have to worry about
Google indexing the old title and then having to 301 redirect to the
new title. Or people bookmarking an old title etc. It just gives much
less flexibility to change the page title on the fly. I ended up just
going with a url like http://domain.com/content/$id/my-cool-page-title/.
Here's an example on my blog (Still in development)
http://code621.com/content/5/a-new-cakephp-community.

Btw, for your slug function, why not just use: Inflector::slug
($pageTitle, '-') . '.html';

You can change it to add your page numbering jammy. But that's a
cleaner way to slugify.
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: MySQL Subselects

2009-05-23 Thread DanielMedia

Bump...
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Can this slug code be improved?

2009-05-23 Thread number9

I pieced together this code from a few tutorials and was very happy
with it until I realised it has a bit of a flaw! The code is placed in
the app model, and automatically adds a .html extension, and turns the
name field into a suitable URL. It also checks whether the slug is
unique, if it isn't it will add a number before the slug so that it is
unique. (If there is already a number there, then it will keep looping
until it finds a unique number). All of this is done automatically,
with no code in the controller/view as long as there is a "slug" and a
"name" field.

So what's the problem? Problem is, when something is updated (i.e.
edit action), it sees the slug is not unique and adds a number... I
have solved this by specifying the fields to save in each edit
controller, but thought there must be an easier way to stop the code
running for every edit function? The thing I like about this is that
it requires no real setting up in the controllers. I know what I want
to do in pseudocode in terms of an if/else statement somewhere, but
cannot see how I could add it?

Here is the code anyway:

name; // Put the model's name in an easier to
read variable

// If there's a slug field present, auto-populate it
if ($this->hasField('slug')) {
  if (isset($this->data[$modelName]['name'])) {
// If the model has a name, use that to make its slug
$this->data[$modelName]['slug'] = $this->createSlug($this-
>data[$modelName]['name']);
  } else {
// Otherwise, use anything that'll give it a unique
identifier as it's easier for absolutely everything to use slugs -
less exceptions to the rules make for simplicity.  I'm going to
serialise the data (turn the array into a string) and make an MD5 sum
of it (turn that into a few random-looking hex digits).  Hopefully
this should be unique.  I'd be worried if it wasn't.
$this->data[$modelName]['slug'] = md5(serialize($this->data
[$modelName]));
  }
}
  return TRUE; // Go ahead and validate the data
}

function createSlug ($string, $id=null) {
// Turn names such as "It's wrinkled!" into slugs such as "its-
wrinkled"
$slug = strtolower($string); // Make the string lowercase
$slug = str_replace('\'', '', $slug); // Take out apostraphes.
CakePHP takes care of escaping strings before putting them into SQL
queries. This is purely for aesthetic purposes - changing "that-s-
cool" into "thats-cool"
$slug = ereg_replace('[^[:alnum:]]+', '-', $slug); // Turn any group
of non-alphanumerics into a single hyphen
$slug = trim($slug, '-'); // Remove unnecessary hyphens from
beginning and end
$slug = $slug.".html"; // add html extension so pages appear static.

// Now loop through slugs, if there is an identical one - add a
number at the beginning.
$i = 0;
$params = array ();
$params ['conditions']= array();
$params ['conditions'][$this->name.'.slug']= $slug;
if (!is_null($id)) {
$params ['conditions']['not'] = array($this->name.'.id'=>$id);
}
while (count($this->find ('all',$params))) {
if (!preg_match ('/-{1}[0-9]+$/', $slug )) {
// trim .html extension so that number can be added:
$slug = substr_replace($slug ,"",-5);
// now reattach .html after number
$slug .= '-' . ++$i.'.html';
} else {
$slug = preg_replace ('/[0-9]+$/', ++$i, $slug );
}
$params ['conditions'][$this->name . '.slug']= $slug;
}
return $slug;
}

}
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model with Dynamic Data Fields

2009-05-23 Thread number9

I'm by no means an expert so somebody may want to disagree here, but I
think if you are not bothering with templates, I would have one
"documents" table, with all of the possible relevant fields. You could
possibly break it up if you wanted to, and break up the information in
seperate tables and link it in with relations, but I don't think in
this instance there would be any point. The only reason you break up
tables is if you would run out of fields (e.g. you created 10 comment
fields, what happens when you need 11 kind of thing if that makes
sense?) But as you are specifying everything it should be OK to have
one.

Hope that helps and I haven't confused you!

On May 23, 3:03 pm, byqsri  wrote:
> Ok many thanks that's is clear
> I have another question
> Do I keep the values of the fields of all documents in a single table?
> a table like this:
>
> document_id, document_field_id, value
>
> I ask this question
> Because in 'value' I can have a number ,a string, a text ,a datetime
> I don't know if it's the best
>
> On 23 Mag, 15:49, number9  wrote:
>
>
>
> > If I've understood you correctly each document will have a number
> > of different fields that would be useful to store in the database, but
> > all documents are unique.
>
> > The first thing I would do is write down a list of every single
> > possible field that you would need for these documents. If you think
> > that some documents will share certain characteristics, you could make
> > another table and have a few document templates that would fit your
> > needs. E.g. one template has text, title and attachment, another is
> > the same but does without the attachment.
>
> > Alternatively you could just create one big table with all of the
> > possible fields that you drew up and just make them optional.
> > Obviously you would need some form of validation. You could set them
> > as NULL in your mysql database (so they allow empty values), then draw
> > up a validation rule that said documents must have at least 3 fields
> > (for example).
>
> > On May 23, 1:24 pm, "marco.rizze...@gmail.com"
>
> >  wrote:
> > > Hi
> > > My problem is about the project of the models of my web application
> > > I have a model Document . The problem is that this model must have
> > > dinamic data fields.
> > > A document can have like fields : title .text , data
> > > Another can have : title, number , attachment
> > > ect...
> > > This fields can have different type: some can be simple string, other
> > > can be file , other can be text .
>
> > > Substantially for the moment I have create only the model Document but
> > > I've no idea how to handle everything else
> > > I really hope that someone can help me
> > > Many thanks
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Using Auth: Access denied even when I allow everything

2009-05-23 Thread nurvzy

You're '*' in allow in AppController won't make a bit of difference in
your products controller because you're not using parent::beforeFilter
().  You generally want to use parent::beforeFilter()  (or any
callback function) whenever you define a new beforeFilter in your
controller extending AppController.

function beforeFilter(){
  parent::beforeFilter();
  $this->Auth->allow('show');
}

Chances are you're doing that, but I didn't see that in your example.
Another thing I suggest looking for are actionRequest calls in your
views/elements/layouts that aren't being allowed thus giving you the
illusion the page you're asking for (URL) isn't being allowed but in
fact its another action you forgot to 'allow' that will bite me
every now and then.   I highly suggest the debug_kit plugin because it
will show you what's going on behind the scenes of each request.

Hope that helps,

On May 22, 10:02 am, Roman Brunnemann  wrote:
> Hi,
>
> I am using Auth and most of it works fine. But when I want to call a
> page directly as
>
> http://localhost/products/show/
>
> it says ""You are not authorized to access that location.".
>
> So I went in the products controller and made a
>
>    function beforeFilter() {
>
>         $this->Auth->allow('show');
>     }
>
> but it didn't help.
>
> Even a change of the AppController didn't make any difference.
>
> class AppController extends Controller {
>
>     var $component = array('Auth');
>
>     function beforeFilter() {
>
>         $this->Auth->allow('*');  //allow every action of every controller
>     }
>
> }
>
> Do you have any idea why the access is still blocked?
>
> Thanks a lot.
> Roman
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



regarding the HTML link helper..

2009-05-23 Thread Abhishek

Hi,
When i use this to generate the  link
$html->link('Go',array('controller'=>'users','action'=>'index'));

The link generated by the above statement doesnt contain .. the action
as index ..

I know /controller/  and /controller/index is the same thing ..

I need it for some other reason .. is there any way i can force the
helper to show index also in the link ..


Abhishek
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Problem with retrieving data with relationships

2009-05-23 Thread number9

I'm fairly new myself so you will have to bear with me here!

How do you reference fields in your view? There may be a problem there
if that is wrong. Have you baked the controllers/views?

I think the problem is probably your recursive setting, try adding
this line to your controller:

$this->Property->recursive = 2;

When you are pulling in related data you need it set to two in some
cases depending on the data you are trying to output. If debug is not
already set to 2 (in the config file) set it to 2 so you can see the
SQL queries that are being run.

On May 22, 10:38 pm, Bryan Paddock  wrote:
> Hi all,
> Just started learning cakephp last week so a bit scratchy and still
> learning...
>
> There are two tables in question here:
>
> property -> stores rows of properties
> seller -> stores sellers of the properties.
>
> - one property can only have one seller
> - one seller can have many properties
>
> property model has its hasone definition:
>
>   // one property has one seller
>   var $hasOne = array(
>     'Seller' => array(
>       'className'    => 'Seller',
>       'foreignKey'    => 'id'
>     )
>   );
>
> seller model has its hasmany defintion:
>
>   // one seller can have any number of favourites and properties
>   var $hasMany = array(
>     'Favourite' => array(
>       'className'     => 'Favourite',
>       'foreignKey'    => 'seller_id',
>       'dependent'=> true
>     ),
>     'Property' => array(
>       'className' => 'Property',
>       'foreignKey' => 'seller_id'
>     )
>   );
>
> ignore the favourites table for now...
>
> property table contains 'seller_id'
>
> property table
> 
> id
> seller_id
> x
>
> seller table
> ---
> id
> xx
>
> (I do have $useTable defined in each model to ensure table names are
> correct)
>
> In my browse function of the propertiescontroller I have the standard code:
>
>     $this->pageTitle = 'Browse All Properties';
>     $this->paginate['limit'] = 25;
>     $data = $this->paginate('Property');
>     $this->set('properties', $data);
>
> It returns the properties but blank seller information.. it has the full
> seller array with all the database fields but no values for any of them...
>
> Can anyone shed some light on this?
>
> I'm quite stuck here!
>
> - Bryan
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model with Dynamic Data Fields

2009-05-23 Thread byqsri

Ok many thanks that's is clear
I have another question
Do I keep the values of the fields of all documents in a single table?
a table like this:

document_id, document_field_id, value


I ask this question
Because in 'value' I can have a number ,a string, a text ,a datetime
I don't know if it's the best



On 23 Mag, 15:49, number9  wrote:
> If I've understood you correctly each document will have a number
> of different fields that would be useful to store in the database, but
> all documents are unique.
>
> The first thing I would do is write down a list of every single
> possible field that you would need for these documents. If you think
> that some documents will share certain characteristics, you could make
> another table and have a few document templates that would fit your
> needs. E.g. one template has text, title and attachment, another is
> the same but does without the attachment.
>
> Alternatively you could just create one big table with all of the
> possible fields that you drew up and just make them optional.
> Obviously you would need some form of validation. You could set them
> as NULL in your mysql database (so they allow empty values), then draw
> up a validation rule that said documents must have at least 3 fields
> (for example).
>
> On May 23, 1:24 pm, "marco.rizze...@gmail.com"
>
>  wrote:
> > Hi
> > My problem is about the project of the models of my web application
> > I have a model Document . The problem is that this model must have
> > dinamic data fields.
> > A document can have like fields : title .text , data
> > Another can have : title, number , attachment
> > ect...
> > This fields can have different type: some can be simple string, other
> > can be file , other can be text .
>
> > Substantially for the moment I have create only the model Document but
> > I've no idea how to handle everything else
> > I really hope that someone can help me
> > Many thanks
>
>
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Objects vs. arrays

2009-05-23 Thread jakobjp

I've read a few discussions about CakePHP returning objects vs.
arrays, and this is NOT intended to be such. I just have a question,
related to it:

I used to have (i.e. "before CakePHP") objects like this:

class Apple {
  var $color;
  var $sweet;
  function __construct($id = false) {
if ($id) $this->load($id);
return $this;
  }
  function load($id) {
... do something to load apple with `id` = $id from db ...
  }
  function isRed() {
if ($this->color == 'red') return true;
else return false;
  }
}


In my code I would then often work like this:

$apple = new Apple(123);
if ($apple->isRed()) echo 'Apple is red";
else echo 'Apple is not red';


Now my question:
Where would a function like isRed() be located in the the CakePHP-way?

Since in Cake I don't have an object to call a model's method on, I am
not sure how to go about this...
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model with Dynamic Data Fields

2009-05-23 Thread number9

If I've understood you correctly each document will have a number
of different fields that would be useful to store in the database, but
all documents are unique.

The first thing I would do is write down a list of every single
possible field that you would need for these documents. If you think
that some documents will share certain characteristics, you could make
another table and have a few document templates that would fit your
needs. E.g. one template has text, title and attachment, another is
the same but does without the attachment.

Alternatively you could just create one big table with all of the
possible fields that you drew up and just make them optional.
Obviously you would need some form of validation. You could set them
as NULL in your mysql database (so they allow empty values), then draw
up a validation rule that said documents must have at least 3 fields
(for example).

On May 23, 1:24 pm, "marco.rizze...@gmail.com"
 wrote:
> Hi
> My problem is about the project of the models of my web application
> I have a model Document . The problem is that this model must have
> dinamic data fields.
> A document can have like fields : title .text , data
> Another can have : title, number , attachment
> ect...
> This fields can have different type: some can be simple string, other
> can be file , other can be text .
>
> Substantially for the moment I have create only the model Document but
> I've no idea how to handle everything else
> I really hope that someone can help me
> Many thanks
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: findAllThreaded root hack for version 1.2.x

2009-05-23 Thread AD7six



On May 19, 9:40 pm, Anna P  wrote:
> Hello.
> Can anyone help me with hacking findAllThreaded function for version
> 1.2.x ?
>
> In 1.1.x it looked like it to set the root ID for function:
>
> function findAllThreaded($root = null, $conditions = null, $fields =
> null, $sort = null) {
>     return $this->__doThread(Model::findAll($conditions, $fields,
> $sort), $root);
>
> }
>
> But in 1.2.x findAllThreaded is deprecated:
>
> function findAllThreaded($conditions = null, $fields = null, $order =
> null) {
>     return $this->find('threaded', compact('conditions', 'fields',
> 'order'));
>
> }
>
> How to supply to findAllThreaded function the root ID of a model which
> I want to get all children from?

You don't.

You specify conditions such that the find('all') call contains
everything you want

like find('threaded', array('conditions' => array('category' =>
'foo')));
or (if using the tree behavior)
$this->id = $foo;
$lft = $this->field('lft');
$rght = $this->field('rght');
find('threaded', array('conditions' => array('lft >=' => $lft, 'rght
<=' => $rght)));

It is not designed to "allow" you to retrieve unnecessary data and
cherry pick the bit you want.

AD
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Dynamic RSS feed title?

2009-05-23 Thread number9

If anybody is interested, I never managed to pull in the field (still
not sure why), but got the dynamic name working by simply using the
variable I was calling in the function (not sure why I didn't think of
that before!

Relevant code looks like this:

// declare feed function:
function feed($name = null) {

$this->set
  (
'channel',
array
(
'title' => $name
)
  );

On May 22, 7:07 pm, number9  wrote:
> Many thanks for replying.
>
> I can confirm that it works for me as well so thankyou very much!
>
> Only problem is, while I can assign a string as a variable no problem,
> I'm having trouble retrieving the data.
>
> It is located in a "posts controller", and I am looking for the "name"
> field from the category table as the dynamic title.
>
> I have tried all the usual ways but nothing is getting outputted, (I
> have included var $uses = array('Category', 'Post'); at the top so I
> should be able to access the category table?)
>
> I've tried:     $my_title = $this->Category->field('name');   &&
> $my_title = $data['Category']['name']; and a few other variations with
> no joy.
>
> I'm a bit stumped, it is maybe something stupid that I am doing as I
> am fairly new to cake.
>
> Thanks in advance.
>
> On May 22, 5:57 pm, "dr. Hannibal Lecter"  wrote:
>
>
>
> > This works for me (in controller):
>
> > $this->set
> >       (
> >         'channel',
> >         array
> >         (
> >           'title' => $dynamicTitleHere,
> >           'description' => 'Yer description'
> >         )
> >       );
>
> > On May 22, 5:57 pm, number9  wrote:
>
> > > Is there anyway to set make an RSS feed title dynamic? I'm not talking
> > > about the item titles, but the single title that is referenced from
> > > pageTitle.
>
> > > I know that you can alter it statically, but I have setup an RSS feed
> > > for all of my categories (from one view/action), so cannot declare an
> > > individual title for each feed (besides that would go against the DRY
> > > philosophy).
>
> > > I have tried in both the view and controller to use a variable for the
> > > title but it just doesn't work.
>
> > > E.g:
>
> > >         // grab category name and store in a variable:
> > >         $pageTitle = $this->pageTitle = $data['Category']['name'];
> > >         // Set channel variables for feed:
> > >         $channel = array (
> > >         'title' => $pageTitle,
>
> > > Has anybody managed this?
>
> > > Thanks in advance!
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Model with Dynamic Data Fields

2009-05-23 Thread marco.rizze...@gmail.com

Hi
My problem is about the project of the models of my web application
I have a model Document . The problem is that this model must have
dinamic data fields.
A document can have like fields : title .text , data
Another can have : title, number , attachment
ect...
This fields can have different type: some can be simple string, other
can be file , other can be text .

Substantially for the moment I have create only the model Document but
I've no idea how to handle everything else
I really hope that someone can help me
Many thanks
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: findAllThreaded root hack for version 1.2.x

2009-05-23 Thread Anna P

anyone?:)
--~--~-~--~~~---~--~~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---