Re: error handling: how to handle missing secondary database gracefully

2012-02-09 Thread qwanta
Thanks for the idea, I looked into it a little, but I don't want to
mess too much with the innards of my app as someone else will be
taking it over soon.

What I ended up doing was placing a link next to the empty job number
textbox that opens a new browser tab/window with the job number list
in it. That way if the job number server is unavailable it doesn't
crash the entire cakephp app.

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


error handling: how to handle missing secondary database gracefully

2012-02-07 Thread qwanta
I am reading a list of job numbers from a mysql database on an old
server on my intranet. This server is completely independent from the
server for my cakephp app and database. If the server is there, I
populate a combobox with the list of job numbers, however, if it is
down, I would like to handle the error gracefully and just show an
empty textbox (for manual data entry) instead of the list of job
numbers.

Any ideas on how to do this? I have tried to override the missingTable
function in error.php, but have trouble redirecting to my original
page. I think it would work better if I could avoid the error being
triggered altogether.

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: Conceptual problem Model on View ..

2010-01-06 Thread qwanta
You would put the code to calculate the can_close values for each row
in the model or in the controller.

To put the code in the model, do not use find('all') but create your
own method in the model, for example find_all_model_a. Now in this
function, call $r = $this->find('all'), then iterate through the
result array $r using a foreach and add a field called "can_close"
that is true or false based on your criteria. From the controller you
call $ma = $this->MODEL_A->find_all_model_a(). Then $this->set('ma',
$ma); and ma contains everything you need in the controller with logic
in the model.

On Jan 6, 4:13 pm, Bottazzo  wrote:
> I ll up this post just one more time.. thanks.
>
> On 4 jan, 16:18, Bottazzo  wrote:
>
> > Yes Dave, this is what I do now. But, if the condition can_close() is
> > more than check  if the status fields == 'OPEN' ? .. for ie: check
> > status field + check parent model status + check created date .. (and
> > in the future add more instructions in can_close() )...  so... i
> > really need to call the can_close() method .. right?
>
> > Can you understand my problem now man? Do what u say it's solving my
> > problem now.. but in the future.. can cause some problem to me..
>
> > :)
>
> > Thanks for the reply Dave!
>
> > On Dec 31 2009, 3:55 am, "Dave"  wrote:
>
> > > Not sure if I follow 100% but why not just grab the data where its OPEN?
>
> > > $this->find('all', array('conditions' => array('MODEL_A.status' =>
> > > 'open')));
>
> > > Or if you need to grab all the data then add the "close" link to OPEN 
> > > cases
> > > do the foreach
> > > Controller: (or better yet make a function in the MODEL)
> > > $this->set('cases', $this->find('all'));
>
> > > VIEW:
>
> > > Foreach ($cases as $case)
> > > {
> > >         if ($case['Model']['status'] = 'open')
> > >         {
>
> > >                 $case_status = "button code here";
>
> > >         } else {
>
> > >                 $case_status = 'Case Closed';
>
> > >         }
>
> > > Your looped data / html  so if its open it will
> > > add the button,if not "Case Closed"  will be there
>
> > > }
>
> > > Not 100% ure of the question but hope that helps. Maybe someone else has a
> > > different idea.
>
> > > Dave
>
> > > -Original Message-
> > > From: cake-php@googlegroups.com [mailto:cake-...@googlegroups.com] On 
> > > Behalf
>
> > > Of Bottazzo
> > > Sent: December-30-09 10:31 AM
> > > To: CakePHP
> > > Subject: Conceptual problem Model on View ..
>
> > > Hi guys, im don't speak english but ill try to explain my problem for u. 
> > > So,
> > > sorry for my poor english.
>
> > > Ok, let imagine that I have an Model named MODEL_A that have an status 
> > > field
> > > ( OPENED and CLOSED )..
> > > I have an method on MODEL_A named can_close() that return true if i can
> > > close the element..
>
> > > I want to show a list of MODEL_A elements in the page.. so in the 
> > > controller
> > > I call a MODEL_A->find(all).. ok.. get all instances...and $this->set to
> > > view... nice!
>
> > > Ok, now i have all my MODEL_A elements on VIEW... and I want to do
> > > this: foreach element check .. if MODEL_A->can_close()  == true...
> > > show button CLOSE .. on the side of element name.. if can_close() == 
> > > false..
> > > hide it.
>
> > > So... a ill need to import my model to the view.. to call can_close 
> > > method..
> > > right? but.. call model on view is the worst sin for MVC pattern ahn??
>
> > > So.. what I do now friends?
>
> > > Thank you for all..
>
> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelpothers
> > > 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
> > > cake-php+athttp://groups.google.com/group/cake-php?hl=en
> > > No virus found in this incoming message.
> > > Checked by AVG -www.avg.com
> > > Version: 9.0.722 / Virus Database: 270.14.122/2590 - Release Date: 
> > > 12/30/09
> > > 03:57:00
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: Problem handling search form fior multiple values

2009-08-03 Thread qwanta

If you print out the contents of the $this->data array ( debug($this-
>data) ).
You should see:
[vendor_id] => Array
(
[0] => 1
[1] => 2
)

So that's where you access those values, they are in the array.

On Jul 27, 3:31 pm, NIghtmare327  wrote:
> I have a form I am using to do searches, and am having issues with the
> return values from the form.  here is the code segment from the form:
>
> = index.ctp =
>
>                          echo $form->button('Reset Form', array
> ('type'=>'reset', 'style'=>'width:200px;height:35px'));
>                 echo $form->input('Search.keywords');
>                 echo $form->input('Search.name',array('after'=>__
> ('wildcard is *',true)));
>                 //echo $form->input('Search.vendor_id');
>                 echo $form->input('Search.vendor_id', array('type' =>
> 'select', 'multiple'=>true));
>                 echo $form->submit('Search');
>         ?>
>
> It shows me themultiplelist, but when I print the passed values in
> the controller, this is what I get:
>
> Array ( [Search.vendor_id] => Array )
>
> It appears I am getting the word Array back rather than the values of
> the selected items.
>
> Any thoughts on this matter?  let me know if you need to see more of
> the source to see what is happening.  Just as some background, Vendors
> is a lookup table for vendors based on vendor_id obviously.  I want to
> be able to do a search based uponmultiplevendors rather than just
> 1.  I have the search for one working, just not this one.  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: saving a view to .htm file

2009-06-05 Thread qwanta

Experimenting a bit more, it seems that another straightforward way to
do this is use the php function "file_get_contents" to get a string
with the view.
The advantage is that any view can be accessed even in a different
cake app (as mine is).

On Jun 5, 10:13 am, qwanta  wrote:
> Thanks brian. I didn't know render returned a string - I had looked up
> the function in the book (where the return val isn't documented) but
> not in the source code.
>
> On Jun 4, 12:47 pm, brian  wrote:
>
>
>
> > Have a look at Controll:render() method. It returns a string that you
> > could write to a file. However, I'm not sure how that might affect
> > also rendering the same view to the browser.
>
> >http://api.cakephp.org/view_source/controller/#line-755http://book.ca...
>
> > I suppose, if for some reason, calling render() twice (once manually,
> > to save your file, and again automatically, as usual) will mess things
> > up for the browser output, you could write the string to a file, then
> > echo the same string. You might have to set the appropriate headers,
> > though.
>
> > But that's all speculation. Try calling render yourself to write to
> > the file and see if Cake wwill still call it automatically for browser
> > output, as normal.
>
> > On Wed, Jun 3, 2009 at 8:10 PM, qwanta  wrote:
>
> > > I am drawing a blank on this one, any help appreciated. Basically my
> > > view is a calibration record that also needs to be saved in a folder
> > > for backup purposes. Is it possible to save the view as an htm file,
> > > just as if you selected "Save Page As" in Firefox?
--~--~-~--~~~---~--~~
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: saving a view to .htm file

2009-06-05 Thread qwanta

Thanks brian. I didn't know render returned a string - I had looked up
the function in the book (where the return val isn't documented) but
not in the source code.


On Jun 4, 12:47 pm, brian  wrote:
> Have a look at Controll:render() method. It returns a string that you
> could write to a file. However, I'm not sure how that might affect
> also rendering the same view to the browser.
>
> http://api.cakephp.org/view_source/controller/#line-755http://book.cakephp.org/view/428/render
>
> I suppose, if for some reason, calling render() twice (once manually,
> to save your file, and again automatically, as usual) will mess things
> up for the browser output, you could write the string to a file, then
> echo the same string. You might have to set the appropriate headers,
> though.
>
> But that's all speculation. Try calling render yourself to write to
> the file and see if Cake wwill still call it automatically for browser
> output, as normal.
>
>
>
> On Wed, Jun 3, 2009 at 8:10 PM, qwanta  wrote:
>
> > I am drawing a blank on this one, any help appreciated. Basically my
> > view is a calibration record that also needs to be saved in a folder
> > for backup purposes. Is it possible to save the view as an htm file,
> > just as if you selected "Save Page As" in Firefox?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



saving a view to .htm file

2009-06-03 Thread qwanta

I am drawing a blank on this one, any help appreciated. Basically my
view is a calibration record that also needs to be saved in a folder
for backup purposes. Is it possible to save the view as an htm file,
just as if you selected "Save Page As" in Firefox?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



sorting a table with javascript (no page reloads)

2009-05-13 Thread qwanta

I was looking for a way to sort a table without requerying the
database for the data with a new ORDER clause.

This javascript library I found did just that, so I thought I would
share it.

http://www.kryogenix.org/code/browser/sorttable/

All you have to do is download sorttable.js and place in the webroot/
js folder. Add a $javascript->link('sorttable', false); to the top of
the view and add class='sortable' to the  tag.

That's it! You should now be able to click on the column tables
headers to sort. Usually this stuff never works painlessly, but this
seems to be the rare case where it does.
--~--~-~--~~~---~--~~
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: Poll: what do you hate about CakePHP?

2009-05-11 Thread qwanta

There are a lot of things to like in cakephp, but if I had to say what
aggravates me the most it's the seemingly wasteful and inefficient SQL
calls that cake makes. The first time I turned on debug = 2 I was
astounded at the close to 100 sql calls on a basic page that 1 or 2
SQL statements should have covered. It seems like when working with
find queries with tables two or more levels removed from the
originating model, all hell breaks loose as cake is unable to figure
out JOINS more than one level deep. This also makes it impossible to
set conditions on a table field that's two or more levels removed from
the original. So after first learning $uses and recursive, then
jettisoning that for "containable" behaviour, it turns out I have to
write custom SQL queries after all as soon as my app gets a little
more complicated than the beginner examples.

I think there could be some major improvements there, and I understand
they are on the way for v2; but I'm surprised this doesn't come up
more often.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



containable behavior nested conditions

2009-05-11 Thread qwanta

Well, I finally got to grips with containable behavior and have
successfully been able to write my find queries to return just the
information I need.
Now I am trying to take this to the next level and put conditions in
the contain array, but I am running into problems. I have found quite
a few posts related to this in the group, but none seem to have a
consistent solution that I can get working.
Basically, I have a function like this in my Item model:

function getBigItemList( $class ) {
  $arr_contain = array(
'Product' => array(
  'fields'=> array('id', 'model_number', 'range_min',
'range_max'),
  'EquipmentType' => array(
'fields'=>array('id','type'),
'EquipmentClass'=> array(
  'fields'=>array('class','id'),
  'conditions'=> array ('EquipmentClass.id = '.$class)
)
  ),
),
  );

$arr_c =array( 'contain' => $arr_contain );
$i_list = $this->find('all', $arr_c);
return $i_list;
}

I am trying to set a condition on the EquipmentClass table which is a
few steps removed from the Item table. (Item->Product->EquipmentType-
>EquipmentClass). Instead of returning all Items of EquipmentClass.id
= $class, I get all the Items in the table but those with a different
EquipmentClass.id than $class return a blank for that value.
I could simply eliminate the extra items from the returned array, but
the query takes a long time and I would like to optimize it to return
only the Items with the right EquipmentClass.id. What is the best way
to approach this? (I would like to force a JOIN of the equipment class
table into the main query if possible)
--~--~-~--~~~---~--~~
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: Is it possible to set the index of a select box after populating it with find('list')?

2009-05-05 Thread qwanta

Both 'selected'=> & 'default'=> seem to do the trick. Thanks!

On May 5, 6:44 am, andy  wrote:
> Seehttp://book.cakephp.org/view/199/options-selected. In the view,
> you will need to do something like this:
>
> $form->input('fieldname', array('options' => array($listvalue),
> 'selected' => 'desiredselectvalue') );
>
> On May 4, 3:56 pm, qwanta  wrote:
>
> > In the controller I do a find('list') to get an array ready for
> > populating a select box. I am quite stumped as to how I would set the
> > selected index of the select box in the view.
> > This is a case where the automagic situation (editing a record) is not
> > applicable - it is a log entry form and a new record each time.
>
> > 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
-~--~~~~--~~--~--~---



Is it possible to set the index of a select box after populating it with find('list')?

2009-05-04 Thread qwanta

In the controller I do a find('list') to get an array ready for
populating a select box. I am quite stumped as to how I would set the
selected index of the select box in the view.
This is a case where the automagic situation (editing a record) is not
applicable - it is a log entry form and a new record each time.

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



Cakephp does same SQL query multiple times (foreign key)

2009-04-28 Thread qwanta

I have a simple database set-up and have optimized the query using
cakephp's containable behavior to where I get only the fields I need
(I check this with a debug command to see the array). However when I
set the debug level to 2 in core.php, I notice many repeat SQL calls
on foreign keys.

For example:

115 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 50
116 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 47
117 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 49
118 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 47
119 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
120 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
121 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
122 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
123 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
124 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
125 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
126 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
127 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
128 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
129 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
130 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
131 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
132 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 14
133 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 21
134 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 21
135 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 21
136 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 21
137 SELECT `Manufacturer`.`name` FROM `manufacturers` AS
`Manufacturer` WHERE `Manufacturer`.`id` = 21

Where manufacturers is a table two levels removed from the main table.
It seems that cake should be able to cache and reuse the result for
the same `Manufacturer`.`id`.

Is there a way to achieve this? Does this only happen at debug level 2
perhaps and not level 1? (And how to I find out what sql queries are
going on at levels 0 & 1?) 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: Pulling data to use in default.ctp menu

2009-04-25 Thread qwanta

I had a similar problem (display the logged in username in the
default.ctp header), and used the beforeFilter function in the
app_controller. This is a function that when defined in a controller
will execute before any controller action, so if you place it in
app_controller.php the same code will execute before any action in any
controllers and you can do your $this->set() there to setup your list
for the default.ctp view.

A word of caution, if you define beforeFilter in a normal controller.
be sure to call:
parent::beforeFilter();
so that the app_controller beforeFIlter executes.


On Apr 22, 10:58 am, blake  wrote:
> Hello,
>
> I have a menu being generated in my default.ctp file, and I need the
> menu options to change depending on a users permissions. I have a
> component to handle all the checking and returning an array I can use,
> but I am unsure how to properly get that data into the default.ctp
> layout.
>
> What controller would I use the component in to pass the data through
> to default.ctp?
--~--~-~--~~~---~--~~
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 way to find out if onetomany record is used (before deleting it)?

2009-04-14 Thread qwanta

Thanks, that's what I was looking for, I have not used behaviors yet.
While researching beforeDelete I came across the hasAny() function
which also helps.

My current way of doing things also displays a list of all the records
("books") that belongTo the record that has been attempted to be
deleted ("author"), so the jury's still out on if coding this with a
behavior would simplify things. I'll have to experiment a bit more.

On Apr 14, 11:26 am, Richard  wrote:
> Depending on your database, you may be able to use constraints on the
> foreign keys of your database ("ON DELETE RESTRICT"), however that's a
> responsive check rather than pro-active. In your situation, you may find
> creating a behavior would be beneficial. The behavior would run the checks
> on the beforeDelete callback and you can restrict it at that level instead
> of a database.
>
> Richard
>
> On Tue, Apr 14, 2009 at 3:41 PM, qwanta  wrote:
>
> > In the case where If I have a one to many relationship like Authors-
> > >Books and I would like to delete an author - but only if this author
> > has no books - is there a buiilt-in way to check?
>
> > I find that I run into this situation a lot (every time a table has a
> > foreign key), and at the moment manually write a function in the model
> > to check this. eg. for the Books model a method with the author_id as
> > parameter that returns true if the author has books, false otherwise.
> > But it seems like cakephp should be able to check this based on the
> > model relationships, so is there something built-in I am missing?
>
> > 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
-~--~~~~--~~--~--~---



easy way to find out if onetomany record is used (before deleting it)?

2009-04-14 Thread qwanta

In the case where If I have a one to many relationship like Authors-
>Books and I would like to delete an author - but only if this author
has no books - is there a buiilt-in way to check?

I find that I run into this situation a lot (every time a table has a
foreign key), and at the moment manually write a function in the model
to check this. eg. for the Books model a method with the author_id as
parameter that returns true if the author has books, false otherwise.
But it seems like cakephp should be able to check this based on the
model relationships, so is there something built-in I am missing?

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: simple authentication with roles

2009-04-10 Thread qwanta

I also wanted to mention that if you try this out with a controller
called TestsController, the authentication doesn't seem to work -
everyone (even not logged on) is given access to all functions. I
found this out the hard way! That's why I renamed it to
TrestsController.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



simple authentication with roles

2009-04-10 Thread qwanta

After struggling a bit with Auth, especially in terms of doing "role"
or "group" authentication, I thought I would post what I found out.

Basically each user belongs to a group ("admin", "calibration",
etc...) and I wanted to set the authorized controller functions for
each group in each individual controller.

I'll assume you have successfully built a user table & model with
username/password at this point. ( see 
http://book.cakephp.org/view/172/Authentication
).

Next add the beforeFilter function to the app controller:


Auth->loginRedirect = array('controller'=>'pages',
'action'=>'display', 'home');
$this->Auth->logoutRedirect = array('controller'=>'pages',
'action'=>'display', 'home');
$this->Auth->allow('display');
$this->Auth->authorize = 'controller';

// store info for access in other controllers
$auth_id =  $this->Auth->user('id');
$this->set('logged_in', $auth_id);
if ($auth_id) {
$this->auth_role = $this->User->getRole( $auth_id );

// do this so we can use these in default.ctp
$this->set('auth_username', 
$this->Auth->user('username'));
$this->set('auth_role', $this->auth_role );
}
}
}
?>

