CakePHP 1.2.8 released

2010-08-21 Thread mark_story
The CakePHP development team is happy to announce the release of
CakePHP 1.2.8[1]. 1.2.8 is a maintenance release for the 1.2 branch
and contains bugfixes and optimizations for features found in 1.2.

Since the release of CakePHP 1.2.7 in April, there have been more than
30 commits and 20 tickets resolved. There have been a few changes that
may affect your application.

- Welsh was added to the supported list of locales in l10n
- Controller::validateErrors now accepts arbitrary model objects.
This better reflects the intention of the documentation.
- Calling bindModel/unbindModel multiple times now correctly resets
associations.
- TextHelper::autoLink() no longer strtolower()'s the urls, as this
created issues with URL shorteners.
- HttpSocket no longer loses auth credentials when multiple requests
are made with same object.
- String::insert() will now correctly handle two keys starting with
the same subpattern.

Be sure to check the full changelog[2] for all changes that have
occurred, and the related tickets. There is continued work and ongoing
support for 1.3.  Work on the 2.0 branch is also ongoing, with several
branches seeing development, if you are interested in helping with the
development of 2.0, take a look at the wiki pages[3], and open
tickets. We'd like to thank everyone who contributed tickets, patches
and documentation to this release. Cakefest 2010[4] is also
approaching quickly and if you haven't purchased tickets they are
moving quickly, so get one while you still can.

Download a packaged release [1]
View the changelog[2]

[1] http://github.com/cakephp/cakephp/downloads
[2] http://cakephp.lighthouseapp.com/projects/42648/changelog-1-2-8
[3] http://cakephp.lighthouseapp.com/projects/42648/milestones/71894-200
[4] http://cakefest.org

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Warning (2): range() [function.range]: step exceeds the specified range [CORE\cake\libs\set.php, line 235]

2010-08-21 Thread Marcos Mendonça
I'm sure.

With $internacoes[0]['data_entrada'] I'm just picking the first
element of the $internacoes array. That works fine.



On Aug 20, 1:43 pm, cricket  wrote:
> 2010/8/20 Marcos  Mendonça :
>
>
>
> > I'm getting this error on a given view.
>
> > Warning (2): range() [function.range]: step exceeds the specified
> > range [CORE\cake\libs\set.php, line 235]
>
> > range - [internal], line ??
> > Set::numeric() - CORE\cake\libs\set.php, line 235
> > DboSource::fields() - CORE\cake\libs\model\datasources\dbo_source.php,
> > line 2019
> > DboSource::generateAssociationQuery() - CORE\cake\libs\model
> > \datasources\dbo_source.php, line 1217
> > DboSource::read() - CORE\cake\libs\model\datasources\dbo_source.php,
> > line 811
> > Model::find() - CORE\cake\libs\model\model.php, line 2093
> > Model::read() - CORE\cake\libs\model\model.php, line 1128
> > InternosController::view() - APP\controllers\internos_controller.php,
> > line 13
> > Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
> > Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
> > [main] - APP\webroot\index.php, line 83
>
> > Line 13 of my controller is:
> > $this->set('interno', $this->Interno->read(null, $id));
>
> > This is the view method:
> >    function view($id = null) {
> >        if (!empty($id)) {
> >            $this->set('interno', $this->Interno->read(null, $id)); //
> > line 13
> >            $internacoes = $this->Interno->data['Internacoes'];
>
> >            $data_in = new DateTime($internacoes[0]['data_entrada']);
> >            if (empty($internacoes[0]['data_saida'])) {
> >                $data_out = new DateTime;
> >            } else {
> >                $data_out = new DateTime($internacoes[0]
> > ['data_saida']);
> >            }
> >            $duracao = $data_in->diff($data_out);
>
> >            $this->set('duracao', $duracao);
>
> >        } else {
> >            $this->redirect(array('action' => 'index'));
> >        }
> >    }
>
> > This is my model:
> > class Interno extends AppModel {
> >    var $name = 'Interno';
>
> >    var $helpers = array('Time');
> >    var $validate = array(
> >                'nome' => array('rule' => 'notEmpty'));
> >    var $hasMany = array(
> >        'Internacoes' => array(
> >            'className' => 'Internacao',
> >            'order' => 'Internacoes.created DESC'),
> >        'Visitas' => array(
> >            'className' => 'Visita',
> >            'order' => 'Visitas.data DESC'),
> >        'Enderecos' => array('className' => 'Endereco'));
>
> >    var $hasAndBelongsToMany = array(
> >        'Contato' => array (
> >            'className' => 'Contato',
> >            'joinTable' => 'contatos_internos',
> >            'foreignKey' => 'interno_id',
> >            'associationForeignKey' => 'contato_id'));
> > }
>
> > My suspicions are on the DateTime and date_diff usage, because when I
> > take that part of the code off, it works smoothly with no warnings.
>
> > Any ideas of what could be going on here?
>
> Are you sure that line 13 is not this one?
>
> $data_in = new DateTime($internacoes[0]['data_entrada']);
>
> That [0] looks odd to me. Try this:
>
> $this->set('interno', $this->Interno->read(null, $id));
>
> die(debug($this->Interno->data));

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Two same type object in the same table

