Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Some Issues: multiple views on one page and help with javascript
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Timo  
View profile  
 More options Apr 17 2012, 4:36 am
From: Timo <timo.responde...@googlemail.com>
Date: Tue, 17 Apr 2012 01:36:25 -0700 (PDT)
Local: Tues, Apr 17 2012 4:36 am
Subject: Some Issues: multiple views on one page and help with javascript

Hello everybody,

since I am fairly new to CakePhp and since my research has not yielded any
definitive results concerning my specific problem so far, I figured the
best thing to do would be to ask here. :)
Bear with me, this is going to be rather elaborate, I fear...

I'm creating an application with CakePhp (2.1) and Javascript / JQuery, one
basic functionality is that table entries can be viewed in different ways,
to which I will come in a moment. My main content area consists of 2 sub
divisions, one is the actual main content, the other is a horizontally
sliding area which can be toggled on and off (in the following text
referred to as "accordion"). I will attach an image at the end of the post
to exemplify what I mean.

The afore mentioned different views ( / edits / adds)  are:

*1. Standard view* would be in accordion which is hidden until a table
entry is chosen, once the view is triggered, the area is supposed to slide
from the right side into the screen and overlap the underlying table, the
area can be toggled on and off. Basically it acts as a horizontal accordion
window, the user is able  to quickly manipulate table entries, hide the
entry to look something up in the table, and show the entry again to
continue whatever he was doing before.
*2. Fullscreen view *is supposed to be rendered in the actual main content
area, in this view the table is transferred to the accordion, basically
table and table entry swap positions.

Another aspect of the application is that table entries can be stored in
"favourites" or "clipboard", those two are small windows which can be shown
on any page of the application and which are also part of the start page.

Now that I have started to try to implement this layout, I have encountered
some problems, which might result from me being a beginner in CakePhp.
After baking controllers and models via the console, I created the index
view for one controller ("companies") and went on to the "add" view for
this controller. Naive as I was I simply put the generated "add" view code
in the accordion div and left the table (index view) code in the main area
div which led to errors. So if I understand this correctly, I cannot simply
fill 2 divs with different view contents from only one query, which makes
sense. My research led me to the "elements" functionality of cake, though I
could only find the cookbook entry for 1.3 (
http://book.cakephp.org/1.3/view/1081/Elements ).
Please tell me whether this will help me with my problem, or if there is a
better, simple solution for what I am trying to do. (I might have to fill
not only the accordion and the main content area with data entries, but
also the "favourites" and "clipboard" area once the user clicks the button
to show those). I also searched for a way to "fetch" multiple content in my
default layout like

echo $this->fetch('content');
echo $this->fetch('accordion');  

but I did not find anything. So this is my first issue. A second one:
When the user clicks on a table entry in the table, an option menu is shown
at the mouse position from which the user can choose to edit, delete or
view the clicked entry. This option menu is also shown when the user clicks
on an entry in the favourites or clipboard area. Is there a way to combine
PHP and Javascript to determine, which kind of data is clicked (e.g. which
controller must be used)?
And furthermore, is  there a way to integrate (cake)php in code in
javascript?

Example:
$('#listEditButton').click(function(){
   window.location.href="companyEdit.html";

});

Instead of window.location.href="companyEdit.html"; the cakephp edit view
for the correct controller should be triggered.

*Breathes deeply* Excuse my excessive question, but I just started with
CakePhp (did research, went through the blog tutorial - which as far as I
can tell does not cover what I need for my application), maybe I even
missed some CakePhp functionalities which provide exactly what I am looking
for.

To sum it up:
*1. Multiple Views on one page: *How does one for example show the index
view AND the view of one entry of a controller on a single page with
CakePhp.
*2. Javascript and CakePhp: *How do you use CakePhp view "calls" in
javascript, is this even possible, how would one approach the above problem
with the option menu (if there is any way apart from separate option menus
for all pages AND for "favourites" and "clipboard").

If you have read all the above - Thank you very much! I would have put this
in caps but that is just hurting for the eyes. I hope someone can help me
and put me on the right way to what I am trying to do :)

Kindest regards

Timo

Attachment:

<https://lh6.googleusercontent.com/--4enSImYE8U/T40rbqL-DFI/AAAAAAAAAA...>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bs28723  
View profile  
 More options Apr 17 2012, 10:42 am