What I have done is add a field called "role" to the user table. In my
user model, I defined a function called getRole to retrieve the role
based on a user id. Again getRole does not exist by default, you have
to make it. I declared $auth_role as a controller property so that it
can be accessed in all child controllers through $this->auth_role. We
will need this for when we add the logic to control access based on
the user role.

the set statements are used so that I can display the current user and
his role in the default.ctp layout, at the top of the page. At this
point we have only given access to non-logged on users to "display"
pages (such as home.ctp), all controller functinos will be blocked
off. Logged on users will have access to everything.

For more control over which roles have access to what, do something
like this in each controller:


auth_role == "admin" ) {
if ( $this->action == "f1" ) { return true; }
if ( $this->action == "f2" ) { return true; }
}
if ($this->auth_role == "calibration" ) {
if ( $this->action == "f1" ) { return false; }
if ( $this->action == "f2" ) { return true; }
}
return false;
}

function f1() {


}

function f2() {


}

}
?>


Basically, add an entry for each controller method under each role in
the isAuthorized method. Return true for access, false for no access.
$this->action maps out to the method that's being called in the
controller.

In the example above, any users in the admin role/group will have
access to f1 & f2, whereas the calibration role/group will only have
access to f2.
--~--~-~--~~~---~--~~
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: pass variable from beforeFilter in app_controller to child controller

2009-04-10 Thread qwanta

OK, nevermind. Sure enough the second I post, I come up with a
solution (after struggling all morning on the problem).

class AppController extends Controller {
 var $auth_role;
}

then refer to it as $this->auth_role in all controllers.

On Apr 10, 11:16 am, qwanta  wrote:
> I am setting a variable value that in app_controller beforeFilter, and
> I would like to access it in all child controllers beforeFilter
> function.
>
> class AppController extends Controller {
>   var $components = array('Auth');
>   var $uses = array('User');
>
>   $auth_id =  $this->Auth->user('id');
>   if ( $auth_id ) {
>     $auth_role = $this->User->getRole($auth_id);
>   }
>
> }
>
> class XController extends AppController {
>   (...)
>   function beforeFIlter() {
>     parent::beforeFilter();
>     if ($auth_role == "calibrator") {
>        (...)
>     }
>   }
>
> }
>
> When I call a method in XController. I get an $auth_role not defined
> error. Is there a way to pass the variable value to the child
> controller?
> 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
-~--~~~~--~~--~--~---



pass variable from beforeFilter in app_controller to child controller

2009-04-10 Thread qwanta

I am setting a variable value that in app_controller beforeFilter, and
I would like to access it in all child controllers beforeFilter
function.

class AppController extends Controller {
  var $components = array('Auth');
  var $uses = array('User');

  $auth_id =  $this->Auth->user('id');
  if ( $auth_id ) {
$auth_role = $this->User->getRole($auth_id);
  }
}

class XController extends AppController {
  (...)
  function beforeFIlter() {
parent::beforeFilter();
if ($auth_role == "calibrator") {
   (...)
}
  }
}

When I call a method in XController. I get an $auth_role not defined
error. Is there a way to pass the variable value to the child
controller?
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: Accessing Model From another Controller

2009-04-02 Thread qwanta

I thought the preferred way was to add the models at the top of the
controller:

var $uses = array('Product', 'Category');

But investigating briefly, it seems like there is a performance hit
for this nice syntax - I found the following post at nabble:

>Don't use $uses, ever. It is terrible for performance.
>
>Always access models through their associations, ie. $this->model1- 
>>model2->find();
>
>If you don't have any associations to the model you want, use the
>following before accessing your model:
>
>App::import('Model', 'Product');
>$tmpProduct = new Product();
>$tmpProduct->find();

--~--~-~--~~~---~--~~
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: Access a returned AJAX value

2008-12-02 Thread qwanta

Hi tobi_one,

I had the exact same problem and never got an answer:
http://groups.google.com/group/cake-php/browse_thread/thread/6a8bca31cbc37600/68463ae52185dd1a
http://groups.google.com/group/cake-php/browse_thread/thread/e96a87bb82267767

In the end, I abandoned the CakePHP ajax helper and did it in straight
javascript. It was much easier than I thought, and I learnt something
about the inner workings of ajax. I think you'll find it's quite
easier this way. IMO it's one of thoswe situations where the
simplified "helper" gets in the way, and the best is to get to the
nuts and bolts. I used the example from the book http://ajaxphp.packtpub.com/
and the free sample chapter that will give you a template to work from
for the ajax call http://ajaxphp.packtpub.com/1825_01_Final.pdf

Good luck

On Dec 2, 3:40 am, tobi_one <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have the following situation:
> A view where I call an AJAX helper with following options:
>
>  'url' => array('controller' => 'users', 'action'=>'login'),
> 'before' => 'startLoadingLogin()',
> 'complete' => 'endLoadingLogin()',
> 'failure' => 'alert(\'Error\')'
> );
> ?>
>
> Once the AJAX call is completet the JS function endLoadingLogin() is
> called. In this function I want to access a return value that I wrote
> in the controller like this:
>
> echo "1";
> $this->render(null,'ajax');
>
> How can I access the return value of this AJAX call in my
> endLoadingLogin() function?
>
> I have tried accessing things like:
>
> var response = t.responseXML.documentElement;
> var response = oXmlHttp.responseText;
>
> in endLoadingLogin() but they don't seem to work and I don't see how
> they should work anyway, because there is no connection between the
> response variable and the AJAX call...
>
> Any ideas are highly appreciated!
>
> cheers,
> tobi_one
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: TCPDF and Cake PHP

