Problem with afterFind for associated tables

2012-11-19 Thread Mark Wratten
We are using Cake 2.2.2 and we have the following tables -

Article - id, group_id, town_id, ...
Group - id, town_id, ...
Town - id, ...

The Article and Group tables need to modify their data with data from the 
Town table, so in each of those Models we have an afterFind callback that 
checks for the presence of Town data in the results and if found does the 
updates.

This works fine for the primary model. However Group is also an associated 
model to the Article table, so if I execute the following find function -

$this-Article-find('all', array('contain' = array('Town', 'Group', 
'Group.Town')));

Cake does run the query and assembles the data correctly, but the Group 
afterFind callback is called without the associated Town data, even though 
it is part of the query. As far as I can tell, the Group-afterFind is 
called before the queries for its associated tables are run.

I'm looking for an elegant way to do this within the model, rather than 
resorting to putting the code in the controller.

Thanks in advance

Mark

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: Problem with afterFind for associated tables

2012-11-19 Thread Mark Wratten
After experimenting for a while, I discovered that Cake actually calls my 
afterFind function twice for each matching row, but with different data 
formats -

The first time in the form - array(array('Group' = ('id' = ...)))
The second time in the form - array('id' = ... , 'Town' = array('id' = 
...)) so I do get the Town data. It is rather unfortunate that the data 
formats are different as it makes the afterFind code rather ugly.

Mark

On Monday, November 19, 2012 5:37:59 PM UTC-5, Mark Wratten wrote:

 We are using Cake 2.2.2 and we have the following tables -

 Article - id, group_id, town_id, ...
 Group - id, town_id, ...
 Town - id, ...

 The Article and Group tables need to modify their data with data from the 
 Town table, so in each of those Models we have an afterFind callback that 
 checks for the presence of Town data in the results and if found does the 
 updates.

 This works fine for the primary model. However Group is also an associated 
 model to the Article table, so if I execute the following find function -

 $this-Article-find('all', array('contain' = array('Town', 'Group', 
 'Group.Town')));

 Cake does run the query and assembles the data correctly, but the Group 
 afterFind callback is called without the associated Town data, even though 
 it is part of the query. As far as I can tell, the Group-afterFind is 
 called before the queries for its associated tables are run.

 I'm looking for an elegant way to do this within the model, rather than 
 resorting to putting the code in the controller.

 Thanks in advance

 Mark


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en.




Re: How to use two view(controller) in a page??

2012-09-04 Thread Mark Wratten
I am assuming you have a route that routes to a specific controller/action, 
e.g. pages controller, index action.
Then in you home page view View/Pages/index.ctp -

pWelcome to my home page./p

div id=news-summary
  h2News Summary/h2
  ?php echo $this-requestAction('/news/summary'); ?
/div

div id=login-form
  ?php echo $this-requestAction('users/login'); ?
/div

Then, in your News controller, create and action - summary, and a view file 
summary.ctp.
In your Users controller create action login (which should also handle the 
POST request when the user logs in) and a login.ctp view file.

Then when the home page is rendered, the news summary and login forms will 
be displayed.

Mark