2010-08-21 Thread cricket
On Fri, Aug 20, 2010 at 8:13 PM, toki  wrote:
> Here is the context:
> I want to store theorems objects in my database.
> A theorem as many sons and many fathers.
> So it's a graph and not a simple tree.
>
> I can't create a table like (id, theorem_id, theorem_id) : this
> syntaxe is forbidden
>
> An ugly solution : (id, parentid, theorem_id), with added code in
> controllers
>
> Do you see a better way todo ? Can cakephp do such things ?
>

I think what you're dealing with is a "directed acyclic graph". Have a
look at this article: "A Model to Represent Directed Acyclic Graphs
(DAG) on SQL Databases":
http://www.codeproject.com/KB/database/Modeling_DAGs_on_SQL_DBs.aspx

It's been awhile for me since I thought about these, and I haven't
attempted to use this with Cake. But I think that article might help
you come up with a solution. If all works out, please consider posting
something at the Bakery.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Easy cake pagination!

2010-08-21 Thread Okalany Daniel
On Thu, Aug 19, 2010 at 8:06 PM, bradmaxs  wrote:

> Does your Count model have a count field and if so, how does that
> relate to Place?  I am a little confused about what you are trying to
> do.  Does your Count model have a place_id for the relationship
> reference?
>
> Yes, my Count model has a field count. and yes, there is a place_id field
with the belongs two relationship.

> One thing you could try is in the hasMany array in the Place model you
> could always declare the order there.
>
> var $hasMany = array(
>'Count' => array(
>'className' => 'Count',
>'foreignKey' => 'place_id',
>'order' => 'Count.count ASC',
>)
> );
>
> I'm trying to order based on the value of the child relationship.
I'm tracking daily hits for a place. So im trying to retrieve the places by
the place with the highest hits on a particular day.
I can do ->find() without problems and with the same options, but paginate
is troublesome.