From: bs28723 <bill.sto...@boosterwebsolutions.com>
Date: Tue, 17 Apr 2012 07:42:05 -0700 (PDT)
Local: Tues, Apr 17 2012 10:42 am
Subject: Re: Some Issues: multiple views on one page and help with javascript

I will try to help with the view issue.
First look at the 2.x View Template section
http://book.cakephp.org/2.0/en/views.html
And look into Extending Views.   This will allow you to break up the
view.  You create a frame work for a controller, then the view can have
different content in the main section depending on the function.

I would then look at each of these areas that slide in and out might be
a good fit for an Element. (see same doc page).
You can pass parameters to them to customize them.  I use elements for
addresses.  I have shipping, billing & other address. It formats the
address. I pass a title to element to be displayed by element.

you can use the requestAction function in the Elements to get data from
another controller function. See sample code in same documentation page
under elements.

This way you have a few main functions and views to go with them. Then
you have the elements, that may use other functions in the controller or
possibly other controllers, to get data.  You could do this for a
dashboard, or to fill these  slide outs that you describe.

You may want to consider adding a Helper to get some of this data for
the view, if you think you may want the data on multiple views.  The
helper can make calls via requestAction to this controller, or possibly
other controllers to get some data, that can be formatted by the
elements for the view.

Bill

On 4/17/2012 7:30 AM, Timo [via CakePHP] wrote:

--
View this message in context: http://cakephp.1045679.n5.nabble.com/Some-Issues-multiple-views-on-on...
Sent from the CakePHP mailing list archive at Nabble.com.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Timo  
View profile  
 More options Apr 18 2012, 7:01 am
From: Timo <timo.responde...@googlemail.com>
Date: Wed, 18 Apr 2012 04:01:26 -0700 (PDT)
Local: Wed, Apr 18 2012 7:01 am
Subject: Re: Some Issues: multiple views on one page and help with javascript

Thanks a lot for your answer, it helped me a lot!

I see how elements can be used for what I am trying to do. I tried the
simple example from the link you provided, so now I can populate multiple
ares of one page with different views - that's great!

What I don't quite grasp is the usefulness of adding a helper as you
mentioned in your last paragraph. So basically the helper would get all the
data for my elements instead of me calling requestAction multiple times?

I was told that AJAX can be used to put content into element areas (via
requestAction, too?), e.g. I have my slideout visible which shows a data
entry, then, with my table still visible in the main content area, I choose
edit on a different entry and instead of loading the page anew, the
slideout element loads new content. How would one go about this task? A
simple example would be enough to get me started, since I cannot find any
useful ones, e.g. a button that triggers an element to be filled with a
different view. I am aware of the .load function in JQuery (
http://api.jquery.com/load/ ), but that does not explain how to include
such functionality in a CakePhp environment. Can I simply use something
like 'controllername/add' as url parameter for load?

As I see it, one issue remains despite the element solution (which might
result from my limited Cake knowledge)  - concrete example: The application
has tables for companies, users and posts, each table and corresponding
controller has index / add / view(show the data) / edit views. Index is
displayed in the main area, the other views are supposed to be displayed in
the slideout.
Would I not need many different element specifications depending
a) on the chosen table
b) the chosen option (add / edit / etc) ?

Is there a way to put for example the rendered view of
"View/Company/add.ctp" into an element? Because as far as I understand
requestAction, I can only get the data provided by the controller (which
makes sense due to the MVC pattern) and this data still has to be echoed
and styled. And that is the problem since there is not a common style for
add / edit / view (add and edit would have inputs for data values, view
would use labels). My thought would be to put those options into one
element and control which style is used by a parameter given to the
element, I just want to know if that is viable or if there is another,
better way to do this.

I hope that was somewhat intelligible :)
Many thanks in advance for any helpful advice

Timo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
luca capra  
View profile  
 More options Apr 18 2012, 7:59 am
From: luca capra <luca.ca...@gmail.com>
Date: Wed, 18 Apr 2012 13:59:06 +0200
Local: Wed, Apr 18 2012 7:59 am
Subject: Re: Some Issues: multiple views on one page and help with javascript

Il 18/04/2012 13:01, Timo ha scritto:

I use it in this way:
$("#someelement").load("/controller/action div.index");
loads html content of div.index in #someelement

You can handle it better with $.post / $.get handling the html response
$.get('controller/action', function(html){
   var myHtml = $(html);
   $("#something").replace( myHtml.find("#something").html() );

});

This works faster if you create an empty layout and print only the
$content_for_layout, I use it with a custom extension
eg. controlller/index.dhtml give me only the action response, without
the whole layout code around.

> As I see it, one issue remains despite the element solution (which
> might result from my limited Cake knowledge)  -
> ...
> Is there a way to put for example the rendered view of
> "View/Company/add.ctp" into an element?
> ...

I suggest you to look at the new -cool- templating system (from 2.1 I think)
http://book.cakephp.org/2.0/en/views.html

Luca


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bs28723  
View profile  
 More options Apr 18 2012, 9:42 am
From: bs28723 <bill.sto...@boosterwebsolutions.com>
Date: Wed, 18 Apr 2012 06:42:21 -0700 (PDT)
Local: Wed, Apr 18 2012 9:42 am
Subject: Re: Some Issues: multiple views on one page and help with javascript

I don't know a lot about AJAX - Need to learn :-)
What I am doing with the helper, is that I was finding that I was
repeating code in multiple views or several times in a single view to
get ready to call an element.  So, I just moved this common code from
the view to a helper, then made a single to call to the helper.

In Controller
    public $helpers = array ('Html', 'Form', 'Session',  'Address');

In view
     $title = "Shipping Address";
<? php echo $this->Address->makeAddressElements($organization); ?>

In Helper
    public function makeAddressElements($organization) {
       // some details removed....
         $addresses =
$this->requestAction('addresses/getByOrg/'.$organization['id']);
         foreach ($addresses as $address) {
             $title = "Not Used Address";
             if ($organization['ship_address_id'] ==
$address['Address']['id'])
                 $title = "Shipping Address";
             if ($organization['bill_address_id'] ==
$address['Address']['id'])
                 $title = "Billing Address";
             $html .= $this->_View->element('address', array("addr" =>
$address['Address'], "title" => $title));
        }
        return $html;
   }

     In the Helper in order to call an element that is associated with a
view, you need to use the call  $this->_View->element().   This will
used the attached view to help render the element.  This is not well
documented, but seems to be the way other helpers do this.

You may not need to do this since you are doing Ajax.  You may be able
to load all this stuff in the beginning and have javascript hide and
display the details as needed.

As for the controller function mapping to views, while Cakephp will
defualt create add / index / edit / view functions and views, you are
not required to use them all. If you want to have everything displayed
and managed for the controller thru the view function and the view view,
I don't think this is a problem.  You could then use requestAction, or a
bunch of set commands to pass information to the view.

This is where my Ajax knowledge puts me on thin ice, but I think you can
create Ajax or javascript functions that can call other functions in the
controller, like add or edit, and return information that you updated a
portion of the screen, so that you don't have to render the entire page.

I guess the way I would look at this is that the view is the webpage.  
If you want everything to be processed in a single page, with pop outs,
etc. then you only need one view.  It may be complicated, but if you are
familiar doing this with just PHP and Ajax then it should be fine.   The
controller is where all the business logic is run. So this can be
organized based on how you want to process the data.

Not sure if I am getting to basic here, or if this answers your question
about views.

Bill

On 4/18/2012 7:02 AM, Timo [via CakePHP] wrote:

--
View this message in context: http://cakephp.1045679.n5.nabble.com/Some-Issues-multiple-views-on-on...
Sent from the CakePHP mailing list archive at Nabble.com.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Timo  
View profile  
 More options Apr 23 2012, 1:36 am
From: Timo <timo.responde...@googlemail.com>
Date: Sun, 22 Apr 2012 22:36:24 -0700 (PDT)
Local: Mon, Apr 23 2012 1:36 am
Subject: Re: Some Issues: multiple views on one page and help with javascript

Hi :)

thank you both for your advice, it helped me to get going and so far I was
able to implement the design I had in mind using elements and ajax. Should
I encounter more difficulties, I will post them here.

Oh and bs28723: No worries that you might've been too basic, I'm always
glad for any advice, especially since I'm just beginning to learn Cake :)

Timo


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »