Re: RegEx: Dash Problem

2009-03-09 Thread KS

Thanks for your suggestion!

It turns out I was using the clean function of CakePHP's Sanitize
class.  It was doing something to my dashes :)
One I moved that function AFTER my validation, everything worked
great!

KS

On Mar 8, 5:00 am, Graham Weldon  wrote:
> Hey,
>
> Try escaping the hyphen:
>
> \-
>
> That should work out for you.
>
> Cheers,
>
> Graham Weldon
> w.http://grahamweldon.com
> e. gra...@grahamweldon.com
> p. +61 407 017 293
>
> On Sat, 7 Mar 2009 16:02:58 -0800 (PST), KS  wrote:
> > Hi there,
>
> > This might not be a cakePHP issue, but here goes...
>
> > I use CakePHP + WAMP on Windows.
> > My problem is that whenever there is a dash in a pattern and an input
> > string has a dash, no match occurs.
> > As a result, validation fails (like the built in e-mail and phone
> > number validations).
>
> > I have tried using a custom validation method with the following
> > code:
>
> > function valid_phone($data) {
> >   $pattern = "^[0-9]{3}-[0-9]{4}$";
> >   $phone_no = trim($data['phone']);
> >   if (ereg($pattern, $phone_no))
> >         return 1;
> >   else
> >         return 0;
> > }
>
> > If I remove the dash from the pattern and input 7 digits, everything
> > works fine.
> > If I add the dash and input something like "123-45657", validation
> > fails.
>
> > This is not the only pattern I've tried, all with the same results.
>
> > Any ideas?
>
> > Thank you!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



RegEx: Dash Problem

2009-03-08 Thread KS

Hi there,

This might not be a cakePHP issue, but here goes...

I use CakePHP + WAMP on Windows.
My problem is that whenever there is a dash in a pattern and an input
string has a dash, no match occurs.
As a result, validation fails (like the built in e-mail and phone
number validations).

I have tried using a custom validation method with the following
code:

function valid_phone($data) {
  $pattern = "^[0-9]{3}-[0-9]{4}$";
  $phone_no = trim($data['phone']);
  if (ereg($pattern, $phone_no))
return 1;
  else
return 0;
}

If I remove the dash from the pattern and input 7 digits, everything
works fine.
If I add the dash and input something like "123-45657", validation
fails.

This is not the only pattern I've tried, all with the same results.

Any ideas?

Thank you!

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Checking for config.time in cake session

2008-02-21 Thread ks

In session.php in functions __checkValid