2008-12-01 Thread qwanta

I couldn't get that tutorial to work either. It was a while ago, so I
don't remember so well, but here are the notes I took to get something
to work:

***
1) Download the TCPDF files from TCPDF.org (php5 is OK)

2) Extract to app/vendors/tcpdf (to not get dir in dir, extract to app/
vendors)

3) Create a new layout called pdf.ctp
=

=

4) Do a function like this in the controller:
=
function viewPdf($id = null)
{
Configure::write('debug',0); // Otherwise we cannot use this
method while developing

$this->layout = 'pdf'; //this will use the pdf.ctp layout
$this->render();
}
=

5) Create a view view_pdf.ctp:
=
Output("example_001.pdf", "I");

running the view should now launch the pdf save or open dialog
***

This did work for me, so perhaps it can help you. You're probably best
off starting from scratch, but some things I see in your code:

- I think you need to uncomment Configure::write('debug',0);
- change
echo $tcpdf->Output('filename.pdf', 'D');
to
$tcpdf->Output('filename.pdf', 'D');
- use TCPDF object and vendor, not XTCPDF which doesn't work.

But again, follow my step by step to get a working skeleton you can
build upon.

Good luck!

On Dec 1, 6:34 am, Fernando Mendonça <[EMAIL PROTECTED]> wrote:
> Hi everybody,
>
> I'm trying to generate some pdfs files with Cake PHP and TCPDF with
> Bakery Tutorial of this 
> address:http://bakery.cakephp.org/articles/view/creating-pdf-files-with-cakep...
>
> I did everything like this tutorial and I wrote in one of my
> controller (teacher_controller.php) the follow code:
>
>         function __view($id = null) {
>                 if (!$id) {
>                         $this->Session->setFlash(__('Invalid Teacher.', 
> true));
>                         $this->redirect(array('action'=>'index'));
>                 }
>
>                 $this->set('teacher', $this->Teacher->read(null, $id));
>
>         }
>
>         function viewPdf($id = null)
>     {
>         if (!$id)
>         {
>             $this->Session->setFlash('Sorry, there was no property ID
> submitted.');
>             $this->redirect(array('action'=>'index'), null, true);
>         }
>         //Configure::write('debug',0); // Otherwise we cannot use this
> method while developing
>
>         $id = intval($id);
>
>         $property = $this->__view($id); // here the data is pulled
> from the database and set for the view
>
>         if (empty($property))
>         {
>             $this->Session->setFlash('Sorry, there is no property with
> the submitted ID.');
>             $this->redirect(array('action'=>'index'), null, true);
>         }
>
>         $this->layout = 'pdf'; //this will use the pdf.ctp layout
>         $this->render();
>     }
>
> I created the view (viewPdf.ctp) too:
>
>  App::import('Vendor','xtcpdf');
> $tcpdf = new XTCPDF();
> $textfont = 'freesans'; // looks better, finer, and more condensed
> than 'dejavusans'
>
> $tcpdf->SetAuthor("KBS Homes & Properties athttp://kbs-properties.com";);
> $tcpdf->SetAutoPageBreak( false );
> $tcpdf->setHeaderFont(array($textfont,'',40));
> $tcpdf->xheadercolor = array(150,0,0);
> $tcpdf->xheadertext = 'KBS Homes & Properties';
> $tcpdf->xfootertext = 'Copyright © %d KBS Homes & Properties. All
> rights reserved.';
>
> // Now you position and print your page content
> // example:
> $tcpdf->SetTextColor(0, 0, 0);
> $tcpdf->SetFont($textfont,'B',20);
> $tcpdf->Cell(0,14, "Hello World", 0,1,'L');
> // ...
> // etc.
> // see the TCPDF examples
>
> echo $tcpdf->Output('filename.pdf', 'D');
>
> ?>
>
> But when I try to acess: 127.0.0.1/cake/myapp/teacher/1 the message
> "Sorry, there is no property with the submitted ID." appears. I know
> this message has to appears when nothing is set to $property, but I
> thing I'm doing this.
>
> Anybody Can help me?
>
> Thanksuse
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Use Ajax without using library: like prototype.js, jquery.js

2008-10-17 Thread qwanta

For a pure javascript/ajax template, go here http://ajaxphp.packtpub.com/
and download the sample chapter http://ajaxphp.packtpub.com/1825_01_Final.pdf

This should give you a basic working xmlhttprequest that should be
easy to modify to do what you need.

On Oct 17, 11:57 am, bookme <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am using jquery for ajax  in my application.. and was getting very
> good results using it.
>
> But when I was working on a registration page then this jquery is not
> providing me seamless effect.
>
> There is two select box - drop down
> 1 State
> 2 City
> when ever a user select a state correspondingly city comes in city
> drop down. jquery - ajax  is working fine but it's taking time to
> displaying results.
>
> So I have to use simple ajax approach
>
> 1 Create a HTTP object : httpObject
>
> 2  open http connection
>
> httpObject.open("GET", url,  true);
> httpObject.send(null);
> httpObject.onreadystatechange = setOutput;
>
> 3 getting response on httpObject.readyState == 4
>
> till now working fine but in next line creating problem
>
>  top = httpObject.responseXML.getElementsByTagName("cities")[0];
>
> JavaScript Error : httpObject.responseXML has no properties ??
>
> I tested it using httpObject.responseText it's working fine.
> Also my controller is generating xml ..xml is showing in view source
> but i think it's not correct because View Genearted Source not showing
> xml instead of it showing HTML
>
> View Source is
>  
> 
> 0100
> 
>
> Is I am going on write track?
>
> How should I generate xml for this ajax request ..I have alraedy added
> Xml, RequestHandler everything but can not solve problem ?
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: simple AJAX

2008-10-14 Thread qwanta

Before looking at the cakephp ajax helper, and the different js
frameworks (prototype, script.aculo.us, jquery etc) I suggest doing a
simple AJAX example in pure PHP/javascript. There's a great tutorial
here:
http://ajaxphp.packtpub.com/1825_01_Final.pdf

which is a chapter from this book http://ajaxphp.packtpub.com/

On Oct 14, 12:56 am, nayan <[EMAIL PROTECTED]> wrote:
> i am very new to cakePHP.i want to implement AJAX in my code so can
> any one suggest me simple tutorial or from where i have to start.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: New to CakePHP

2008-10-13 Thread qwanta

Also, don't forget to restart apache after making the httpd.conf
changes.

On Oct 12, 2:16 pm, imran k <[EMAIL PROTECTED]> wrote:
> Hi everyone! I am Imran k and very new to CakePHP. I have downloaded
> cake_1.2.0.7692-rc3  and installed on XAMPP server but the 'welcome
> screen' appears without any graphics or colors.
>
> I tried editing the httpd.conf file but it didn't made any difference.
> The screen is still with no color, no styles, no layout, and no font
> changes appear—it’s just black text on a white background.
>
> Can anybody please help?
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: how to create table in database from cakephp

2008-10-10 Thread qwanta

You can do this with the query method of the model.

http://book.cakephp.org/view/456/query

It seems like you need to create a dummy table in the database for the
controller so that you can access the method: for the following
example, I had to create the table "qs" to avoid an "Error: Database
table qs for model Q was not found". I didn't need to create a model
file though.

autoRender = false;

 $this->Q->query("CREATE TABLE customer
  (First_Name char(50),
  Last_Name char(50),
  Address char(50) default 'Unknown',
  City char(50) default 'Mumbai',
  Country char(25),
  Birth_Date date)");
}
}
?>

On Oct 10, 4:49 am, "gunung pangrango" <[EMAIL PROTECTED]> wrote:
> Hello everyone??
>
> i'm newbie in cakephp and now i'm develop web application with cakephp and
> mysql...
> in my application user can add table or add field table from user
> interface...such us phpmyadmin user can define table name , field name ,
> field type and more...
>
> and now i want to know how to create that application using cakephp and
> mysql...
>
> thanks for ur help...
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: How to update two divs with $ajax->link ??

2008-10-09 Thread qwanta

I am not an authority on this, but I had a similar problem that I had
to solve.

Basically, it helps to understand that an ajax call gets a simple text
string back from the server. This text string is generated by the
controller function specified in your ajax call. So really what you
want to do is call a function that generates both updateimage.ctp &
updatelink.ctp in the same string (separated with a known divider
character sequence or better, embedded in xml tags
ie.stringherestringhere.) Then with the string returned, you would parse it and
update the 2 divs. The theoretical way to do this in CakePHP would be
to use the callback function "complete" that allows you to run code
after the XMLHttpRequest is complete ( 
http://book.cakephp.org/view/211/Callback-Options
). But in practice I found it didn't work because there was no way
(AFAIK) to obtain the ajax response string in it.

In the end, I abandoned the CakePHP ajax helper and did it in straight
javascript. It was much easier than I thought, and I learnt something
about the inner workings of ajax. I think you'll find you can update
the 2 divs very easily this way. Check the book http://ajaxphp.packtpub.com/
and the free sample chapter that will give you a template to work from
for the ajax call http://ajaxphp.packtpub.com/1825_01_Final.pdf



On Oct 9, 9:43 am, Anna P <[EMAIL PROTECTED]> wrote:
> Hi again!
> I tried this way:
> link('Frame product', '/products/frameimage/'.
> $p['Product']['id'], array('update' => array('p-image','p-link')); ?>
> so as the second argument I gave link.
> But the problem is that I want to update two divs with two different
> things (so I want to call two functions (two links/urls) and two views
> for them). In 'p-image' I have an image thumbnail and in 'p-link' i
> have link to the image of original size.
> In the $ajax->link call I want to call function 'updateimage' in
> Products controller (and in the 'p-image' div I want the views/
> products/updateimage.ctp to display) and call another funcion
> 'updatelink' in Products controller (and in the 'p-link' div I want
> the views/products/updatelink.ctp to display).
> How to do that?
>
> I tried to set the link as a variable in the 'updateimage' function
> (by $this->set('updated_link',$updated_link)), and then in 'p-link'
> to dipslay $updated_link (with 'p-image' and 'p-link' update) but it
> doesn't work.
> please, help:)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Conventions regarding "people" and "Person"

2008-10-05 Thread qwanta

Note that you can use the $useTable property in the model to
explicitly define what table to use in case of doubt/ambiguity.

http://manual.cakephp.org/view/436/useTable

On Oct 5, 11:47 am, Sentinel <[EMAIL PROTECTED]> wrote:
> Hello everybody.
>
> I have a question regarding the convention within the CakePHP manual.
> At point 2.4.4 in the Manual for version 1.2.x it says that when you
> create a Model class called "Person", the corresponding table in the
> database is/should be "people".
>
> Now, it does state earlier in the manual that the database table name
> has to be the plural of the model class...but does CakePHP really work
> this way? Should it not be "persons"?
>
> I am not speaking from a "What is correct in the English dictionary?"
> type of way, rather from a programming view. Did CakePHP take all the
> plurals available in the dictionary and made sure to recognize:
> man -> men
> mouse -> mice
> person -> people
> and every other plural form that does not abide by the rules?
>
> Anyhow, awaiting an answer about this.
>
> Cheers.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Notice (8): Undefined index: abc [APP\views\......\index.ctp

2008-10-04 Thread qwanta

CREATE TABLE `authors` {
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
other fields...

CREATE TABLE `books` {
`id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`author_id` int(11) NOT NULL,
other fields...

http://jbenner.net/blog/understanding-cakephp-associations


On Oct 4, 4:48 am, "S/*\\L/*\\L/*\\M" <[EMAIL PROTECTED]> wrote:
> qwanta yes the relationship is that u mentioned.i had did these all
> things as u mention, but the error r stuck there and couldnt remove so
> 4..this error is not from table syntax nor from cake php..but as i
> think i didnt define foreign key properly.
> ->if i want to define a foreign key for {author_id} so what will be
> the syntax for this..tables r authors and books.
> thnx for ur time and help.
>
> On Oct 4, 12:56 am, qwanta <[EMAIL PROTECTED]> wrote:
>
> > Note also you have to have your tables defined according to the
> > CakePHP syntax. Each one should have an "id" key column. Then the Book
> > table should have an author_id field to link the author.
>
> > On Oct 3, 2:54 pm, qwanta <[EMAIL PROTECTED]> wrote:
>
> > > If it's a one to many relationship (author has many books, each book
> > > has one author):
>
> > > In Book Model you stick this:
> > > var $belongsTo = array ('Author');
>
> > > In Author Model:
> > > var $hasMany = array ('Book');
>
> > >http://book.cakephp.org/view/78/Associations-Linking-Models-Together
>
> > > I'd recommend going through these tutorials:
>
> > >http://www.sitepoint.com/article/application-development-cakephp/http...
>
> > > On Oct 3, 1:36 pm, "Abdus Salaam" <[EMAIL PROTECTED]> wrote:
>
> > > > thanx for ur time.
> > > > - ya u r rite that htmlhelper is easy way to genrate tables cell and
> > > > headers..
> > > > but i m trying to learn some code myself.. :p
> > > > - i m trying to made relationship b/w books and authors tables...i 
> > > > think its
> > > > relation is not make properly.
> > > > -how to make foreign key?..i think thats the problem.
> > > > thanx
>
> > > > On Fri, Oct 3, 2008 at 11:13 PM, qwanta <[EMAIL PROTECTED]> wrote:
>
> > > > > What you probably want to do is take a look at what you have in the
> > > > > $books array at the end of your controller. A quick and dirty way is
> > > > > to put a var_dump($books); as last statement in your controller
> > > > > function. The contents will then show up at the top of your view.
> > > > > Check if the ['Author']['name'] data is there.
> > > > > Does it work without recursive=1? (My guess is the problem is to do
> > > > > with the Author table and your model definition)
>
> > > > > FYI, the htmlhelper::tableCells & tableHeaders functions are nice for
> > > > > generating tables. :)
>
> > > > > I believe also that the preferred way in cakephp 1.2 to optimize
> > > > > database calls is to use containable behavior. ie.
> > > > > replace
> > > > > $this->Book->recursive = 1;
> > > > > with
> > > > > $this->Book->contain('Author');
>
> > > > >http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/
>
> > > > > But try getting it to work first without optimization.
>
> > > > > On Oct 3, 1:14 am, "S/*\\L/*\\L/*\\M" <[EMAIL PROTECTED]> wrote:
> > > > > > hi all,
> > > > > > i m very new in cakePHP, pls help me some one about this error, 
> > > > > > which
> > > > > > is headeach for me.
> > > > > > => i m getting error of [Undefined index] in  abc view file.i m
> > > > > > pasting code here if some 1 got it then pls help me.
> > > > > > thanx
>
> > > > > > =>this controller file code for index...
> > > > > > function index() {
> > > > > > $this->Book->recursive = 1;
> > > > > > $books = $this->Book->find('all');
> > > > > > $this->set('books', $books);
>
> > > > > > }
>
> > > > > > =>and this one code for index.ctp
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > i am waiting :)
>
> > > > --
> > > > Best Regards
> > > > ABDUS SALAAM
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Notice (8): Undefined index: abc [APP\views\......\index.ctp

2008-10-03 Thread qwanta

If it's a one to many relationship (author has many books, each book
has one author):

In Book Model you stick this:
var $belongsTo = array ('Author');

In Author Model:
var $hasMany = array ('Book');

http://book.cakephp.org/view/78/Associations-Linking-Models-Together

I'd recommend going through these tutorials:

http://www.sitepoint.com/article/application-development-cakephp/
http://www.davidgoldingdesign.com/newbie-cakephp.pdf


On Oct 3, 1:36 pm, "Abdus Salaam" <[EMAIL PROTECTED]> wrote:
> thanx for ur time.
> - ya u r rite that htmlhelper is easy way to genrate tables cell and
> headers..
> but i m trying to learn some code myself.. :p
> - i m trying to made relationship b/w books and authors tables...i think its
> relation is not make properly.
> -how to make foreign key?..i think thats the problem.
> thanx
>
>
>
> On Fri, Oct 3, 2008 at 11:13 PM, qwanta <[EMAIL PROTECTED]> wrote:
>
> > What you probably want to do is take a look at what you have in the
> > $books array at the end of your controller. A quick and dirty way is
> > to put a var_dump($books); as last statement in your controller
> > function. The contents will then show up at the top of your view.
> > Check if the ['Author']['name'] data is there.
> > Does it work without recursive=1? (My guess is the problem is to do
> > with the Author table and your model definition)
>
> > FYI, the htmlhelper::tableCells & tableHeaders functions are nice for
> > generating tables. :)
>
> > I believe also that the preferred way in cakephp 1.2 to optimize
> > database calls is to use containable behavior. ie.
> > replace
> > $this->Book->recursive = 1;
> > with
> > $this->Book->contain('Author');
>
> >http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/
>
> > But try getting it to work first without optimization.
>
> > On Oct 3, 1:14 am, "S/*\\L/*\\L/*\\M" <[EMAIL PROTECTED]> wrote:
> > > hi all,
> > > i m very new in cakePHP, pls help me some one about this error, which
> > > is headeach for me.
> > > => i m getting error of [Undefined index] in  abc view file.i m
> > > pasting code here if some 1 got it then pls help me.
> > > thanx
>
> > > =>this controller file code for index...
> > > function index() {
> > > $this->Book->recursive = 1;
> > > $books = $this->Book->find('all');
> > > $this->set('books', $books);
>
> > > }
>
> > > =>and this one code for index.ctp
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > i am waiting :)
>
> --
> Best Regards
> ABDUS SALAAM
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Notice (8): Undefined index: abc [APP\views\......\index.ctp

2008-10-03 Thread qwanta

Note also you have to have your tables defined according to the
CakePHP syntax. Each one should have an "id" key column. Then the Book
table should have an author_id field to link the author.

On Oct 3, 2:54 pm, qwanta <[EMAIL PROTECTED]> wrote:
> If it's a one to many relationship (author has many books, each book
> has one author):
>
> In Book Model you stick this:
> var $belongsTo = array ('Author');
>
> In Author Model:
> var $hasMany = array ('Book');
>
> http://book.cakephp.org/view/78/Associations-Linking-Models-Together
>
> I'd recommend going through these tutorials:
>
> http://www.sitepoint.com/article/application-development-cakephp/http://www.davidgoldingdesign.com/newbie-cakephp.pdf
>
> On Oct 3, 1:36 pm, "Abdus Salaam" <[EMAIL PROTECTED]> wrote:
>
> > thanx for ur time.
> > - ya u r rite that htmlhelper is easy way to genrate tables cell and
> > headers..
> > but i m trying to learn some code myself.. :p
> > - i m trying to made relationship b/w books and authors tables...i think its
> > relation is not make properly.
> > -how to make foreign key?..i think thats the problem.
> > thanx
>
> > On Fri, Oct 3, 2008 at 11:13 PM, qwanta <[EMAIL PROTECTED]> wrote:
>
> > > What you probably want to do is take a look at what you have in the
> > > $books array at the end of your controller. A quick and dirty way is
> > > to put a var_dump($books); as last statement in your controller
> > > function. The contents will then show up at the top of your view.
> > > Check if the ['Author']['name'] data is there.
> > > Does it work without recursive=1? (My guess is the problem is to do
> > > with the Author table and your model definition)
>
> > > FYI, the htmlhelper::tableCells & tableHeaders functions are nice for
> > > generating tables. :)
>
> > > I believe also that the preferred way in cakephp 1.2 to optimize
> > > database calls is to use containable behavior. ie.
> > > replace
> > > $this->Book->recursive = 1;
> > > with
> > > $this->Book->contain('Author');
>
> > >http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/
>
> > > But try getting it to work first without optimization.
>
> > > On Oct 3, 1:14 am, "S/*\\L/*\\L/*\\M" <[EMAIL PROTECTED]> wrote:
> > > > hi all,
> > > > i m very new in cakePHP, pls help me some one about this error, which
> > > > is headeach for me.
> > > > => i m getting error of [Undefined index] in  abc view file.i m
> > > > pasting code here if some 1 got it then pls help me.
> > > > thanx
>
> > > > =>this controller file code for index...
> > > > function index() {
> > > > $this->Book->recursive = 1;
> > > > $books = $this->Book->find('all');
> > > > $this->set('books', $books);
>
> > > > }
>
> > > > =>and this one code for index.ctp
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > 
> > > > i am waiting :)
>
> > --
> > Best Regards
> > ABDUS SALAAM
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Notice (8): Undefined index: abc [APP\views\......\index.ctp

2008-10-03 Thread qwanta

What you probably want to do is take a look at what you have in the
$books array at the end of your controller. A quick and dirty way is
to put a var_dump($books); as last statement in your controller
function. The contents will then show up at the top of your view.
Check if the ['Author']['name'] data is there.
Does it work without recursive=1? (My guess is the problem is to do
with the Author table and your model definition)

FYI, the htmlhelper::tableCells & tableHeaders functions are nice for
generating tables. :)

I believe also that the preferred way in cakephp 1.2 to optimize
database calls is to use containable behavior. ie.
replace
$this->Book->recursive = 1;
with
$this->Book->contain('Author');

http://cakebaker.42dh.com/2008/05/18/new-core-behavior-containable/

But try getting it to work first without optimization.

On Oct 3, 1:14 am, "S/*\\L/*\\L/*\\M" <[EMAIL PROTECTED]> wrote:
> hi all,
> i m very new in cakePHP, pls help me some one about this error, which
> is headeach for me.
> => i m getting error of [Undefined index] in  abc view file.i m
> pasting code here if some 1 got it then pls help me.
> thanx
>
> =>this controller file code for index...
> function index() {
> $this->Book->recursive = 1;
> $books = $this->Book->find('all');
> $this->set('books', $books);
>
> }
>
> =>and this one code for index.ctp
> 
> 
> 
> 
> 
> 
> 
> i am waiting :)
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



AJAX callback function "complete" - how do I access the XMLHttpRequest response text?

2008-10-02 Thread qwanta

In traditional javascript you can get the text of the message of an
XMLHttpRequest by doing something like this:

xmlResponse = xmlHttp.responseXML; // xml
textResponse = xmlHttp.responseText; // text

where xmlHttp is an XMLHttpRequest Object that has received a message
from the server.


How do I access this message text in the CakePHP "complete" callback
function of an ajax link?

eg:
in my view:
=
echo $ajax->link('link1',
array('controller'=>'tests' ,
'action'=>'simple_ajax1_fcn'),
array('complete'=>'my_js_callback()')
);
=
in my controller:
=
class TestsController extends AppController
{
var $name = 'Tests';
var $uses = array();

function simple_ajax1_fcn() {
$this->autoRender = false;
echo "secret message 14562642";
}
}
=
How do I get "secret message 14562642" in my_js_callback()?

I've tried various constructs like:
request.responseText
response.responseText
Ajax.response.responseText
Ajax.responseText
XMLHttpRequest.responseText

but none seem to work.
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: AJAX: is it possible to update the src parameter of an image directly?

2008-10-02 Thread qwanta

I've been playing around trying to find it with something like this in
my js function.

try {
alert(request.responseText);
}
catch(err) {
alert   (err.toString());
}

but both the request and response objects are undefined (don't exist).

By trial and error I found there's an "Ajax" object and an
"XMLHttpRequest" object defined in the scope, but I can't get any
responseText out of them. I think the answer lies in the prototype
library, as that's where these callback functions are defined, but I
can't quite figure it out from perusing the docs. Anyway, thanks, I'll
post back if I figure it out! (I think I'll post another topic with
this specific question in it)

On Oct 2, 9:12 pm, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote:
> Sorry, try request.responseText.
> And put it in the Book if it worked. :-)
>
> On 3 Oct 2008, at 02:44, qwanta wrote:
>
>
>
> > On Oct 1, 11:59 pm, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote:
> >> 'callback' doesn't exist, the only names of callbacks you can use are
> >> listed on the page in my last message. :-)
> > Oooops, it was getting late
>
> >> Other than that, you pretty much got it. I always forget what the
> >> variable name is called, but I think in your callback function you'll
> >> have access to whatever the controller returns in the variable
> >> 'response.responseText'.
>
> > Well, I'm halfway there. I can set the image src from the javascript,
> > but I can't seem to figure out how to get access to the text returned
> > from the controller - "response.responseText" doesn't seem to be it.
> > Is it documented anywhere? I'm drawing a blank with google.
> > In my original non-cakephp javascript, I was getting the text response
> > from the XMLHttpRequest object (ie. xmlHttp.responseXML; ). This
> > object doesn't seem available in the callback either (unless it's
> > called something else).
>
> > mikeg - thanks for the tip, but I think it's close to working with the
> > "official" cakephp prototype solution. I don't want to delve into
> > jquery if I don't have to.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: AJAX: is it possible to update the src parameter of an image directly?

2008-10-02 Thread qwanta



On Oct 1, 11:59 pm, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote:
> 'callback' doesn't exist, the only names of callbacks you can use are
> listed on the page in my last message. :-)
Oooops, it was getting late

> Other than that, you pretty much got it. I always forget what the
> variable name is called, but I think in your callback function you'll
> have access to whatever the controller returns in the variable
> 'response.responseText'.
>
Well, I'm halfway there. I can set the image src from the javascript,
but I can't seem to figure out how to get access to the text returned
from the controller - "response.responseText" doesn't seem to be it.
Is it documented anywhere? I'm drawing a blank with google.
In my original non-cakephp javascript, I was getting the text response
from the XMLHttpRequest object (ie. xmlHttp.responseXML; ). This
object doesn't seem available in the callback either (unless it's
called something else).

mikeg - thanks for the tip, but I think it's close to working with the
"official" cakephp prototype solution. I don't want to delve into
jquery if I don't have to.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: AJAX: is it possible to update the src parameter of an image directly?

2008-10-01 Thread qwanta

OK, thanks. That's exactly what I am looking for. I already have the
javascript I need from my php/javascript code. If I understand this
correctly, I just have to send the generated image name back using
echo statements in the controller (maybe wrapping it in xml format),
then trigger my 3 js statements to read the name and update the src
parameter with it.

I'll be investigating this in more detail, but one quick thing I have
run into right away:
I added some alert statements to my ajax link:
===
array('callback'=>'alert("callback")',
'complete' => 'alert( "Executed OK" )',
'loading'=> 'alert("Loading")',
'loaded'=> 'alert("Loaded")')
===
Loading, loaded & complete all fire the alert window OK. But I don't
get the callback one. Is there anything special to be set up? Thanks.


On Oct 1, 10:23 pm, "David C. Zentgraf" <[EMAIL PROTECTED]> wrote:
> I guess the AJAX helper doesn't have this ability built-in, but you
> could simply write your own JS for the 'complete' 
> callback.http://book.cakephp.org/view/211/Callback-Options
>
> On 2 Oct 2008, at 12:12, qwanta wrote:
>
>
>
> > Using pure php/javascript without cakephp, I am able to use the
> > javascript function
> > ===
> > document.getElementById("pic").src = imageName;
> > ===
> > to update an image (when a button on the web page is clicked). this
> > results in very smooth image updates.
>
> > In CakePHP, I have been able to update the image from an ajax link by
> > updating the  containing the image. ie. by generating the full
> >  tag in the controller to replace the text in the .
> > Something like this:
> > ===
> > echo "";
> > ===
>
> > Both methods work OK, but the cakephp  update results in a
> > flicker as the div size briefly goes to zero, before it displays the
> > image (anything below the image moves up briefly to cover the area
> > where the image was, then moves back down again when the image is
> > loaded and displayed). I would like to get the smooth image updates of
> > the javascript function in CakePHP by directly injecting the new image
> > name into the src parameter of the  tag. Is this possible?
>
> > Just to give some more background, I am using jpgraph to generate line
> > plots based on changing data, with time on the x-axis. Each new graph
> > is an image with a randomly generated filename that I pass back to the
> > client.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



AJAX: is it possible to update the src parameter of an image directly?

2008-10-01 Thread qwanta

Using pure php/javascript without cakephp, I am able to use the
javascript function
===
document.getElementById("pic").src = imageName;
===
to update an image (when a button on the web page is clicked). this
results in very smooth image updates.

In CakePHP, I have been able to update the image from an ajax link by
updating the  containing the image. ie. by generating the full
 tag in the controller to replace the text in the .
Something like this:
===
echo "";
===

Both methods work OK, but the cakephp  update results in a
flicker as the div size briefly goes to zero, before it displays the
image (anything below the image moves up briefly to cover the area
where the image was, then moves back down again when the image is
loaded and displayed). I would like to get the smooth image updates of
the javascript function in CakePHP by directly injecting the new image
name into the src parameter of the  tag. Is this possible?


Just to give some more background, I am using jpgraph to generate line
plots based on changing data, with time on the x-axis. Each new graph
is an image with a randomly generated filename that I pass back to the
client.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: help me understand cakaphp

2008-10-01 Thread qwanta

There's also a couple good tutorials:

http://www.sitepoint.com/article/application-development-cakephp/
http://www.davidgoldingdesign.com/newbie-cakephp.pdf

But they are from 2006, so a little outdated (use .thtml instead
of .ctp extension). Still worth reading for the concepts, and the code
still works fine.

But really I would recommend one (or both) of the CakePHP books. I
thought the Packt publishing one was pretty good.

www.packtpub.com/cakephp-application-development/book

On Sep 30, 8:16 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
>  I m totally new to cakephp and i need to develope my project using
> cakephp framework .Previously all projects was done using simple php
> coding no framework nothing was used.Can any body tell me how do i
> start my application using cakephp. Before this i used devlope coding
> in php  .I have read the begining mannual but not understood how to
> start.So plz tell me from the beging steps.If posiible plz give any
> example of theapplication where cakephp was used.
>  not exactally where i have use code and put and how run on
> localserver
>
> Will be very thankfull if somebosy helps me in
> this 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Simple Ajax link to update div

2008-09-30 Thread qwanta
PLICIT call is made to then render the
view. If spelled out it would look like this: $this-
>render('simple_ajax1','default'); ('default' is the layout). We can
prevent this rendering from happening by placing the line $this-
>autoRender = false; in the controller function as I have done above.
Also, note that the render function is simply generating text and
returning it to the browser via http. Any text output with "echo" in
the controller function will also be sent back to the browser when it
browses to the function. To illustrate this, add this function to the
TestsController:

function simple_text() {
$this->autoRender = false;
echo "aaa";
echo "bbb";
echo "ccc";
}

Now navigate to http://127.0.0.1/[cakephpapp]/tests/simple_text

You should see the text in the browser.
aaa
bbb
ccc

And because we set autoRender to false, the controller doesn't even go
looking for simple_text.ctp .

For the ajax function, it's the same thing except that the text
(whether generated with echo or with a ctp template) is injected into
the div we set up in the ajax link as the update parameter
(array('update' => 'divout')).

Anyway, this is probably very basic stuff for most CakePHP developers,
but I just wanted to get it out there in case it can help someone
struggling with the ajax docs as I was.

On Sep 30, 10:33 am, qwanta <[EMAIL PROTECTED]> wrote:
> Thanks for the reply.
>
> I placed an fwrite statement in ajaxfcn1() and it is writing to file.
> So I'm getting as far as triggering ajaxfcn1 now. But the div isn't
> updating.
> I guess what I am having trouble understanding is how CakePHP
> generates a response to the asynchronous call. With the standard
> javascript XMLhttprequest object, the server-side php usually
> generates an xml response containing the desired data to be is sent
> back to the client.
>
> eg. something like this:
> ===
>  $data = "this is a test";
>
> // we'll generate XML output
> header('Content-Type: text/xml');
> // generate XML header
> echo '';
> // create the  element
> echo '';
> //
> echo $data;
> // close the  element
> echo '';
> ?>
> =
>
> then you can use $data on the client side javascript, for example
> placing it in a  element.
>
> I understand that this is abstracted out in CakePHP, but I am having a
> hard time understanding the process conceptually. In CakePHP how is
> this xml data generated? (how do I place data in the response to be
> passed back to the client)? And how do I update divs with it? (without
> having access to js functions like
> document.getElementById("divout").innerHTML). thanks
>
> On Sep 30, 9:07 am, Donkeybob <[EMAIL PROTECTED]> wrote:
>
> > it looks like your syntax is wrong for the ajax link . . .no
> > parenthesis around '$ajax->link' code either . . .check 
> > outhttp://book.cakephp.org/view/212/Methodsforproper syntax.
>
> > from the manual related to your code
> > link('View Post',
> > array( 'controller' => 'tests', 'action' => 'ajaxfcn1', 1 ),
> > array( 'update' => 'divout', 'complete' => 'alert( "Executed
> > OK" )' )
> >  );
> > ?>
>
> > in your controller function:
>
> > echo "Controller Executed";
>
> > as long as protoptype is linked up, then that should work.
>
> > On Sep 29, 11:56 pm, qwanta <[EMAIL PROTECTED]> wrote:
>
> > > Hi,
> > > I have been struggling a bit to get a simple Ajax link working. I have
> > > searched this group for help in older posts, but it seems like a key
> > > tutorial (the grahambird one) is no longer available - perhaps because
> > > it no longer works with 1.2.
>
> > > If there is a tutorial somewhere that covers this, please let me know.
> > > I think I have gone over all the available (through google) CakePHP
> > > ajax tutorials, but unfortunately without success - some are outdated
> > > (pre 1.2), others do not have full working code etc...
>
> > > In any case, here is my code:
> > > 
> > > index.ctp
> > > Ajax 3 - testing ajax link and button
> > >  > > $link_array1 = array('controller'=>'tests' ,
> > >  

Re: Simple Ajax link to update div

2008-09-30 Thread qwanta

Thanks for the reply.

I placed an fwrite statement in ajaxfcn1() and it is writing to file.
So I'm getting as far as triggering ajaxfcn1 now. But the div isn't
updating.
I guess what I am having trouble understanding is how CakePHP
generates a response to the asynchronous call. With the standard
javascript XMLhttprequest object, the server-side php usually
generates an xml response containing the desired data to be is sent
back to the client.

eg. something like this:
===
';
// create the  element
echo '';
//
echo $data;
// close the  element
echo '';
?>
=

then you can use $data on the client side javascript, for example
placing it in a  element.

I understand that this is abstracted out in CakePHP, but I am having a
hard time understanding the process conceptually. In CakePHP how is
this xml data generated? (how do I place data in the response to be
passed back to the client)? And how do I update divs with it? (without
having access to js functions like
document.getElementById("divout").innerHTML). thanks

On Sep 30, 9:07 am, Donkeybob <[EMAIL PROTECTED]> wrote:
> it looks like your syntax is wrong for the ajax link . . .no
> parenthesis around '$ajax->link' code either . . .check 
> outhttp://book.cakephp.org/view/212/Methodsfor proper syntax.
>
> from the manual related to your code
> link('View Post',
> array( 'controller' => 'tests', 'action' => 'ajaxfcn1', 1 ),
> array( 'update' => 'divout', 'complete' => 'alert( "Executed
> OK" )' )
>  );
> ?>
>
> in your controller function:
>
> echo "Controller Executed";
>
> as long as protoptype is linked up, then that should work.
>
> On Sep 29, 11:56 pm, qwanta <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > I have been struggling a bit to get a simple Ajax link working. I have
> > searched this group for help in older posts, but it seems like a key
> > tutorial (the grahambird one) is no longer available - perhaps because
> > it no longer works with 1.2.
>
> > If there is a tutorial somewhere that covers this, please let me know.
> > I think I have gone over all the available (through google) CakePHP
> > ajax tutorials, but unfortunately without success - some are outdated
> > (pre 1.2), others do not have full working code etc...
>
> > In any case, here is my code:
> > 
> > index.ctp
> > Ajax 3 - testing ajax link and button
> >  > $link_array1 = array('controller'=>'tests' ,
> > 
> > 'action'=>'ajaxfcn1');   // the function to execute: function
> > ajaxfcn1 in controller tests
>
> > $link_array2 = array( 'update' => 'divout',
> > 'complete' 
> > => 'alert( "Executed OK" )' );  // the div we want
> > to update
>
> > echo ($ajax->link('this an ajax link', $link_array1,
> > $link_array2,'Confirmation String'));
>
> > echo "";
>
> > echo ($ajax->submit('this is an ajax button', $link_array1,
> > $link_array2,'Confirmation String'));
> > ?>
> > 
> > 
> > the div to update
> > 
> > 
> > tests_controller.php
> >  > class TestsController extends AppController {
>
> > var $name = 'Tests';
> > var $uses = array();// prevent cake from looking for a 
> > database
> > model
>
> > function index() {
>
> > }
>
> > function ajaxfcn1() {
> > $this->render('index', 'ajax');
> > }}
>
> > ?>
> > 
>
> > So basically I have a view with an ajax link, an ajax button, and a
> > . I would like to change the text in the div when I click the
> > link or button. At this point, nothing happens when I click them. I am
> > not sure if the ajaxfcn1() function is even executing at this point.
> > What's an easy statement to add in ajaxfcn1() to determine if the code
> > is executing? What function would I use to set the new div text from
> > within ajaxfcn1()?
>
> > 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Simple Ajax link to update div

2008-09-30 Thread qwanta

Hi,
I have been struggling a bit to get a simple Ajax link working. I have
searched this group for help in older posts, but it seems like a key
tutorial (the grahambird one) is no longer available - perhaps because
it no longer works with 1.2.

If there is a tutorial somewhere that covers this, please let me know.
I think I have gone over all the available (through google) CakePHP
ajax tutorials, but unfortunately without success - some are outdated
(pre 1.2), others do not have full working code etc...

In any case, here is my code:

index.ctp
Ajax 3 - testing ajax link and button
'tests' ,

'action'=>'ajaxfcn1');  // the function to execute: function
ajaxfcn1 in controller tests

$link_array2 = array( 'update' => 'divout',
'complete' => 
'alert( "Executed OK" )' );   // the div we want
to update

echo ($ajax->link('this an ajax link', $link_array1,
$link_array2,'Confirmation String'));

echo "";

echo ($ajax->submit('this is an ajax button', $link_array1,
$link_array2,'Confirmation String'));
?>


the div to update


tests_controller.php
render('index', 'ajax');
}
}
?>


So basically I have a view with an ajax link, an ajax button, and a
. I would like to change the text in the div when I click the
link or button. At this point, nothing happens when I click them. I am
not sure if the ajaxfcn1() function is even executing at this point.
What's an easy statement to add in ajaxfcn1() to determine if the code
is executing? What function would I use to set the new div text from
within ajaxfcn1()?

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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



bakery not taking comments?

2008-09-03 Thread qwanta

Not sure if this is the best place to report this, but I couldn't find
any contact info for the bakery.

Basically, it seems like comments cannot be left for articles at the
bakery. There is some problem with the title validation as it reports
a blank field even when there is text in there.

I was trying to leave a comment/question for Kalileo's "Creating PDF
files with CakePHP and TCPDF" article.

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---