On Monday, September 3, 2012 8:04:34 PM UTC-4, shyandsy wrote:

 could you put some details on, thanks a lot!
 Making a home page that includes login and news list.

 I can write a view and controller for that job login or news list, but I 
 don't know how to make that things togerther!!


 在 2012年9月3日星期一UTC-5上午12时22分41秒,Mark Wratten写道:

 Easiest is to use requestAction() in the homepage view.

 On Thursday, August 30, 2012 4:26:12 PM UTC-4, shyandsy wrote:

 I am kind of new guy on cakePhp. So the description as below:

 I hope to provide two function to users in the homepage, login and news. 
 The login uses the view login and the controller loginController, and 
 the news uses the news view and newscontroller.
 The problem is how to put the two view in the home page.

 (apologize, my first language is not English, if you meet some problem 
 about grammar, I will try to fix 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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: How to use two view(controller) in a page??

2012-09-02 Thread Mark Wratten
Easiest is to use requestAction() in the homepage view.

On Thursday, August 30, 2012 4:26:12 PM UTC-4, shyandsy wrote:

 I am kind of new guy on cakePhp. So the description as below:

 I hope to provide two function to users in the homepage, login and news. 
 The login uses the view login and the controller loginController, and the 
 news uses the news view and newscontroller.
 The problem is how to put the two view in the home page.

 (apologize, my first language is not English, if you meet some problem 
 about grammar, I will try to fix 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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: PHP functions in controller

2012-08-29 Thread Mark Wratten
$this-set('randword', 
$this-Word-findById(rand(1,$this-Word-find('count';

On Wednesday, August 29, 2012 10:24:26 AM UTC-4, Nareh Tarasyan wrote:

 Thanks Marcus

 but u know what I did here... see:

 $this-set('rand', rand(1,$this-Word-find('count'))); 
 $this-set('randword', $this-Word-findById());

 I want ID= value of rand function, but don know how to write 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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Subquery in join clause in CakePHP 2.2

2012-08-28 Thread Mark Wratten
Glad to. After some reading I was able to take it a step further and turn 
it into a custom find method, which nicely encapsulates the code in the 
model. In our app we 'broadcast' articles to a number of different towns, 
but because we also do a radius search that can result in duplicate rows 
being returned. So I needed a function that does a SELECT DISTINCT on the 
joining table to get unique ids, in the form of -

SELECT ... FROM articles Article JOIN (SELECT DISTINCT article_id FROM 
articles_towns WHERE town_id IN (...)) ArticleTown ON 
ArticleTown.article_id = Article.id

I decided to create a custom find method named broadcast.

In the Article model -

public $findMethods = array('broadcast' = true);

protected function _findBroadcast ($state, $query, $results = array()) {
if ($state == 'before') {
$query['joins'] = array(
array(
'table' = sprintf((SELECT DISTINCT article_id FROM articles_towns WHERE 
town_id IN (%s)), TownsComponent::neighbors()),
'alias' = 'ArticleTown',
'type' = INNER,
'conditions' = array('ArticleTown.article_id = Article.id')));
return $query;
}
return $results;
}

In the Controller -

$this-Article-find('broadcast', $options);

or

$this-paginate = ('broadcast', $options);
$this-paginate('Article');

In my case the list of town is in a static component, but could easily be 
passed in with the options. I think you will agree it can be done in a very 
tidy way with Cake. With older versions of Cake I used to see example code 
that was much longer than the SQL it generated and thought, what's the 
point, why not just use SQL? But I'm growing to like the new abilities of 
Cake and you can really minimize the amount of SQL you need to put in your 
code.

Disclaimer - there may be better ways to do the same thing that I have not 
thought of.

Mark

On Tuesday, August 28, 2012 12:08:38 PM UTC-4, ceap80 wrote:

 Hi Mark, could you post a code sample of how you solved?

 I'm always interested in querying the db the cakephpway.

 Thanks.

 On Monday, August 27, 2012 10:30:55 PM UTC-4:30, Mark Wratten wrote:

 Figured it out for myself, the subquery just goes in place of the table 
 name.

 On Monday, August 27, 2012 6:17:05 PM UTC-4, Mark Wratten wrote:

 Is there a 'Cake' way of including subqueries in join clauses of SQL 
 select statements?

 I'm looking to generate something in the form of -

 SELECT ... FROM table1
 JOIN (SELECT DISTINCT key FROM table2 WHERE ...) table2 ON table2.key = 
 table1.key

 I have been looking at joining tables in the docs, but it only seems to 
 support joining tables rather than expressions. I could move the DISTINCT 
 to the main query, but that does not perform as well, and also messes up 
 pagination.

 Thanks

 Mark



-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Subquery in join clause in CakePHP 2.2

2012-08-27 Thread Mark Wratten
Is there a 'Cake' way of including subqueries in join clauses of SQL select 
statements?

I'm looking to generate something in the form of -

SELECT ... FROM table1
JOIN (SELECT DISTINCT key FROM table2 WHERE ...) table2 ON table2.key = 
table1.key

I have been looking at joining tables in the docs, but it only seems to 
support joining tables rather than expressions. I could move the DISTINCT 
to the main query, but that does not perform as well, and also messes up 
pagination.

Thanks

Mark

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Subquery in join clause in CakePHP 2.2

2012-08-27 Thread Mark Wratten
Figured it out for myself, the subquery just goes in place of the table 
name.

On Monday, August 27, 2012 6:17:05 PM UTC-4, Mark Wratten wrote:

 Is there a 'Cake' way of including subqueries in join clauses of SQL 
 select statements?

 I'm looking to generate something in the form of -

 SELECT ... FROM table1
 JOIN (SELECT DISTINCT key FROM table2 WHERE ...) table2 ON table2.key = 
 table1.key

 I have been looking at joining tables in the docs, but it only seems to 
 support joining tables rather than expressions. I could move the DISTINCT 
 to the main query, but that does not perform as well, and also messes up 
 pagination.

 Thanks

 Mark


-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Best Practice to display data in layout or view

2012-08-11 Thread Mark Wratten
Option 2. is fine for simple stuff, i.e. grab a bunch of data from the 
database and render it, but if there is any complexity to the logic, then 
you end up loading your helpers with application logic, which in a pure MVC 
world belongs in a controller or component. So in that case, requestAction 
would be the purest approach but suffers the overhead of re-initializing 
the environment each time. Ideally, there would be some middle ground 
approach, which currently you have to roll yourself, by instantiating a new 
controller and calling the appropriate method yourself.

Mark

On Saturday, August 11, 2012 2:33:33 AM UTC-4, Sanjeev Divekar wrote:

 Hello,

 What is the best practice to display data e.g. list of products, events, 
 news in layout?

 1. Element - which requires to call requestAction() and also calls 
 beforeFilter from AppController each time
 2. Helper - need to use Model class in helper

 Regards,


-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Need help with reverse routing

2012-08-10 Thread Mark Wratten
I'm looking for some help with reverse routing as the documentation is a 
bit thin. Particularly for use with rendering objects such as 
PaginatorHelper.

I have a URL in the format - /state/city/page/slug which I route with -
Router::connect('/:state/:city/:page/*', array(
'controller' = 'pages', 'action' = 'display', 'level' = 'town'), array(
'state' = '[a-z][a-z]', 'city' = '[a-z]+', 'page' = '[^/]*', 'pass' = 
array('page')));

That works fine in the forward direction, but how do I get the 
PaginatorHelper to assemble the URL with the state and city pieces?

If I add another route for ajax requests, such as -
Router::connect('/ajax/:controller/:action/*');

That also works in the forward direction, but the URL generated by 
PaginatorHelper in the previous case now generates the URL in the form - 
/ajax/pages/display/...
So How do you tell the reverse routing which rule to use?

If I need to resort to a custom router, how do you tell the the Cake 
rendering functions to use the custom router?

Thanks in advance 

Mark

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Need help with reverse routing

2012-08-10 Thread Mark Wratten
cricket - thanks for the reply, I will try it and see if it works.

Thanks

Mark

On Friday, August 10, 2012 4:18:32 PM UTC-4, cricket wrote:

 Here's a generic element I use for pagination: 

 http://pastebin.com/JvKbyWUi 

 Perhaps you can modify that to your own needs. With Cake 2.x I've had 
 to make some changes to what I had been using. I suppose that I must 
 be doing something wrong that it requires the AppController snippet. 

 I think your route could be improved a bit: 

 Router::connect( 
 '/:state/:city/:page/:slug', 
 array( 
 'controller' = 'pages', 
 'action' = 'display', 
 'level' = 'town' 
 ), 
 array( 
 'state' = '[a-z]{2}', 
 'city' = '[-a-z]+', 
 'page' = '[0-9]+', 
 'slug' = '[-a-z]+', 
 'pass' = array('page', 'slug') 
 ) 
 ); 


 I've added the slug to the URL, which allows you to pass it as an 
 action param. Otherwise, I'm not sure what good it would do you. 

 I've also made a better regex for state, and sluggified city -- a 
 name with a space or apostrophe would not match your regex. Because 
 you want the city name to appear in URLs, you'll need to store both 
 the display text and slug for each city. 

 As for what's being passing as params, personally, I would pass state, 
 city, and slug. I also think it's a bit odd that this is pointing to 
 PagesController. But then, I don't know the details so ... 

 On Fri, Aug 10, 2012 at 2:33 PM, Mark Wratten ma...@trimar.comjavascript: 
 wrote: 
  I'm looking for some help with reverse routing as the documentation is a 
 bit 
  thin. Particularly for use with rendering objects such as 
 PaginatorHelper. 
  
  I have a URL in the format - /state/city/page/slug which I route with - 
  Router::connect('/:state/:city/:page/*', array( 
  'controller' = 'pages', 'action' = 'display', 'level' = 'town'), 
 array( 
  'state' = '[a-z][a-z]', 'city' = '[a-z]+', 'page' = '[^/]*', 'pass' 
 = 
  array('page'))); 
  
  That works fine in the forward direction, but how do I get the 
  PaginatorHelper to assemble the URL with the state and city pieces? 
  
  If I add another route for ajax requests, such as - 
  Router::connect('/ajax/:controller/:action/*'); 
  
  That also works in the forward direction, but the URL generated by 
  PaginatorHelper in the previous case now generates the URL in the form - 
  /ajax/pages/display/... 
  So How do you tell the reverse routing which rule to use? 
  
  If I need to resort to a custom router, how do you tell the the Cake 
  rendering functions to use the custom router? 
  
  Thanks in advance 
  
  Mark 
  
  -- 
  You received this message because you are subscribed to the Google 
 Groups 
  CakePHP group. 
  To post to this group, send email to cake...@googlegroups.comjavascript:. 

  To unsubscribe from this group, send email to 
  cake-php+u...@googlegroups.com javascript:. 
  Visit this group at http://groups.google.com/group/cake-php?hl=en-US. 
  
  


-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




How override base URL in PaginatorHelper

2012-08-09 Thread Mark Wratten
We are migrating an app from Cake 1.1 to 2.2.1. Our URLs are in the format 
/state/town/page/slug and I have got the Router setup to forward route 
correctly, but have not got reverse routing to work yet.

In function such as Html-link you can specific the URL as a string or 
array, so you can set the correct URL. However the Paginator function Next 
and Prev appear to only accept the URL parameter as an array which is not 
creating the correct URL as it does not override the base url. Is there a 
way to force the base URL as with the other functions, or do I need to 
create a custom router?

Mark

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Model associations

2012-08-09 Thread Mark Wratten
Do you have var $belongsTo = array('Category', 'Product'); in your 
CatProduct model?

On Thursday, August 9, 2012 10:43:43 AM UTC-4, André Luis wrote:

 Hi people, it´s me again!

 I am using a habtm relationship in my application, it works 100% fine... 
 But the Product menu is created dinamically with it´s Categories... so i 
 have Product model and the Category model with habtm relationship between 
 them.

 In AppController i have to set at beforeFilter the variable 
 products_categories, as i dont need the products of each category right 
 now i use 
 $this-set('products_categories,$this-Product-CatProduct-find('all')); 
 and it works fine... BUT, latter when i need to read the product category 
 with it´s products, i would use $this-CatProduct-read('*',$id); right? 
 BUT it´s returning ONLY the category, not the products relateds, but if i 
 comment the line $this-Product-CatProduct-find('all') it works fine, and 
 returns me the category and all related products.

 What i am doing wrong? Isnt there anyway to get only the categories them 
 get one category with it´s relateds?

 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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Why is composite primary key bad?

2012-08-08 Thread Mark Wratten
One possible exception might be HABTM tables, consisting of just the 
foreign keys to the related tables. MySQL only supports clustering on the 
primary key and using a composite primary key would give you a covered 
index, which in theory should perform a bit better. Though in practice, I 
have not found much difference and usually add an integer primary key 
column to those tables as well.

-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Select Last Record From Database

2012-08-08 Thread Mark Wratten
In your beforeSave callback you could include a cal that does something 
like - SELECT MAX(invoice_number) FROM table, then in your code, generate 
the next number. Though if the code is going to be used by many people 
simultaneously, you would need to create a unique index on that column, to 
prevent duplicates.

On Friday, August 3, 2012 2:02:15 AM UTC-4, Mr. Manager wrote:

 Dear All,

 Current I want to generate invoice number like INV1 and so I would 
 like to get the last value of filed no (stand for invoice number) in order 
 to generator one increment when we create a new invoice.

 I am looking forward to hearing from you as soon as possible.

 Best Regard,
 Mr. Manager,


-- 
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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Problem with ordering by a calculated field

2012-08-08 Thread Mark Wratten
Generally, the Haversine Formula is the best one to calculate distance 
between two points, given the lat/long of both the client and the hotel.
See http://en.wikipedia.org/wiki/Haversine_formula for more information.

SELECT acos(sin(radians(P2.latitude)) * sin(radians(P2.latitude)) + 
cos(radians(P1.latitude)) * cos(radians(P2.latitude)) * 
cos(radians(P1.longitude) - radians(P2.longitude))) * 3963.1 AS distance

In CakePHP, you can implement that as a calculated field.

On Wednesday, August 1, 2012 8:26:53 AM UTC-4, yassine yas wrote:

 hi daniel

 i have the same probleme like you and i want to help me.

 my english is not good.

 well i develop a backEnd that receive the request of the client (lat  
 lng) and it's calculate the distance from the client to the hotels

 how can i calculate the distance i calculated field and sort it

 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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Problem with ordering by a calculated field

2012-08-08 Thread Mark Wratten
Oops, should be

SELECT acos(sin(radians(P1.latitude)) * sin(radians(P2.latitude)) + 
cos(radians(P1.latitude)) * cos(radians(P2.latitude)) * 
cos(radians(P1.longitude) - radians(P2.longitude))) * 3963.1 AS distance

On Wednesday, August 8, 2012 12:47:37 PM UTC-4, Mark Wratten wrote:

 Generally, the Haversine Formula is the best one to calculate distance 
 between two points, given the lat/long of both the client and the hotel.
 See http://en.wikipedia.org/wiki/Haversine_formula for more information.

 SELECT acos(sin(radians(P2.latitude)) * sin(radians(P2.latitude)) + 
 cos(radians(P1.latitude)) * cos(radians(P2.latitude)) * 
 cos(radians(P1.longitude) - radians(P2.longitude))) * 3963.1 AS distance

 In CakePHP, you can implement that as a calculated field.

 On Wednesday, August 1, 2012 8:26:53 AM UTC-4, yassine yas wrote:

 hi daniel

 i have the same probleme like you and i want to help me.

 my english is not good.

 well i develop a backEnd that receive the request of the client (lat  
 lng) and it's calculate the distance from the client to the hotels

 how can i calculate the distance i calculated field and sort it

 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.
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.




Re: Is there a lighter weight alternative to requestAction?

2012-06-29 Thread Mark Wratten
On Friday, June 29, 2012 12:30:39 AM UTC-4, Ilie wrote:

 Hello,

 Another way to do this is to have one controller requestAction to fetch 
 (as array or objects) all the data you need to render your modules, then 
 using Elements or View Blocks to do the actual rendering of the modules.

Yes, that's exactly what I'm doing to assemble the modules. With view 
blocks, we can divide the page into panels and create a view block for each 
panel, so by specifying a panel attribute in the module, we can render each 
module in the specified panel and assemble the layout in the common view. 
That part is working very well.

However, suppose the content editors want to write an article about farmers 
markets and they want to display a list of farmers markets in the local 
area, we can tell them to embed something like 
{/organizations/list/tag:farmers-markets/radius:10/count:5} in the content. 
Or somewhere else they want a list of music events, then we would tell them 
to embed {/events/list/tag:music/radius:75/count:10}. So by passing that 
URL to requestAction, it will call the appropriate controller and action 
and return the rendered content. It keeps the code simple and modular, in 
the spirit of MVC. We are doing a form of that in Cake 1.1 right now but 
the rendering time is a bit longer than I would like. I suppose we can 
create our own version of the dispatcher, though I'm not sure of the 
benefit vs. maintainability. 

As you say, caching is important and we do do that, so really it is the 
first time hit that counts.

Mark

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Is there a lighter weight alternative to requestAction?

2012-06-28 Thread Mark Wratten
That's the dilemma we are facing. The traditional MVC paradigm where a URL 
maps to a controller and action is fine for simple sites, but for more 
complex sites the model falls apart. Our site started as a straightforward 
MVC design, but then the users wanted to add their own landing pages and 
control what appears on each page. It is not practical to create a new 
controller/action/view for each new landing page so the site became a 
hybrid of traditional MVC and a CMS with the ability to embed active 
content.

@Florian, that's essentially what we are doing. For the updated design, we 
are routing all requests to a single controller/action/view and using a 
Helper to embed modules in the content. The module positions are 
represented by tokens in the content, so we don't know which modules to 
load until rendering the view. As most of the modules are active content we 
need to use requestAction to assemble the module content from data in the 
database and render in the view. Because requestAction loads a new 
environment it adds a significant overhead especially when loading a lot of 
modules. And it also involves a bit of a kludge to change the routing on 
the fly. It is working, but I feel it could be done in a cleaner, simpler, 
more efficient way, but I am struggling how to figure out how to do that 
and stay within the Cake paradigm.

Mark

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Is there a lighter weight alternative to requestAction?

2012-06-27 Thread Mark Wratten
We are migrating our site from Cake 1.1 to 2.1 or 2.2. The site is highly 
modular which gives the site admins the ability to choose and position 
modules on each landing page. Many of these modules are mini MVC blocks and 
we are using requestAction to render them. So there can be as many as a 
dozen requests on a page, which as the documentation points out, can be 
slow as Cake initializes a new environment for each request. The 
documentation talks about being able to specify the controller/action 
directly, to bypass the router, but that does not work, the code just uses 
the router to convert the request to a URL before creating a new dispatcher.

I'm wondering if there is a lighter weight way of calling multiple MVC 
blocks in a single request? I have been looking at the new event manager, 
but it is not clear whether it can be used to render a view. I'm curious 
whether anyone else has had the same problem and come up with a better 
method?

Incidentally the new view blocks in 2.1 are great and really work well for 
a modular design.

Thanks

Mark

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Model Associations Question

2012-06-27 Thread Mark Wratten
In you code you have 'className' = 'Bookings'. Shouldn't that be 
'className' = 'Booking' ?

You should also be able to shorten it to - var $belongsTo = 
array('Booking') as you are using booking_id as your foreign key.

MArk

On Wednesday, June 27, 2012 2:34:25 AM UTC-4, Sanfly wrote:

 Sorry, I'll repost this - my database is Bookingdate not Bookingnight

 Hi

 Im having some trouble with a model association - yes, I have tried the 
 manual!

 For each Booking I have, I can have many Bookingnights

 *Booking*
 Booking.id
 

 *Bookingdate*
 Bookingdate.id
 Bookingdate.booking_id

 In my Booking model, I am able to get all the associated Bookingdates 
 without issue.

 var $hasMany = array(
 'Bookingdate' = array(
 'className' = 'Bookingdates',
 'foreignKey'= 'booking_id',
  
 )
 
 );

 My problem is when I try and go back the other way.  I have my 
 Bookingdate.id, and want to get the associated booking.

 I would think that it should be belongsTo in my Bookingdate model?

 var $belongsTo = array(
 'Booking' = array(
 'className' = 'Bookings',
 'foreignKey' = 'booking_id'
 )

 ); 

 == Doesnt Work

 Is there something obvious that I'm missing?

 On Wednesday, 27 June 2012 18:26:42 UTC+12, Sanfly wrote:

 Hi

 Im having some trouble with a model association - yes, I have tried the 
 manual!

 For each Booking I have, I can have many Bookingnights

 *Booking*
 Booking.id
 

 *Bookingnight*
 Bookingnight.id
 Bookingnight.booking_id

 In my Booking model, I am able to get all the associated Bookingnights 
 without issue.

 var $hasMany = array(
 'Bookingdate' = array(
 'className' = 'Bookingdates',
 'foreignKey'= 'booking_id',
  
 )
 
 );

 My problem is when I try and go back the other way.  I have my 
 Bookingnight.id, and want to get the associated booking.

 I would think that it should be belongsTo?

 var $belongsTo = array(
 'Booking' = array(
 'className' = 'Bookings',
 'foreignKey' = 'booking_id'
 )

 ); 

 == Doesnt Work

 Is there something obvious that I'm missing?

 Thanks!





-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: Slightly different models, merge or separate?

2012-06-27 Thread Mark Wratten
You could consider storing your measurement data in a single column in the 
measurements table as a JSON string. Thus the logic would be very simple as 
you only need to convert to and from JSON. The downside is you won't be 
able to easily query against values in the measurement data. Anything you 
want to include in a query should be in a separate column.

Mark

On Monday, June 25, 2012 4:12:43 AM UTC-4, Poyan Nabati wrote:

 *How should I implement this on the backend?*


- *Two models.* I thought of having two models, Goal and Measurement, 
where Measurement has a corresponding field in the database called value 
that's agnostic of it's contents (in other words, a VARCHAR that I 
interpret differently depending on context). I believe, however, that this 
approach will create a lot of special code for each of the different cases 
down the line. 
- *Many models.* Another way to do it would be to create 
NumericMeasurement, BooleanMeasurement etc etc for each of the different 
measurement-types. In Goal I could have a field that indicates the type 
 and 
create the association Goal hasMany (each of the measurement types). Do 
 you 
see any problems with this approach?

 Is there another, better approach that I haven't thought about?

 How would you solve this?


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: One model, multiple pagination in a single view with conditions?

2012-06-27 Thread Mark Wratten
You can only paginate one way at a time, so presumably you can set the 
associations dynamically depending on the parameters from jQuery. Though 
separate models might be cleaner as you can hard-code the associations.

Mark

On Monday, June 25, 2012 11:41:16 PM UTC-4, 42startups wrote:

 As the title suggests, is there a simple way to do this?

 Or should I create a separate model?

 Here's the code:

 $this-paginate = array('limit'=30); 
 $this-Hashtag-Pin-bindModel(array('hasOne' = array('HashtagsPin')), 
 false);
 $this-set('hashtag', $this-paginate('Pin', 
 array('HashtagsPin.hashtag_id' = $id)));
 $this-set('thought', $this-paginate('Pin', 
 array('HashtagsPin.hashtag_id' = $id,'Pin.url'=null))); 

 So I need to paginate 'hashtag' and 'thought' separately. I'll be 
 attaching infinite scroll jquery to both.


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: URGENT - NEED HELP IN ASSOCIATION HABTM

2012-06-27 Thread Mark Wratten
Often it is easier to create a model for the linking table, i.e. 
OrderProduct and use belongsTo Order and Product rather than using HABTM 
associations. Then query using that model.

Mark

On Monday, June 25, 2012 11:10:11 AM UTC-4, Caio Vncius wrote:

 Hello,

 need a help in a ratio of two-mode HABTM tables.

 I have a table called orders and another called produts. Estaão related 
 orders_produts the table. Unless the relationship but usually when I need 
 to display per EXAMPLE products which have an order, I do not. How can I do 
 to get all the products of an order and pull the table daod sda produts 
 such as price and description ...

 sorry my english


-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


Re: How get Exception Handler to use plugin layout?

2012-06-22 Thread Mark Wratten
Majna, thanks for the tip. That inspired me to think about it a bit more 
and I figured it was simpler and cleaner to set the layout in bootstrap.php 
where the plugin is loaded. That is working well.

Thanks

Mark

On Friday, June 22, 2012 2:24:36 PM UTC-4, majna wrote:

 You can use AppController or MyPluginAppController beforeRender() callback 
 to check if controller name is 'CakeError'
 and set $this-layout = 'MyPlugin.error' 

 or extend ExceptionRenderer


 http://book.cakephp.org/2.0/en/development/exceptions.html#using-a-custom-renderer-with-exception-renderer-to-handle-application-exceptions

 On Thursday, June 21, 2012 7:11:30 PM UTC+2, Mark Wratten wrote:

 We are rewriting our site to use Cake 2.1 and I'm really loving the new 
 features. The site has a back-end administration function which I have 
 implemented as a plugin, including its own layout file. The admin function 
 runs off its own host name, so I have a line in bootstrap.php that checks 
 the hostname and if it matches, loads the plugin with its own routes.

 Everything works great until an exception occurs. When that happens, the 
 code uses the layout file from the main app, rather than the plugin. I'd 
 like the Exception Handler to use the plugin layout, but I don't know how 
 to configure it to do so other than by writing a new exception handler. Is 
 there a quick way of configuring the layout to use?

 Thanks

 Mark



-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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


How get Exception Handler to use plugin layout?

2012-06-21 Thread Mark Wratten
We are rewriting our site to use Cake 2.1 and I'm really loving the new 
features. The site has a back-end administration function which I have 
implemented as a plugin, including its own layout file. The admin function 
runs off its own host name, so I have a line in bootstrap.php that checks 
the hostname and if it matches, loads the plugin with its own routes.

Everything works great until an exception occurs. When that happens, the 
code uses the layout file from the main app, rather than the plugin. I'd 
like the Exception Handler to use the plugin layout, but I don't know how 
to configure it to do so other than by writing a new exception handler. Is 
there a quick way of configuring the layout to use?

Thanks

Mark

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


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