There is a check with the Config.time.

  if ($this->_userAgent == $this->read("Config.userAgent") && $this-
>time <= $this->read("Config.time")) {


We have run into issues where sometimes users get logged out and found
the session id string empty but also found that commenting the second
part of the above && helped

Is there reason for that check against Config.time  - is it a security
check to prevent someone writing a script to access all the pages?

Also is there any reason why the session id string becomes empty?

thanks
Krishnan

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



cake i18n localization

2007-05-17 Thread ks

the __( ...) method seems to call the debug_backtrace() method to get
the directory by getting the stacktrace

Looking at the data returned and the call, it looks expensive to do
this for every string I call to translate.

Is there a way to do it differently or override this?

Thanks,
Krishnan


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



Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-05-09 Thread ks

Mariano,

Am I missing something simple? Can you let me know an example were you
were able to use with redirect? Should I do something different in my
application.

I am keen to use your new framework for our unit tests but right now I
am blocked on this.

Thanks
Krishnan

On May 1, 8:26 am, ks <[EMAIL PROTECTED]> wrote:
> Mariano,
>
> I have tried writing some tests. This looks great. Thanks.
>
> I am running into an issue when my controller actions is doing
> redirects. For e.g. in my login action, the user is redirected to
> another page if login is successful. However the cake redirect
> function has an exit in it ( which is useful for the web application)
> but thetestframework exits when that happens.
>
> What is the best way to handle this? In TestSuite, I think the
> dispatch maybe handled differently since I was able totestthe same
> action with a post.
>
> Thanks
> Krishnan
>
> On Apr 25, 2:04 am, ks <[EMAIL PROTECTED]> wrote:
>
> > Great! Thanks Mariano.
>
> > I downloaded the code yesterday and see the testAction method which i
> > did not have in the previous version. Thanks for your help, I will
> > give this a try
>
> > Krishnan
>
> > On Apr 23, 3:28 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
> > wrote:
>
> > > I haven't had time to write a Bakery article regarding this, but update to
> > > latest SVN head and look for testAction() in CakeTestSuite. I still have 
> > > to
> > > add a couple of things but I'll try to give you an idea here:
>
> > > Say you have typical Articles controller, with articles model, and it 
> > > looks
> > > like this:
>
> > > 
> > > class ArticlesController extends AppController {
> > > var $name = 'Articles';
> > > var $helpers = array('Ajax', 'Form', 'Html');
>
> > > function index($short = null) {
> > > if (!empty($this->data)) {
> > > $this->Article->save($this->data);
> > > }
>
> > > if (!empty($short)) {
> > > $result = $this->Article->findAll(null, 
> > > array('id',
> > > 'title'));
> > > } else {
> > > $result = $this->Article->findAll();
> > > }
>
> > > if (isset($this->params['requested'])) {
> > > return $result;
> > > }
>
> > > $this->set('title', 'Articles');
> > > $this->set('articles', $result);
> > > }
>
> > > }
>
> > > ?>
>
> > > Create then a file named articles_controller.test.php on your
> > > app/tests/cases/controllers directory and inside put:
>
> > > 
> > > class ArticlesControllerTest extends CakeTestCase {
> > > function startCase() {
> > > echo 'StartingTestCase';
> > > }
>
> > > function endCase() {
> > > echo 'EndingTestCase';
> > > }
>
> > > function startTest($method) {
> > > echo 'Starting method ' . $method . '';
> > > }
>
> > > function endTest($method) {
> > > echo '';
> > > }
>
> > > function testIndex() {
> > > $result = $this->testAction('/articles/index');
> > > debug($result);
> > > }
>
> > > function testIndexShort() {
> > > $result = $this->testAction('/articles/index/short');
> > > debug($result);
> > > }
>
> > > function testIndexShortGetRenderedHtml() {
> > > $result = $this->testAction('/articles/index/short',
> > > array('return' => 'render'));
> > > debug(htmlentities($result));
> > > }
>
> > > function testIndexShortGetViewVars() {
> > > $result = $this->testAction('/articles/index/short',
> > > array('return' => 'vars'));
> > > debug($result);
> > > }
>
> > > function test

Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-05-01 Thread ks

Mariano,

I have tried writing some tests. This looks great. Thanks.

I am running into an issue when my controller actions is doing
redirects. For e.g. in my login action, the user is redirected to
another page if login is successful. However the cake redirect
function has an exit in it ( which is useful for the web application)
but the test framework exits when that happens.

What is the best way to handle this? In TestSuite, I think the
dispatch maybe handled differently since I was able to test the same
action with a post.

Thanks
Krishnan

On Apr 25, 2:04 am, ks <[EMAIL PROTECTED]> wrote:
> Great! Thanks Mariano.
>
> I downloaded the code yesterday and see the testAction method which i
> did not have in the previous version. Thanks for your help, I will
> give this a try
>
> Krishnan
>
> On Apr 23, 3:28 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > I haven't had time to write a Bakery article regarding this, but update to
> > latest SVN head and look for testAction() in CakeTestSuite. I still have to
> > add a couple of things but I'll try to give you an idea here:
>
> > Say you have typical Articles controller, with articles model, and it looks
> > like this:
>
> > 
> > class ArticlesController extends AppController {
> > var $name = 'Articles';
> > var $helpers = array('Ajax', 'Form', 'Html');
>
> > function index($short = null) {
> > if (!empty($this->data)) {
> > $this->Article->save($this->data);
> > }
>
> > if (!empty($short)) {
> > $result = $this->Article->findAll(null, array('id',
> > 'title'));
> > } else {
> > $result = $this->Article->findAll();
> > }
>
> > if (isset($this->params['requested'])) {
> > return $result;
> > }
>
> > $this->set('title', 'Articles');
> > $this->set('articles', $result);
> > }
>
> > }
>
> > ?>
>
> > Create then a file named articles_controller.test.php on your
> > app/tests/cases/controllers directory and inside put:
>
> > 
> > class ArticlesControllerTest extends CakeTestCase {
> > function startCase() {
> > echo 'StartingTestCase';
> > }
>
> > function endCase() {
> > echo 'EndingTestCase';
> > }
>
> > function startTest($method) {
> > echo 'Starting method ' . $method . '';
> > }
>
> > function endTest($method) {
> > echo '';
> > }
>
> > function testIndex() {
> > $result = $this->testAction('/articles/index');
> > debug($result);
> > }
>
> > function testIndexShort() {
> > $result = $this->testAction('/articles/index/short');
> > debug($result);
> > }
>
> > function testIndexShortGetRenderedHtml() {
> > $result = $this->testAction('/articles/index/short',
> > array('return' => 'render'));
> > debug(htmlentities($result));
> > }
>
> > function testIndexShortGetViewVars() {
> > $result = $this->testAction('/articles/index/short',
> > array('return' => 'vars'));
> > debug($result);
> > }
>
> > function testIndexFixturized() {
> > $result = $this->testAction('/articles/index/short',
> > array('fixturize' => true));
> > debug($result);
> > }
>
> > function testIndexPostFixturized() {
> > $data = array('Article' => array('user_id' => 1, 'published'
> > => 1, 'slug'=>'new-article', 'title' => 'New Article', 'body' => 'New
> > Body'));
> > $result = $this->testAction('/articles/index',
> > array('fixturize' => true, 'data' => $data, 'method' => 'post'));
&

Re: How to Display info from Different tables ?

2007-04-25 Thread ks

I am dont know if this is the best way to accomplish this but you can
use the requestAction and renderElements to accomplish this.

Create a view - say cpanel/home

This will include elements - userelement, categoryelement,
itemselement

e.g.
renderElement('userelement'); ?>

Create each element in the elements folder ( and name it as
userelement.ctp) - this will probably be the same as your view.ctp for
each - except you will call requestAction('users/index')  and your
element can display the data object from controller however it wants.

The cpanel  view can decide where it wants the userelement to go..
you can have a table with sidebars etc. in your cpanel view

In your users controller - in index method - have some code to check
if its a requestAction  - as follows
if $blah = $this->User->findAll(.  usual stuff)
//checks for requestAction
if(isset($this->params['requested'])) {
   return $blah;


Hope this helps

I did read some articles saying this was a slower way to do it. Does
anyone know if there is a better way to accomplish the same?

On Apr 24, 6:02 am, 浪漫様 <[EMAIL PROTECTED]> wrote:
> Dear mates,
> I was wondering how to display information from different tables on a
> same controller/view.
> For example... i want a control panel, that manages different sections
> of my website, and i want to show the last 5 entries in each table on
> the initial menu [ as a preview ].
> When the login is succeed at "www.mysite.com/cpanel/admins/login" goes
> to "www.mysite.com/cpanel/admins/index" and here i want to show the
> last 5 records of each table on my DB for maintenaice... "users",
> "categories", "items" but i want them centralized at
> "www.mysite.com/cpanel/admins/index" instead of:
>
> "www.mysite.com/cpanel/users/index"
> "www.mysite.com/cpanel/categories/index"
> "www.mysite.com/cpanel/items/index"
>
> Also... how to limit CakePHP to take only 5 records [ "LIMIT (x,5)" on
> mysql ] ?
> Thank you very much!
> Best Regards,
>
> Rohman


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



Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-24 Thread ks

Great! Thanks Mariano.

I downloaded the code yesterday and see the testAction method which i
did not have in the previous version. Thanks for your help, I will
give this a try

Krishnan

On Apr 23, 3:28 pm, "Mariano Iglesias" <[EMAIL PROTECTED]>
wrote:
> I haven't had time to write a Bakery article regarding this, but update to
> latest SVN head and look for testAction() in CakeTestSuite. I still have to
> add a couple of things but I'll try to give you an idea here:
>
> Say you have typical Articles controller, with articles model, and it looks
> like this:
>
> 
> class ArticlesController extends AppController {
> var $name = 'Articles';
> var $helpers = array('Ajax', 'Form', 'Html');
>
> function index($short = null) {
> if (!empty($this->data)) {
> $this->Article->save($this->data);
> }
>
> if (!empty($short)) {
> $result = $this->Article->findAll(null, array('id',
> 'title'));
> } else {
> $result = $this->Article->findAll();
> }
>
> if (isset($this->params['requested'])) {
> return $result;
> }
>
> $this->set('title', 'Articles');
> $this->set('articles', $result);
> }
>
> }
>
> ?>
>
> Create then a file named articles_controller.test.php on your
> app/tests/cases/controllers directory and inside put:
>
> 
> class ArticlesControllerTest extends CakeTestCase {
> function startCase() {
> echo 'StartingTestCase';
> }
>
> function endCase() {
> echo 'EndingTestCase';
> }
>
> function startTest($method) {
> echo 'Starting method ' . $method . '';
> }
>
> function endTest($method) {
> echo '';
> }
>
> function testIndex() {
> $result = $this->testAction('/articles/index');
> debug($result);
> }
>
> function testIndexShort() {
> $result = $this->testAction('/articles/index/short');
> debug($result);
> }
>
> function testIndexShortGetRenderedHtml() {
> $result = $this->testAction('/articles/index/short',
> array('return' => 'render'));
> debug(htmlentities($result));
> }
>
> function testIndexShortGetViewVars() {
> $result = $this->testAction('/articles/index/short',
> array('return' => 'vars'));
> debug($result);
> }
>
> function testIndexFixturized() {
> $result = $this->testAction('/articles/index/short',
> array('fixturize' => true));
> debug($result);
> }
>
> function testIndexPostFixturized() {
> $data = array('Article' => array('user_id' => 1, 'published'
> => 1, 'slug'=>'new-article', 'title' => 'New Article', 'body' => 'New
> Body'));
> $result = $this->testAction('/articles/index',
> array('fixturize' => true, 'data' => $data, 'method' => 'post'));
> debug($result);
> }
>
> }
>
> ?>
>
> Ok couple of things:
>
> * In second parameter of testAction() you send an array with attributes.
> Among others use:
>
> - return: set to what you want returned. Valid values are: 'vars'
> (so you get the view vars available after executing action), 'render' (so
> you get html generated once action is run), or 'return' to get the returned
> value when action uses $this->params['requested']. Default is 'return'.
>
> - fixturize: set to true if you want your models auto-fixturized (so
> your application tables get copied, along with their records, totesttables
> so if you change data it does not affect your real application.) If you set
> 'fixturize' to an array of models, then only those models will be
> auto-fixturized while the other will remain with live tables.
>
> - data: see last item
>
>

Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-23 Thread ks

Mariano,

Great!

Do you know when that will be available in ? We currently need to
write unit tests for our controllers and I am debating if we should
wait until this is released or use testsuite in the meantime and move
to CakeTest once thats available?

Thanks
Krishnan

On Apr 17, 10:37 am, "Mariano Iglesias" <[EMAIL PROTECTED]>
wrote:
> Be a little patient and you are about to see some awesome stuff in 
> Caketestsuitetotestcontrollers.
>
> -MI
>
> ---
>
> Remember, smart coders answer ten questions for every question they ask.
> So be smart, be cool, and share your knowledge.
>
> BAKE ON!
>
> blog:http://www.MarianoIglesias.com.ar
>
> -Mensaje original-
> De: cake-php@googlegroups.com [mailto:[EMAIL PROTECTED] En nombre
> de ks
> Enviado el: Martes, 17 de Abril de 2007 01:55 p.m.
> Para: Cake PHP
> Asunto: Re: whats the relationship between CakePHP 1.2testsuiteN
> SimpleTest
>
> Not sure if someone has found a way totestcontrollers with get/post
> in CakeTest


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



Re: whats the relationship between CakePHP 1.2 test suite N SimpleTest

2007-04-17 Thread ks

Both use SimpleTest. In the case of test suite, you have add that in
your vendors folder as well.

>From what I was able to do:

TestSuite allows you to test your controllers using get/post as well
which is useful. I did not find that in the CakeTest

TestSuite integrates with bake2 and can run from the command line as
well. Although with a small change to test.php ( that cake uses) you
can get that working from the command line as well.

Not sure if someone has found a way to test controllers with get/post
in CakeTest


On Apr 16, 5:49 am, "hydra12" <[EMAIL PROTECTED]> wrote:
> I may be wrong, but I think it works like this:
>
> The cake testsuite (and cakebaker's) are wrappers for simpletest.
> Simpletest is used as a vendor, and the testsuite 'cake-ifies' it.
> (Is that a word?  Probably not . . .)  Anyway, simpletest is doing the
> actual testing, but the test suite makes everything work in a cakey
> way (loading models, controllers, etc).
>
> I hope that helps.  Somebody please correct me if I'm wrong.
>
> hydra12
>
> On Apr 16, 5:37 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > whats the relationship between CakePHP 1.2 test suite N SimpleTest?
>
> > is test suite new feature of the 1.2 ? and does test suite just use
> > SimpleTest as fundamental?
> > and when you download and put SimpleTest in right place ,it enable the
> > test suite??
>
> > and when use bake.php ,it seems like it output test for SimpleTest not
> > cakephp test suite .but why ?


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



I18n and Localization support

2007-03-27 Thread ks

We are building a site that needs to support multiple languages -
content ( titles of topics etc), user names and DB strings etc. will
be in multiple languages - including chinese.

>From the information I found on the site, the 1.1 version will not
support this right? Will the alpha version  (1.2) available on the
download page support what we are looking for? If you can point me to
a version that we can use, that would be great.

Thanks
Krishnan


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