>
>
>
>
>
>
> http://book.cakephp.org/view/1043/hasMany
>
> On Aug 19, 4:42 am, Okalany Daniel  wrote:
> > The SQL Query generated doesn't have a join:
> >
> > *Warning* (512) : *SQL Error:* 1054: Unknown
> > column 'Count.count' in 'order clause'
> > [*CORE\cake\libs\model\datasources\dbo_source.php*, line *673*]
> > Code  | Context 
> >
> > $out = null;if ($error) {
> > trigger_error('' . __('SQL
> > Error:', true) . " {$this->error}", E_USER_WARNING);
> >
> > $sql=   "SELECT `Place`.`id`, `Place`.`name`, `Place`.`guy_count`
> FROM
> > `places` AS `Place`   WHERE 1 = 1   ORDER BY `Count`.`count` ASC "
> > $error  =   "1054: Unknown column 'Count.count' in 'order clause'"
> > $out=   null
> >
> > DboSource::showQuery() -
> > CORE\cake\libs\model\datasources\dbo_source.php, line 673
> > DboSource::execute() - CORE\cake\libs\model\datasources\dbo_source.php,
> line 263
> > DboSource::fetchAll() -
> > CORE\cake\libs\model\datasources\dbo_source.php, line 407
> > DboSource::read() - CORE\cake\libs\model\datasources\dbo_source.php, line
> 812
> > Model::find() - CORE\cake\libs\model\model.php, line 2090
> > PlacesController::index() - APP\controllers\places_controller.php, line
> 16
> > Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
> > Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
> > [main] - APP\webroot\index.php, line 83
> >
> > *Query:* SELECT `Place`.`id`, `Place`.`name`, `Place`.`guy_count` FROM
> > `places` AS `Place`   WHERE 1 = 1   ORDER BY `Count`.`count` ASC
> >
> >
> >
> >
> >
> > On Wed, Aug 18, 2010 at 8:59 PM, bradmaxs  wrote:
> > > What fields do you have in the Count table?  When I get this error it
> > > is because the join was incorrect - usually. Also - when the errors
> > > occur, usually there is a code and a context link that will show you
> > > more of the dump when clicked on and what the conflicting code is.  It
> > > should have also printed out the sql query at the top and you can see
> > > the exact query and troubleshoot from there.
> >
> > > On Aug 17, 6:07 am, Okalany Daniel  wrote:
> > > > the model Place hasMany Count, and Count belongs to place.
> > > > So using the Containable behaviour, i can specify conditions for
> child
> > > > fields like:
> >
> > > > $this->Place->Behaviors->attach('Containable');
> > > > $this->paginate['Place'] = array(
> > > > 'contain' => array('Count'=>array(
> > > > 'conditions'=>array('Count.date'=>date('Y-m-d'))
> > > > )),
> > > > //'order' => 'Count.count DESC'
> > > > );
> > > > $places = $this->paginate('Place');
> >
> > > > But i'd like to order the parent Model by a field in a child model.
> When
> > > i
> > > > uncomment the line that starts 'order', i get the error:
> > > > SQL Error: 1054: Unknown column 'Count.count' in 'order clause'
> >
> > > > Thanks in advance.
> >
> > > > On Tue, Aug 17, 2010 at 10:28 AM, AD7six 
> wrote:
> >
> > > > > On Aug 16, 5:25 pm, Okalany Daniel  wrote:
> > > > > > Hi, Andy Dawson,
> > > > > > i'm having a similar problem,
> >
> > > > > How similar is your sql error or code ? I find it hard to compare
> to
> > > > > things I can't see :).
> >
> > > > > > but i don't understand your fix.
> >
> > > > > I didn't get as far as to propose a fix. However I'll give you this
> > > > > hint: the book almost certainly has a relevant example and hasMany/
> > > > > hasAndBelongsToMany don't generate joins in the main query -
> hasOnes
> > > > > do.
> >
> > > > > AD
> >
> > > > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp
> > > others
> > > > > with their CakePHP related questions.
> >
> > > > > 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
>

CakeNewb: Models joint where one has 2 Foreign Keys

2010-08-21 Thread jamie_chong
This is my second day using/learning Cake so please bear with me :)

I'll try to keep things simple, but there is a lot of data here. I
didnt' want to leave anything out.

Let's say I have these database tables:

my_lists (id, name)
(1, "List One")
(2, "List Two")

items(id, name)
(1, "Item One")
(2, "Item Two")
(3, "Item Three")
(4, "Item Four")

items_my_lists(item_id, my_list_id)
(2, 1)
(3, 1)
(4, 1)
(3, 2)
(4, 2)

my_comments(id, my_list_id, item_id, message)
(1, 1, NULL, "Comment For List One")
(2, NULL, 4, "Comment For Item Four")
(3, 1, 4, "Comment for List One, Item Four")
(4, 2, 4, "Comment for List Two, Item Four")

My Models look like this:

class List extends AppModel
{
public $name = "List";
public $hasAndBelongsToMany = "Item";
public $hasMany = "Comment";
}

class Item extends AppModel
{
public $name = "Item";
public $hasAndBelongsToMany = "List";
public $hasMany = "Comment";
}

class Comment extends AppModel
{
public $name = "Comment";
}

Notice my_comments has Two Foreign Keys (my_list_id, item_id). This is
so I can have comments specifically for
1. my_lists (item_id is NULL)
2. items (my_list_id is NULL)
3. items in my_lists (both my_list_id and item_id are set)

Here is my problem. For each of the two queries (shown below), I only
want comments to be returned for Items if and only if they match the
item_id AND the list_id. Right now I'm getting Comments that belong to
other lists. Furthermore, I don't want comments for Items if either
list_id or item_id are NULL. And lastly, comments for MyList should
only appear if item_id is NULL.


Now when I run a find() search in my Controller, I get for "List One":

$this->MyList->find("first",array(
"conditions"=>array("MyList.id"=>1),
"recursive" => 2
));

Array
(
[MyList] => Array
(
[id] => 1
[name] => List One
)

[MyComment] => Array
(
[0] => Array
(
[id] => 1
[my_list_id] => 1
[item_id] =>
[message] => Comment List One
)

[1] => Array
(
[id] => 3
[my_list_id] => 1
[item_id] => 4
[message] => Comment List One, Item Four
)

)

[Item] => Array
(
[0] => Array
(
[id] => 2
[name] => Item Two
[MyComment] => Array
(
)

)

[1] => Array
(
[id] => 3
[name] => Item Three
[MyComment] => Array
(
)

)

[2] => Array
(
[id] => 4
[name] => Item Four
[MyComment] => Array
(
[0] => Array
(
[id] => 2
[my_list_id] =>
[item_id] => 4
[message] => Comment Item Four
)

[1] => Array
(
[id] => 3
[my_list_id] => 1
[item_id] => 4
[message] => Comment List One, Item Four
)

[2] => Array
(
[id] => 4
[my_list_id] => 2
[item_id] => 4
[message] => Comment List Two, Item Four
)

)

)

)

)

And this is what I get for List Two
$this->MyList->find("first",array(
"conditions"=>array("MyList.id"=>2),
"recursive" => 2
));


Array
(
[MyList] => Array
(
[id] => 2
[name] => List Two
)

[MyComment] => Array
(
[0] => Array
(
[id] => 4
[my_list_id] => 2
[item_id] => 4
[message] => Comment List Two, Item Four
)

)

[Item] => Array
(
[0] => Array
(
[id] => 3
[name] => Item Three
[MyComment] => Array
(
)

)

[1] => Array
(
[id] => 4
[name] => Item Four
[MyComment] => Array
(
[0] => Array
(
[id] => 2
[my_list_id] =>
[item_id] => 4
[message] => Comment Item Four
)

[1] => Array
(
[id] => 3
[my_list_id] => 1
[item_id] => 4
[message] => Comment List One, Item Four
)

[2] => Array
(
[id] => 4
[my_list_id] => 2
[item_id] => 4
[message] => Comment List Two, Item Four
)

)

)

)
)

Ideally for the same two queries, I'd get these results

HABTM and Pagination

2010-08-21 Thread Walt
Hello Everone,

Perhaps I'm daft. I find folks that have similar issues, but none seem
to be as direct as I need it to be.

I'm trying to write a simple search, but the HABTM relationship I have
seems to be getting in the way.

I have three models in the search: Person, Role, and Institution.

Person HABTM Role
Person Belongs to Institution

In my controller, I've built my conditions like this:

 $this->Person->recursive = 2;

 $contain = array(
   'Institution',
   'Role'
 );

 $this->paginate = array(
   'limit' => 10,
   'order' => array('Person.username' => 'asc'),
 );

 $conditions = array(
   'Person.username LIKE' => '%'.$username.'%',
   'Person.department LIKE' => '%'.$department.'%',
   'Person.email LIKE' => '%'.$email.'%',
   'Institution.id' => $institutionId,
   'Role.id' => $roleId,
 );

 $this->set('people', $this->paginate('Person',$conditions));

The above code works if I omit the Role criteria. Since I would only
like to search for people with certain roles, I really do need that
extra bit. With the Role criteria, I recieve the following error,
which seems consistent with something hairy going on with the HABTM I
have set up:

Unknown column 'Role.id' in 'where clause'

Could someone point me to a decent solution. It seems like this should
have been worked out before.

I sincerely appreciate any help you can offer.

Thanks,
Walt

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Two same type object in the same table

2010-08-21 Thread toki
Here is the context:
I want to store theorems objects in my database.
A theorem as many sons and many fathers.
So it's a graph and not a simple tree.

I can't create a table like (id, theorem_id, theorem_id) : this
syntaxe is forbidden

An ugly solution : (id, parentid, theorem_id), with added code in
controllers

Do you see a better way todo ? Can cakephp do such things ?

Thank you =)

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


How to access DboSource from shell

2010-08-21 Thread dmc
I have to to set DboSource::$cacheMethods to false (http://
api13.cakephp.org/view_source/dbo-source/#line-64).
Tried it this (and many other) way(s).
But apparently it does not work.
I really need to disable this caching but only for this shell.

cacheMethods = false;
parent::initialize();
}


function main()
{

}



I also tried the same in the startup- and in the main-function.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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: Pagination across controllers

2010-08-21 Thread Miloš Vučinić
I found one interesting solution to manage everything you need in
Pagination..

basicaly, it is all cake. I had an issue, for example, I had to make
two different paginations, depending on which page are you looking for
the same model (admin or regular user). In pagination var, you can set
everything you want, from order for pagination to condition for which
ones to show (my e.g , post must be published by admin in order to be
viewed by a regular user on the comments page. So I have admin view
and regular index for posts).
There is only one problem left, and that is count ! No mater what
condition you take, cake's pagination will always show you count for
all of the database entries and then you can throw away your code. You
have to rewrite pagination count function in order to make it work,
but then the other one will not work. So I just rewrited the
pagination funciton and made one paramter that it receive. I made it a
global variable in app controller to make it visible no matter what,
because for some reason if I just added param to function it didn't
work. So i set it globaly for 1 if I want the first count and for 2 if
I want the other one (depending on how i have set var paginations
condition) and it is all.

Let me know if you need thew source code...

On Aug 20, 5:19 pm, Philip Thompson  wrote:
> Hi all.
>
> I've done plenty of searching and been unable to find a solution yet. I'm 
> also fairly new to Cake, but not to PHP. I have ajax pagination working from 
> the currently-view controller/model. However, if I attempt to paginate a list 
> that comes from a different model/controller, I only get 1 result.
>
> From Hardware, I get a properly paginated list of hardware items. Hardware 
> has a belongsTo relationship to HardwareType and Location. From Location, I 
> want to include a paginated list of hardware items. If I call the same method 
> from LocationsController as I do in HardwaresController, I only get 1 result.
>
>  class HardwaresController extends AppController
> {
>     public $components = array('RequestHandler');
>     public $helpers = array('Js'=>array('Mootools'));
>     public $paginate = array(
>         'Hardware' => array(
>             'limit' => 3,
>             'order' => array(
>                 'Hardware.name' => 'ASC'
>             ),
>         ),
>     );
>
>     public function index () {
>         $this->set('hardware', $this->listing()); // This works as expected
>     }
>
>     public function listing () {
>         return $this->paginate('Hardware');
>     }
>
> }
>
> class LocationsController extends AppController
> {
>     ...
>     public function view ($id) {
>         ...
>         App::import('Controller', 'Hardwares');
>         $Hardwares = new HardwaresController;
>         $Hardwares->constructClasses();
>         $this->set('hardwares', $Hardwares->listing()); // This is only 1 
> result
>     }
>
> }
>
> class Hardware extends AppModel
> {
>     public $name = 'Hardware';
>     public $belongsTo = array('HardwareType', 'Location');
>     public $order = array('Hardware.name ASC');
>     ...}
>
> ?>
>
> Can anyone explain why I'm only getting a single result (which is the actual 
> first result) and/or please provide some assistance on how to resolve the 
> issue?
>
> Thanks in advance.
>
> ~Philip
>
> http://lonestarlightandsound.com/
>
> "innerHTML is a string. The DOM is not a string, it's a hierarchal object 
> structure. Shoving a string into an object is impure and similar to wrapping 
> a spaghetti noodle around an orange and calling it lunch."

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


cakephp and Ajax pagination (mootools)

2010-08-21 Thread Mariano C.
I have followed perfectly this guide (
http://mark-story.com/posts/view/creating-simple-ajax-pagination-with-cakephp-1-3-and-mootools
) but it only works at 50%.

I just have two link for pagination: 1 & 2. If I go to:
htp://my_web.com/items/user/page:1 the link to second page is active,
thus if I click this link the second page will be opened in ajax
style. OK!

Now, link for page 2 is disabled and link to the first page is active,
but, if I click this link the page will be reloaded entirely as normal
call.

Viceversa happen if I call htp://my_web.com/items/mariano/page:2.
Clicking on link 1 will load new page in AJAX, successivly clicking on
page 2 will happen with classic call.

Why?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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